This module provides a simple interface to [BME280/BMP280 temperature/air presssure/humidity sensors](http://www.bosch-sensortec.com/bst/products/all_products/bme280)(Bosch Sensortec).
Note that you must call [`setup()`](#bme280setup) before you can start reading values!
!!! caution
Note that you must call [`setup()`](#bme280setup) before you can start reading values! Furthermore, there has to be a variable delay between some tens to hundreds of milliseconds between `setup()` and reading measurements. Instead of using a fixed delay you might also poll the sensor until data is delivered e.g. `humi()` not returning `nil` anymore.
## bme280.altitude()
...
...
@@ -215,6 +218,7 @@ print(string.format("altitude=%s%d.%02d", curAltsgn<0 and "-" or "", curAlt/100,
This module provides access to the DS18B20 1-Wire digital thermometer. Note that NodeMCU offers both a C module (this one) and [a Lua module for this sensor](https://github.com/nodemcu/nodemcu-firmware/tree/dev/lua_modules/ds18b20). See [#2003](https://github.com/nodemcu/nodemcu-firmware/pull/2003) for a discussion on the respective merits of them.
## ds18b20.read()
Issues a temperature conversion of all connected sensors on the onewire bus and returns the measurment results after a conversion delay in a callback function.
The returned measurements can be filtered through the ROM addresses passed as a table or by the family type.
The callback function gets invoked for every specified sensor.
#### Syntax
`ds18b20.read(CALLBACK, ROM[, FAMILY_ADDRESS])`
#### Parameters
-`CALLBACK` callback function executed for each sensor
-`ROM` table which contains the addresses for the specified sensors, or left empty to perform a onewire bus search for all sensors
* e.g. `{"28:FF:FF:FF:FF:FF:FF:FF","28:FF:FF:FF:FF:FF:FF:FF"}`, `{}`
-`FAMILY_ADDRESS` optional to limit the search for devices to a specific family type
* e.g `0x28`
#### Returns
`nil`
#### Callback function parameters
-`INDEX` index of the sensor on the bus
-`ROM` sensors 64-bit lasered rom code
*`28:FF:FF:FF:FF:FF:FF:FF` LSB, 8-bit family code, 48-bit serial number, MSB 8-bit crc
-`RES` temperature resolution
-`TEMP` temperature
-`TEMP_DEC` temperature decimals for integer firmware
-`PAR` sensor parasitic flag
!!! note
If using float firmware then `temp` is a floating point number. On an integer firmware, the final value has to be concatenated from `temp` and `temp_dec`.
#### Example
```lua
localow_pin=3
ds18b20.setup(ow_pin)
-- read all sensors and print all measurement results
Rather than calling `subscribe` multiple times you should use the multiple topics syntax shown in the above example if you want to subscribe to more than one topic at once.
This is a Lua module for the DS18B20 1-Wire digital thermometer. Note that NodeMCU offers both a Lua module (this one) and [a C module for this sensor](http://nodemcu.readthedocs.io/en/latest/en/modules/ds18b20/). See [#2003](https://github.com/nodemcu/nodemcu-firmware/pull/2003) for a discussion on the respective merits of them.
## Require
```lua
ds18b20=require("ds18b20")
...
...
@@ -8,33 +11,41 @@ ds18b20 = require("ds18b20")
ds18b20=nil
package.loaded["ds18b20"]=nil
```
<aid="ds18b20_setup"></a>
## readTemp()
Scans the bus for DS18B20 sensors, starts a readout (conversion) for all sensors and calls a callback function when all temperatures are available. Powered sensors are read at once first. Parasite-powered sensors are read one by one. The first parasite-powered sensor is read together with all powered sensors.
# Methods
The module requires `ow` module.
## read_temp()
Scans the bus for DS18B20 sensors (optional), starts a readout (conversion) for all sensors and calls a callback function when all temperatures are available. Powered sensors are read at once first. Parasite-powered sensors are read one by one. The first parasite-powered sensor is read together with all powered sensors.
The also module uses `encoder` module for printing debug information with more readable representation of sensor address (`encoder.toHex()`).
The module requires `ow` module.
#### Syntax
`readTemp(callback, pin)`
`read_temp(callback, pin, unit, force_search, save_search)`
#### Parameters
-`callback` function that receives all results when all conversions finish. The callback function has one parameter - an array addressed by sensor addresses and a value of the temperature (string for integer version).
-`pin` pin of the one-wire bus. If nil, GPIO0 (3) is used.
-`unit` unit can be Celsius ("C" or ds18b20.C), Kelvin ("K" or ds18b20.K) or Fahrenheit ("F" or ds18b20.F). If not specified (nil) latest used unit is used.
-`force_search` if not nil a bus search for devices is performed before readout. If nil the existing list of sensors in memory is used. If the bus has not been searched yet the search performed as well.
-`save_search` if not nil found sensors are saved to the file `ds18b20_save.lc`. When `read_temp` is called, list of sensors in memory is empty and file `ds18b20_save.lc` is present then sensor addresses are loaded from file - usefull when running from batteries & deepsleep - immediate readout is performed (no bus scan).
#### Returns
nil
#### Example
```lua
t=require("ds18b20")
pin=3-- gpio0 = 3, gpio2 = 4
localt=require("ds18b20")
localpin=3-- gpio0 = 3, gpio2 = 4
functionreadout(temp)
localfunctionreadout(temp)
ift.sensthen
print("Total number of DS18B20 sensors: "..#t.sens)
-- Module can be released when it is no longer needed
...
...
@@ -42,13 +53,15 @@ function readout(temp)
package.loaded["ds18b20"]=nil
end
-- t:readTemp(readout) -- default pin value is 3
t:readTemp(readout,pin)
ift.sensthen
print("Total number of DS18B20 sensors: "..table.getn(t.sens))
fori,sinipairs(t.sens)do
-- print(string.format(" sensor #%d address: %s%s", i, s.addr, s.parasite == 1 and " (parasite)" or ""))
print(string.format(" sensor #%d address: %s%s",i,encoder.toHex(s.addr),s.parasite==1and" (parasite)"or""))-- readable address with Hex encoding is preferred when encoder module is available
print(string.format("Sensor %s: %s °C",encoder.toHex(addr),temp))-- readable address with base64 encoding is preferred when encoder module is available
-- Module can be released when it is no longer needed
t=nil
package.loaded["ds18b20"]=nil
--t = nil
--package.loaded["ds18b20"]=nil
end
-- t:readTemp(readout) -- default pin value is 3
t:readTemp(readout,pin)
ift.sensthen
print("Total number of DS18B20 sensors: "..table.getn(t.sens))
fori,sinipairs(t.sens)do
-- print(string.format(" sensor #%d address: %s%s", i, s.addr, s.parasite == 1 and " (parasite)" or ""))
print(string.format(" sensor #%d address: %s%s",i,encoder.toHex(s.addr),s.parasite==1and" (parasite)"or""))-- readable address with base64 encoding is preferred when encoder module is available
resp=resp..string.format("Sensor %s: %s ℃</br>",encoder.toHex(addr),temp)-- readable address with base64 encoding is preferred when encoder module is available