ESP8266/Lua Codez: Difference between revisions
Jump to navigation
Jump to search
| Line 24: | Line 24: | ||
| A string that will be shown when LUA boots up (this ideally will also show all includes modules) | | A string that will be shown when LUA boots up (this ideally will also show all includes modules) | ||
|- | |- | ||
| | | app/modules/wifi.c | ||
| static int wifi_station_getconfig( lua_State* L ) | | static int wifi_station_getconfig( lua_State* L ) | ||
<syntaxhighlight inline lang="cpp">lua_pushstring( L, "" );</syntaxhighlight> | <syntaxhighlight inline lang="cpp">lua_pushstring( L, "" );</syntaxhighlight> | ||
Revision as of 04:18, 6 June 2016
Setup
Firmware Mods
| source | new | old | purpose |
|---|---|---|---|
| app/modules/mqtt.c | #define MQTT_BUF_SIZE 2048
|
#define MQTT_BUF_SIZE 1024
|
increase MQTT buffer size so that larger LUA scripts can be send |
| app/lua/luaconf.h | #define LUA_MAXINPUT 2048
|
#define LUA_MAXINPUT 256
|
increase input buffer so that larger LUA scripts can be directly send to node.input(script) |
| app/include/user_modules.h | #define ...
|
//#define ...
|
Enable all modules to be included |
| app/include/user_version.h | #define BUILD_DATE "playfulexploration.com build"
|
#define BUILD_DATE "unspecified"
|
A string that will be shown when LUA boots up (this ideally will also show all includes modules) |
| app/modules/wifi.c | static int wifi_station_getconfig( lua_State* L )
|
static int wifi_station_getconfig( lua_State* L )
|
Disable the ability to read out the Wifi password |
Custom Lua Builds
https://www.playfulexploration.com/files/nodemcu-firmware/bin/
Esp8266 Flashing Latest Dev builds
- Flashing latest NodeMCU Dev builds with esptool requires additional '-fm dio' option. Without it the chi will not boot after flashing e.g.:
esptool.py --port COM4 write_flash -fm dio 0x000000 "nodemcu_float_dev_20160603-0606.bin" - Latest Dev builds use baud rate 115200
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 BME280 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/1000)
.."\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()
Log BMP085 and DHT22 with influx
bmp085.init(6,5)
print( bmp085.pressure(), bmp085.temperature()/10, dht.read(7) )
host="playfulexploration.com"
mac=wifi.ap.getmac
sendToInflux = function(c)
local s,t,h=dht.read(7)
local b=bmp085.pressure()
local params="baro,mac="..wifi.ap.getmac().." value="..b
.."\ndewp,mac="..mac().." value="..(bme280.dewpoint(h*1000,t*100)/100)
if s==0 then
params=params.."\ntemp,mac="..mac().." value="..t
.."\nhumi,mac="..mac().." value="..h
end
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()