LoraWanDustSensor: Difference between revisions
Line 73: | Line 73: | ||
To compile the code, platformio is used, see the github archive. | To compile the code, platformio is used, see the github archive. | ||
=== | For OTAA, I plan to use the following scheme, to keep administration to a minimum: | ||
* The Device EUI is derived from the ESP32 MAC address, the node shows this on its OLED | |||
* The App EUI is generated in the TTN console, it is the same for all nodes | |||
* The App Key is generated in the TTN console, it is the same for all nodes | |||
* The device is registered in the TTN console by the Device EUI (if this doesn't happen automatically) | |||
* OTAA is done only once for each node. After that, the OTAA parameters are stored in (simulated) EEPROM. | |||
** Perhaps with a long press on the button, we can reset the OTAA? | |||
* OTAA progress is shown on the OLED | |||
* If OTAA has been done successfully, the node uses a kind of ABP mode using the parameters established with OTAA | |||
* not sure if we also save/restore the frame counter (this would be preferable), or just disable the feature in the TTN console. | |||
=== Backend === | |||
A Java program subscribes to the MQTT stream, decodes the telemetry packets and forwards them to the luftdaten API. | |||
There is no storage of measurement data in the Java application. | There is no storage of measurement data in the Java application. | ||
I've already developed some Java code that publishes the measurement values towards luftdaten.info. | I've already developed some Java code that publishes the measurement values towards luftdaten.info. | ||
Also I've developed code before to subscribe to the TTN MQTT stream. | Also I've developed code before to subscribe to the TTN MQTT stream. |
Revision as of 13:54, 10 April 2019
Project LoRaWAN dust Sensor | |
---|---|
LoRaWAN airborne particulate matter sensor | |
Status | In progress |
Contact | bertrik |
Last Update | 2019-04-10 |
The plan
The plan is to create a system consisting of:
- a sensor that measures airborne particulate matter and sends the measurement data using LoRa/TheThingsNetwork to a central location.
- a backend that collects the data from TTN and forwards it to luftdaten.info
This has been done before by other people, but can't find any really good examples:
- source code location is obscure, I will publish all source code on github and put up documentation on this wiki
- payload format is non-standard, I'd like to use something relatively universal and standard, so I think I will try to use the Cayenne LPP format.
This has been done by TTN Ulm, see https://github.com/verschwoerhaus/ttn-ulm-feinstaub (the sensor code) and https://github.com/verschwoerhaus/ttn-ulm-muecke (the forwarder, in python)
Sensors join the network using OTAA (instead of ABP), that way I try to minimize the setup of each individual node.
So I'd like to just re-invent the wheel properly this time.
Next steps
- Make it work with the 'old' LMIC library and ABP
- Try out the 'new' LMIC library at https://github.com/mcci-catena/arduino-lmic
- Experiment with OTAA, saving OTAA parameters, restoring OTAA parameters, see
- Finish the Java software (MQTT listener, payload decoder, luftdaten forwarder)
Dump
Useful links for the TTGO LoRa board:
- https://primalcortex.wordpress.com/2017/11/24/the-esp32-oled-lora-ttgo-lora32-board-and-connecting-it-to-ttn
- https://github.com/fcgdam/TTGO_LoRa32
- https://ictoblog.nl/2018/01/10/mijn-eerste-chinese-esp32-verbonden-met-the-things-network
Hardware
The node is based on Arduino, in particular a TTGO ESP32 board with onboard LoRa chip. The sensor is an SDS-011, just like in the luftdaten project.
Page with correct pinout of the ESP32 LoRa board.
Luftdaten uses a cycle time of 145 seconds for the SDS011.
Proposed hardware connections:
- SDS011 5V to ESP32 5V
- SDS011 GND to ESP32 GND
- SDS011 TXD to ESP32 GPIO25
- SDS011 RXD to ESP32 GPIO34
Software
Source code can be found on the github page.
Common
Packet format
Packets transferred over LoRa contain:
- structure version id: 2 bytes
- MAC address / id for forwarding towards luftdaten (esp-XXXX number): 6 bytes
- PM10 value, encoded in units of 0.1 ug/m3: 2 bytes
- PM2.5 value, encoded in units of 0.1 ug/m3: 2 bytes
- temperature, encoded in units of 0.1 deg C: 2 bytes
- relative humidity, encoded in units of 0.1%, 2 bytes
Total: 16 bytes
Not present value is 0xFFFF. Encoding is big endian.
Would be nice to use Cayenne for this, but I don't know if Cayenne has an id for particulate matter.
Node
To compile the code, platformio is used, see the github archive.
For OTAA, I plan to use the following scheme, to keep administration to a minimum:
- The Device EUI is derived from the ESP32 MAC address, the node shows this on its OLED
- The App EUI is generated in the TTN console, it is the same for all nodes
- The App Key is generated in the TTN console, it is the same for all nodes
- The device is registered in the TTN console by the Device EUI (if this doesn't happen automatically)
- OTAA is done only once for each node. After that, the OTAA parameters are stored in (simulated) EEPROM.
- Perhaps with a long press on the button, we can reset the OTAA?
- OTAA progress is shown on the OLED
- If OTAA has been done successfully, the node uses a kind of ABP mode using the parameters established with OTAA
- not sure if we also save/restore the frame counter (this would be preferable), or just disable the feature in the TTN console.
Backend
A Java program subscribes to the MQTT stream, decodes the telemetry packets and forwards them to the luftdaten API. There is no storage of measurement data in the Java application.
I've already developed some Java code that publishes the measurement values towards luftdaten.info. Also I've developed code before to subscribe to the TTN MQTT stream.