FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

AQmon/lua_modules at master · avaldebe/AQmon · GitHub

/ AQmon Public

Latest commit

 

History

History

README.md

lua_modules

Lua modules for AQmon project.

Project specific modules

  • AQmon.lua: Read sensors and publish to thingspeak.
  • keys.lua: Contains the known APs SSID/PASS pairs, thingspeak keys and pin assignment (LED,SDA/SCL,&c).

Sensor modules

  • bmp180.lua: BMP085 / BMP180 sensors.
  • am2321.lua: AM2320 / AM2321 sensors (tested) and AM2315 / AM2322 (untested) via I2C.
  • bme280.lua: BME280 sensor, can replace BMPxxx and AM232x sensors.
  • pms3003.lua: PMS3003 sensors (tested) and PMS1003 / PMS2003 / PMS5003 / PMS7003 sensors (untested) via UART.
  • sensor_hub.lua: Read all sensors above.

I-Net modules

  • wifi_connect.lua: Connect to a known AP, as defined in keys.lua.
  • sendData.lua: Publish data to thingspeak or other API, as defined in keys.lua

General purpose modules

  • init.lua: Exit infinite reboot caused by a PANIC error. Calls require('app') after 2 seconds from boot. Before that, the call can be aborted by pressing KEY_FLASH, which drives pin3 (gpio0) low.
  • rgbLED.lua: Returns a status function for a RGB LED.
  • hueLED.lua: Returns a function that control a RGB LED with Hue, at full Saturation and Brightness (HSV).
  • i2cd.lua: I2C helper functions with pedantic debug checks. Use require('i2cd').autoscan(true) to find connected I2C devises.

Upload from command line with luatool.py

# find the port
PORT=`ls /dev/ttyUSB? /dev/rfcomm? 2>/dev/null`
# remove all *.lua and *.lc files and restart
luatool.py -p $PORT -w -r
# upload, compile and restart
luatool.py -p $PORT -rc -f bme280.lua
luatool.py -p $PORT -rc -f bmp180.lua
luatool.py -p $PORT -rc -f am2321.lua
luatool.py -p $PORT -rc -f pms3003.lua
luatool.py -p $PORT -rc -f keys.lua
luatool.py -p $PORT -rc -f wifi_connect.lua
luatool.py -p $PORT -rc -f sendData.lua
luatool.py -p $PORT -rc -f rgbLED.lua
# upload, rename, compile and restart
luatool.py -p $PORT -rc -f sensor_hub.lua -t sensors.lua
luatool.py -p $PORT -rc -f AQmon.lua      -t app.lua
# upload and restart
luatool.py -p $PORT -r -f init.lua

Ussage examples

Information for each sensor module can be found at SENSORS.md

Sensor Hub

-- module setup and read: no PMS3003
sda,scl,pinSET=3,4,nil -- GPIO0,GPIO2
require('sensors').init(sda,scl,pinSET)
sensors.verbose=true -- verbose mode
sensors.read()

-- module setup and read: all sensors
sda,scl,pinSET=5,6,7
require('sensors').init(sda,scl,pinSET)
sensors.read(function()
  print(sensors.format({heap=node.heap(),time=tmr.time()},
    'sensors:{time}[s],{t}[C],{h}[%],{p}[hPa],{pm01},{pm25},{pm10}[ug/m3],{heap}[b]'))
end)

-- release memory
sensors,package.loaded.sensors = nil,nil

References

After many round of write/rewrite code it becomes hard to keep track of sources for code and ideas. Please let me know, if I have missed you.

My biggest thanks to the following authors:

  • bigdanz: init.lua is based on ideas form his article abut interrupting init.lua.
  • @javieryanez: I used his nodemcu modules for the BMP180 and DTH22 sensors before I wrote my own module. My bmp180.lua module is based on his.
  • @saper-2: I used his nodemcu modules for the AM2321 sensor before I wrote my own module. My am2321.lua module is based on his.
  • captain-slow: His short article on posting to thingspeak helped me to get my data out.
  • @geekscape: his skeleton/setup.lua is almost esactly the same as my first version of wifi.init. From him I took the idea of using a generic module name (appliation.lua) for the appliation specific code.
  • @hwiguna: his esp8266 videos are an inspiration go out and play (or code).
  • For my bme280.lua module I took bit and pieces from many sources:

Back | FazBrowse Home | New Git URL