ESP8266/Lua Codez: Difference between revisions
Jump to navigation
Jump to search
| Line 15: | Line 15: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bme280.init(1,2) | bme280.init(1,2) | ||
host="playfulexploration.com" | |||
mac=wifi.ap.getmac | |||
sendToInflux = function(c) | sendToInflux = function(c) | ||
local h,t,b=bme280.humi(),bme280.temp(),bme280.baro() | local h,t,b=bme280.humi(),bme280.temp(),bme280.baro() | ||
local params="baro,mac="..wifi.ap.getmac().." value="..b | local params="baro,mac="..wifi.ap.getmac().." value="..b | ||
.."\ntemp,mac="..mac().." value="..(t/100) | |||
.."\nhumi,mac="..mac().." value="..(h/1000) | |||
.."\ndewp,mac="..mac().." 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 | local m="POST /write?db=weather HTTP/1.1" | ||
print(m) | .."\r\nHost:"..host | ||
.."\r\nContent-Length: "..params:len() | |||
.."\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n" | |||
..params | |||
--print(m) | |||
c:send(m) | c:send(m) | ||
end | end | ||
| Line 30: | Line 36: | ||
conn:on("connection", sendToInflux) | 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:on("receive", function(conn,m) conn:close() conn=nil print(m) tmr.alarm(0, 3000, 0, trigger) tmr.softwd(30) end) | ||
conn:connect(8086, | conn:connect(8086,host) | ||
end | end | ||
trigger() | trigger() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 06:58, 4 June 2016
Custom Lua Builds
https://www.playfulexploration.com/files/nodemcu-firmware/bin/
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)
host="playfulexploration.com"
mac=wifi.ap.getmac
sendToInflux = function(c)
local h,t,b=bme280.humi(),bme280.temp(),bme280.baro()
local params="baro,mac="..wifi.ap.getmac().." value="..b
.."\ntemp,mac="..mac().." value="..(t/100)
.."\nhumi,mac="..mac().." value="..(h/1000)
.."\ndewp,mac="..mac().." value="..(bme280.dewpoint(h,t)/100)
local m="POST /write?db=weather HTTP/1.1"
.."\r\nHost:"..host
.."\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,host)
end
trigger()