chipmc / LoRA-Particle-Gateway

3 stars 2 forks source link

LoRA-Particle-Gateway

This is a lightweight and extensible gateway between LoRA and Cellular networks using the Particle platform. This work is possible because of the enhancement of the Particle community libraries RF9X-RK and AB1805_RK

Initial Implementation - Adding LoRA to Cellular for more complete coverage!

The itent of this project is to show how data collected from remote LoRA nodes can be relayed to a server and on to the internet using a cellular connection. This is especially useful in three scenarios:

To get Started, you will need to setup a couple devices:

Modular Program Structure

To make this code easier to maintain, I am breaking out the main c++ file into the following:

Concept of operations

With this program, we will collect data from remote nodes connected via LoRA and relay that data to Particle via the Publish function.
From there, the Particle Integrations will send this data to its final destination via a Webhook. The idea of breaking out this code this way is to allow you to easily swap out - sensors, the platform, the persistent storage media, the connectivity and still reuse code from this effort. Over time, these elements will mature and become building blocks for whatever comes next (your imagination here).

Alert Codes

The gateway controls the nodes via alerts and alertContext, a 1 byte unsigned integer that contains metadata to be sent with the alert. These are intended to allow for all the configuration of the nodes so a new node can get all the needed configuration through interacting with the gateway.

The Alert Codes and their actions are key to this process:

Alert Code 0 - No alerts - Nominal State

Alert Code 1 - Unconfigured Node / Rejoin has been triggered

Alert Code 2 - Time not Synced (CURRENTLY AN INTERNAL CODE FOR THE NODE)

Alert Code 3 - Power cycle the node (CURRENTLY AN INTERNAL CODE FOR THE NODE)

Alert Code 4 - Reinitialize the modem (CURRENTLY AN INTERNAL CODE FOR THE NODE)

Alert Code 5 - Resets ALL data of a node

Alert Code 6 - Resets CURRENT data of a node

Alert Code 7 - Sets the "Zone Mode" of a TOF Occupancy Sensor

Alert Code 8 - Sets the "Distance Mode" of a TOF Occupancy Sensor

Alert Code 9 - Sets the "Floor Interference Buffer" of a TOF Occupancy Sensor

Alert Code 10 - Sets the number of calibration loops for a TOF Occupancy Sensor

Alert Code 11 - Triggers recalibration for a TOF Occupancy Sensor

Alert Code 12 - Gateway override to occupancyNet value of a node.

Alert Code 13 - Sets detections per second for a TOF Occupancy Sensor

Particle Function Commands

Particle Function Commands are executed through the Particle Console for a device (TODO:: or through the Ubidots dashboard widget frontend). The UniqueID of a node is specified as the value for the "node" key of the command and thus, a node must be present in the JSON database of the gateway before executing them.

To add a new node to the database, attempt to join to the gateway once by pressing the User button to trigger a data payload to be sent. This will cause the Gateway to store the node in the database and respond with Alert Code 1 to trigger a Join request.

Reset

Frequency

Stay

Report

Opening Hour

Closing Hour

Break Start Hour

Break Length Minutes

Weekend Break Start Hour

Weekend Break Length Minutes

Power Cycle

Set Sensor Type for a Node

Set Mounting Configuration for an Occupancy Node

Set Zone Mode for an Occupancy Node

Set Distance Mode for an Occupancy Node

Set Floor Interference Buffer for an Occupancy Node

Set Number of Calibration Loops for an Occupancy Node

Recalibrate an Occupancy Node

Reset all Room Occupancy

Reset a Space

Set Net Count for an Occupancy Node

Set Detections per Second for a TOF Sensor Occupancy Node

Set Transmit Latency Seconds for a Node

Payload Assignments for Data Report by Sensor Type

Type Payload1 Payload2 Payload3 Payload4 Payload5 Payload6 Payload7 Payload8
Counter Hourly - H Hourly - L Daily - H Daily - L TBD TBD TBD TBD
Occupancy Gross-H (unused) Gross-L (unused) Net - H Net - L Space Placement Multi Zone Mode
Sensor Data1 - H Data1 - L Data2 - H Data2 - L Data3 - H Data3 - L Data4 - H Data4 - L

Payload Assignments for Join Request by Sensor Type (4 values compressed to 1 byte)

Type Payload1 Payload2 Payload3 Payload4
Counter 2-Way (1 bit) TBD TBD TBD
Occupancy Space (6 bits) Placement (1 bit) Multi (1 bit) TBD
Sensor Space (6 bits) Placement (1 bit) TBD TBD

Additional Data stored in JSON database by Sensor Type

Type JsonData1 (jd1) JsonData2(jd2)
TBD TBD TBD
Occupancy OccupancyNet OccupancyGross (unused)
TBD TBD TBD