print(string.format("Sensor %s: %s 'C",encoder.toBase64(addr),temp))-- readable address with base64 encoding is preferred when encoder module is available
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.toBase64(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.toBase64(addr),temp)-- readable address with base64 encoding is preferred when encoder module is available
pin: 1~10, IO index. If parameter is nil, it will use pin 9(GPIO2) automatically.<br/>
####Returns
nil
####Example
```lua
ds18b20=require("ds18b20")
ds18b20.setup(9)
-- Don't forget to release it after use
ds18b20=nil
package.loaded["ds18b20"]=nil
```
####See also
**-**[]()
<aid="ds18b20_addrs"></a>
## addrs()
####Description
Return a table contain all of the addresses of DS18B20 on one-wire. If the setup(pin) function not executed, the pin 9(GPIO2) will be initialized as one-wire mode automatically. <br/>
####Syntax
addrs()
####Parameters
nil
####Returns
addrs: A table contain all of the addresses of DS18B20 on one-wire. Every address is a string. If failed, it will be nil. <br/>
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. Parasit-powered sensors are read one by one. The first parasit-powered sensor is read together with all powered sensors.
The module requires `ow` module.
<aid="ds18b20_readNumber"></a>
## readNumber()
####Description
Read the value of temperature. If the setup(pin) function not executed, the pin 9(GPIO2) will be initialized as one-wire mode automatically. <br/>
The also module uses `encoder` module for printing debug information with more readable representation of sensor address (`encoder.toBase64()`).
####Syntax
readNumber(addr, unit)
`readTemp(callback, pin)`
####Parameters
addr: string, the address of DS18B20. It will select the first address which be found when this parameter is nil.<br/>
unit: integer, unit conversion. Only Constant is acceptable, such as C(Celsius),F(Fahrenheit) and K(Kelvin). If this parameter is nil, the constant C(Celsius) will be selected automatically. <br/>
-`callback` function that receives all results when all conversions finish. The callback funciton 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.
####Returns
t1: integer. The integer part of the temperature. If it read fails, return nil. <br/>
t2: integer. The fractional part of the temperature. If it read fails, return nil. <br/>
nil
####Example
```lua
t=require("ds18b20")
t.setup(9)
addrs=t.addrs()
-- Total DS18B20 numbers, assume it is 2
print(table.getn(addrs))
-- The first DS18B20
print(t.readNumber(addrs[1],t.C))
print(t.readNumber(addrs[1],t.F))
print(t.readNumber(addrs[1],t.K))
-- The second DS18B20
print(t.readNumber(addrs[2],t.C))
print(t.readNumber(addrs[2],t.F))
print(t.readNumber(addrs[2],t.K))
-- Just read
print(t.readNumber())
-- Just read as fahrenheit
print(t.readNumber(nil,t.F))
-- Read as values
t1,t2=t.readNumber()
-- Don't forget to release it after use
t=nil
ds18b20=nil
package.loaded["ds18b20"]=nil
```
####See also
**-**[]()
t=require("ds18b20")
pin=3-- gpio0 = 3, gpio2 = 4
<aid="ds18b20_read"></a>
## read()
####Description
Read the string of temperature. If the setup(pin) function not executed, the pin 9(GPIO2) will be initialized as one-wire mode automatically. <br/>
addr: string, the address of DS18B20. It will select the first address which be found when this parameter is nil.<br/>
unit: integer, unit conversion. Only Constant is acceptable, such as C(Celsius),F(Fahrenheit) and K(Kelvin). If this parameter is nil, the constant C(Celsius) will be selected automatically. <br/>
####Returns
t: string. The string of the temperature. If it read fails, return nil.<br/>
-- Module can be released when it is no longer needed
t=nil
package.loaded["ds18b20"]=nil
end
####Example
```lua
t=require("ds18b20")
t.setup(9)
addrs=t.addrs()
-- Total DS18B20 numbers, assume it is 2
print(table.getn(addrs))
-- The first DS18B20
print(t.read(addrs[1],t.C))
print(t.read(addrs[1],t.F))
print(t.read(addrs[1],t.K))
-- The second DS18B20
print(t.read(addrs[2],t.C))
print(t.read(addrs[2],t.F))
print(t.read(addrs[2],t.K))
-- Just read
print(t.read())
-- Just read as centigrade
print(t.read(nil,t.C))
-- Don't forget to release it after use
t=nil
ds18b20=nil
package.loaded["ds18b20"]=nil
-- 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.toBase64(s.addr),s.parasite==1and" (parasite)"or""))-- readable address with base64 encoding is preferred when encoder module is available