ESP8266/Lua Codez: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Dump BME280 Pressure, Humidity and Temperature == <syntaxhighlight lang="lua"> bme280.init(1,2) tmr.alarm(1, 3000, 1, function() tmr.softwd(30) local h,t,b=bme280.h...") |
No edit summary |
||
| Line 7: | Line 7: | ||
print('humi: '..(h/1000)..'% temp: '..(t/100)..'C baro: '..b..'PA dewp: '..(bme280.dewpoint(h,t)/100)..'C') | print('humi: '..(h/1000)..'% temp: '..(t/100)..'C baro: '..b..'PA dewp: '..(bme280.dewpoint(h,t)/100)..'C') | ||
end) | end) | ||
</syntaxhighlight> | |||
== Log with influx == | |||
<syntaxhighlight lang="lua"> | |||
bme280.init(1,2) | |||
sendToInflux = function(c) | |||
local h,t,b=bme280.humi(),bme280.temp(),bme280.baro() | |||
local params="baro,mac="..wifi.ap.getmac().." value="..b | |||
params=params.."\ntemp,mac="..wifi.ap.getmac().." value="..(t/100) | |||
params=params.."\nhumi,mac="..wifi.ap.getmac().." value="..(h/1000) | |||
params=params.."\ndewp,mac="..wifi.ap.getmac().." value="..(bme280.dewpoint(h,t)/100) | |||
local m="POST /write?db=weather HTTP/1.1\r\nContent-Length: "..params:len().."\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"..params | |||
print(m) | |||
c:send(m) | |||
end | |||
trigger = nil | |||
trigger = function(c) | |||
conn = net.createConnection(net.TCP, 0) | |||
conn:on("connection", sendToInflux) | |||
conn:on("receive", function(conn,m) conn:close() conn=nil print(m) tmr.alarm(0, 3000, 0, trigger) tmr.softwd(30) end) | |||
conn:connect(8086,"playfulexploration.com") | |||
end | |||
trigger() | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 06:09, 2 June 2016
Dump BME280 Pressure, Humidity and Temperature
bme280.init(1,2)
tmr.alarm(1, 3000, 1, function()
tmr.softwd(30)
local h,t,b=bme280.humi(),bme280.temp(),bme280.baro()
print('humi: '..(h/1000)..'% temp: '..(t/100)..'C baro: '..b..'PA dewp: '..(bme280.dewpoint(h,t)/100)..'C')
end)
Log with influx
bme280.init(1,2)
sendToInflux = function(c)
local h,t,b=bme280.humi(),bme280.temp(),bme280.baro()
local params="baro,mac="..wifi.ap.getmac().." value="..b
params=params.."\ntemp,mac="..wifi.ap.getmac().." value="..(t/100)
params=params.."\nhumi,mac="..wifi.ap.getmac().." value="..(h/1000)
params=params.."\ndewp,mac="..wifi.ap.getmac().." value="..(bme280.dewpoint(h,t)/100)
local m="POST /write?db=weather HTTP/1.1\r\nContent-Length: "..params:len().."\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"..params
print(m)
c:send(m)
end
trigger = nil
trigger = function(c)
conn = net.createConnection(net.TCP, 0)
conn:on("connection", sendToInflux)
conn:on("receive", function(conn,m) conn:close() conn=nil print(m) tmr.alarm(0, 3000, 0, trigger) tmr.softwd(30) end)
conn:connect(8086,"playfulexploration.com")
end
trigger()