A node is a device that sends and receives data from a nearby gateway. This is where the user can communicate with a network of FDRS gateways using their own sketch. A node can be a **sensor** (sending data), **controller** (receiving data), ***or both***.
The unique ID that the node will use when sending sensor values. Can be any integer 0 - 65535. Nodes are not necessarily tied to this parameter. They can be subscribed to up to 256 different IDs or send using several different IDs.
#### `#define GTWY_MAC 0xnn`
The `UNIT_MAC` of the gateway that this device will be paired with.
## Usage
#### `beginFDRS();`
Initializes FDRS, powers up the sensor array, and begins ESP-NOW and/or LoRa.
#### `uint32_t pingFDRS(timeout);`
Sends a ping request to the device's paired gateway with a timeout in ms. Returns the ping time in ms and displays it on the debugging console.
Sends the current packet using ESP-NOW and/or LoRa. Returns true if packet is confirmed to have been received successfully by the gateway.
#### `bool sendFDRSAsync();`
Queues the current packet to be sent asynchronously (in the background). Be sure to use `loopFDRS()` to ensure the system can process the packet. Returns true if packet is successfully added to queue.
Initializes controller functionality by selecting the function to be called when incoming commands are received. If using LoRa, the controller will automatically receive any packets sent with broadcastLoRa(), provided they were sent by the paired gateway. ESP-NOW requires the device to register with its gateway before it will receive incoming commands. This is done automatically, and the ESP-NOW node will continue recieving data until the paired gateway is reset. A maximum of 16 ESP-NOW controllers can receive data from a single gateway. There is no limit to how many LoRa controllers can listen to the same gateway.
Sets the device to listen for a specific DataReading id. When a DataReading with id ```sub_id``` is received, the callback function will be called and given the full DataReading as a parameter.
#### ```unsubscribeFDRS(uint16_t sub_id);```
Removes ```sub_id``` from subscription list.
#### ```loopFDRS();```
Always add this to ```loop()``` to handle the controller's listening capabilities.
Sets the level of verbosity in debug messages. '0' (default) shows only the most important system messages, '1' will show additional debug messages for troubleshooting, and '2' will show all messages, including those used in development. Much gratitude to [Jeff Lehman](https://github.com/aviateur17) for this feature!
If enabled, device will enter deep-sleep when the sleepFDRS() command is used. If using ESP8266, be sure that you connect the WAKE pin (GPIO 16) to RST or your device will not wake up.
Enables LoRa packet acknowledgement. The device will use CRC to ensure that the data arrived at its destination correctly. If disabled, ```sendFDRS()``` will always return true when sending LoRa packets.
Thanks [Jeff Lehman](https://github.com/aviateur17) for this feature!
The callback function is executed when data arrives with an ID that the controller is subscribed to. Inside of this function, the user has access to the incoming DataReading. If multiple readings are received, the function will be called for each of them. While you should always be brief in interrupt callbacks (ISRs), it's okay to do more in this one.
For the moment, my thought is to reserve the first two bits of the type. I might use them in the future to indicate the data size or type (bool, char, int, float, etc?). This leaves us with 64 possible type definitions. If you have more types to add, please get in touch!
Each node in the system sends its data inside of a structure called a DataReading. Its global sensor address is represented by an integer 'id', and each type of reading is represented by a single byte 't'. If a sensor or gateway needs to send multiple DataReadings, then they are sent in an array. A single DataReading.id may have readings of multiple types ('t') associated with it.