This is my attemp to implement a private network in raw LoRa layer based on arduino-LoRa library. The hardware consists of Nodemcu as Gateway and Arduino pro mini as Node. Both Gateway and Node use Ra-02 (rfm98) as LoRa transceiver module. The system features:
- TDMA like class B to save energy
- Beacon message to sync time needed for TDMA
- Star network with forwarder
- During bootup/setup, init lora, wait for Beacon message and set local time
- At each BP (Beacon Period), wake up, wait for Beacon and sync local time, then go sleep
- At each SP (Sense Period), wake up, read sensors and send uplink message, wait for downlink message for X sec, call actuator (if there is instruction from Gateway), then go sleep
- During bootup/setup, init lora, connect wifi, connect NTP server and sync local time
- At each BP, broadcast Beacon message, read from server and save instructions in stack, then go onReceive mode
- onReceive uplink from Node, decode data and send to server, send downlink message with if any instruction
Added some sketch to better illustrate and calculate the desired sleep time. Detail at here
Modified to send downlink message upon each uplink with instruction. Thus reserve a lora.read() window for Node after each SP
No private downlink message. Instructions embedded in Beacon message following global time
Uplink | Beacon | Downlink | MQTT-payload from server
- Include message length; remove useless msgID; Implement control command of max 3 switches in downlink
- Consider removing Year, Month, Day, Second in beacon message with v4-program, since there is no clock running on nodes. They just need to know when is XX:YY:00
- Consider sending message length as well to make sure the recved message is complete || haven't implemented
- uplink and beacon remained
- downlink from gateway
[ destination Addr | groupID | local Addr | msg count | actuator ID | instruction | if any more ]
- uplink message
[ destination Addr | groupID | local Addr | msg count | integer of pt100-1 | decimal of pt100-1 | other sensor values divied into integer and decimal ] - beacon message
[ destination Addr | groupID | local Addr | msg count | Hour | Minute | Second | Day | Month | Year ]
Destination Addr: 0x00-Gateway, 0xFF-broadcast (reserved for beacon message) Local Addr: 0x00-Gateway, 0x01-0xFE for Nodes
Single node with two PT100 sensors and one BME280
- Use led blink to mimic downlink instruction, test passed
- Add flag to exit recv mode once downlink arrived but Node still in the recv slot, to save energy
Gateway:
- Implement sendDownlink inside LoRa onReceive function
- implement reading command from MQTT server and sendDownlink()
- Simplify the beacon message
- Simple encryption
Node:
- Implement readDownlink
- Simple encryption
- Upgrade the software structure with updated TDMA strategy
- enable power down with LowPower library
- Not complete yet, added mode selection at bootup (setup) stage, with four modes in total, 00-debug, 01-lowTxPower, 10-mediumTxPower, 11-highTxPower respectively
- Make it clear how Sense Period offset is calculated based on SP and localAddr
- Define sensor structor to use it more conviently
- Implement the basic of receiving slot after each SP, the downlink recv and actuator operation
Mimic multiple node and create node red dashboard
More stable compared with v2. Fixed the syncTime problem.
Duplex mode. Broadcast Beacon per 2 minutes. No private downlink from Gateway after each uplink. SP based on localAddress not implemented yet in code but designed in comment. Bascially both Gateway and Node works fine but Node sometimes send uplink message not on correct time.
Simplex mode, just sensor data from Node to Gateway. Connected to thingsboard.
-
2.04.2019, 435Mhz, SF-10, BD-125, txPower-17, (5dbi?) antenna at 3rd floor indoor, 3dbi antenna on receive node
Results: 815m, RSSI:-122 ~ -125 -
2.04.2019, 435Mhz, SF-10, BD-125, txPower-17, (5dbi?) antenna at 3rd floor indoor, 3dbi antenna on receive node
Results: 440m, RSSI:-117 ~ -119 -
15.03.2019, 435Mhz, SF-10, BD-125, txPower-17, (5dbi?) antenna at 3rd floor indoor
. Result: 400m, RSSI: -108 ~ -125
- Play with sensors and oled
- Design project-specific data structure
- Get real time from NTP server
- Connect to IoT platform
- Duplex mode for both Gateway and Nodes
- Play with Node-RED with conclusion that it doesn't support multi-user/dashboard by itself
- Listen Before Talk if necessary; need timeout to avoid lockup; not intergrate with current code
- Make UI for instruction input; simpled button and switch on node red
- Implement re-syncTime for fear of lost beacon and timedrift caused beacon-recv-window drift. Conclusion: not necessary, if beacon is lost or local time is incorrect, it will go into syncTime mode anyway, and until it get synced it will not jump out of the loop
- Timeout of syncTime. Conclusion: not necesary, if the beacon message is not received on time, it means either the local time is incorrect or something wrong with the beacon server, thus need to figure it out
- Intergrate watchdog timer & power_down with current structure on pro mini
- Test how setTime() in time library works or if checking setStatus() is needed. Conclusion: the +1 sec ahead sometimes is too fast, maybe insert some delay
- Evaluate if necessary to compensate time dirft of pro mini considering the Beacon Period could be set to 1 or 2 minutes which is quite short. Conclusion: the time drift of pro mini 8Mhz is around 1s per 2 minutes, thus with a 1-min-beacon-period there is no worry
- Implement readServer() on Gateway and save instruction in stack
- Implement sendDownlink() on Gateway
- Implement readDownlink() on Node, and reserve callAcutator() function
- Implement data encryption. Conclusion: Implemented a simple XOR encryption, the key could be updated periodically by lora message if needed
- Node as forwarder or mesh network. Conclusion: With radiohead this feature comes out of box
- Create Timeseries database using influxDB and sqlite; display historical chart on Grafana with influxDB and on Node-RED dashboard with sqlite; implement time range selection
- Play with Radiohead library
- Figure out CAD mode and interrupt to save energy, either using radiohead or arduino-lora-forked
- Test RFO and PA_BOOST setup's range and signal strength, assuming both set +14. Conclusion: AI thinker module (ra-02) has NO RFO Wire connected, only PA_BOOST
- Press test/ packet loss test
- Add watchdog for nodemcu as it easily gets frozen
- Add led or oled screen on gateway/nodemcu to indicate current and historical status