Update Node.md

This commit is contained in:
Timm Bogner 2022-09-26 17:28:20 -05:00
parent 6f0e6609c7
commit ee9fe8ac2d

View File

@ -1,6 +1,6 @@
# FDRS User Node
A node is a device that sends and receives data from a nearby gateway. A node can be a sensor, controller, or both.
A node is a device that sends and receives data from a nearby gateway. A node can be a sensor, controller, or both.
**NOTE: Controller functionality for nodes is currently restricted to the *ESP-NOW protocol*. LoRa gateways can still transport data bi-directionally, but you will need to use ESP-NOW to register a controller node with a gateway.**
# Commands
### ``` beginFDRS();```
@ -22,42 +22,41 @@ Removes ```sub_id``` from subscription list.
## Basic usage:
### Sensor
Sends data (a temperature of 21.0) to the gateway it is addressed to.
Sensor nodes load a packet with data, then send the packet to the gateway that they are addressed to.
```
void setup() {
beginFDRS();
  beginFDRS();
}
void loop() {
loadFDRS(21.0, TEMP_T);
sendFDRS();
sleepFDRS(10); //Sleep time in seconds
  loadFDRS(21.0, TEMP_T);
  sendFDRS();
  sleepFDRS(10);  //Sleep time in seconds
}
```
### Controller
Registers with, then receives data from the device it is addressed to.
Controller nodes register with the gateway they are addressed to, then receive data from it.
```
void fdrs_recv_cb(DataReading theData) {
//Quickly handle incoming data
  //Quickly handle incoming data
}
void setup() {
beginFDRS();
//pingFDRS(1000);
addFDRS(1000, fdrs_recv_cb);
subscribeFDRS(READING_ID);
  beginFDRS();
  //pingFDRS(1000);
  addFDRS(1000, fdrs_recv_cb);
  subscribeFDRS(READING_ID);
}
void loop() {
}
```
## Options
## Configuration
### ```#define READING_ID n```
### ```#define READING_ID  n```
The identifier of this individual device. Should be a 16 bit integer value (0 - 65535).
### ```#define GTWY_MAC 0xnn```
### ```#define GTWY_MAC  0xnn```
The UNIT_MAC of the gateway that this device will send its data to.
### ```#define FDRS_DEBUG```
This definition enables debug messages to be sent over the serial port. If disabled, no serial interface will be initialized.
@ -68,47 +67,47 @@ Enables/disables LoRa.
### ```#define DEEP_SLEEP```
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.
### ```#define POWER_CTRL (pin)```
IF defined, power control will bring a GPIO pin high within beginFDRS(). This is useful for powering sensors while running on battery.
If defined, power control will bring a GPIO pin high when FDRS is initialized. This is useful for powering sensors while running on battery.
##The Callback
When incoming data arrives with an ID that the controller is subscribed to, the callback function is executed, interrupting all other tasks. Inside of this function, the user has access to the DataReading that has just arrived. This function should ONLY contain the code needed to save the data to a more permanent location. Any interpretation or display of the data should occur outside of the callback function. Intermediate users may also like to know that if the controller is subscribed to multiple IDs, the callback may be called multiple times before returning to the loop().
## Type Definitions
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!
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!
```
#define STATUS_T 0 // Status
#define TEMP_T 1 // Temperature
#define TEMP2_T 2 // Temperature #2
#define HUMIDITY_T 3 // Relative Humidity
#define PRESSURE_T 4 // Atmospheric Pressure
#define LIGHT_T 5 // Light (lux)
#define SOIL_T 6 // Soil Moisture
#define SOIL2_T 7 // Soil Moisture #2
#define SOILR_T 8 // Soil Resistance
#define SOILR2_T 9 // Soil Resistance #2
#define OXYGEN_T 10 // Oxygen
#define CO2_T 11 // Carbon Dioxide
#define WINDSPD_T 12 // Wind Speed
#define WINDHDG_T 13 // Wind Direction
#define RAINFALL_T 14 // Rainfall
#define MOTION_T 15 // Motion
#define VOLTAGE_T 16 // Voltage
#define VOLTAGE2_T 17 // Voltage #2
#define CURRENT_T 18 // Current
#define CURRENT2_T 19 // Current #2
#define IT_T 20 // Iterations
#define LATITUDE_T 21 // GPS Latitude
#define LONGITUDE_T 22 // GPS Longitude
#define ALTITUDE_T 23 // GPS Altitude
#define HDOP_T 24 // GPS HDOP
#define LEVEL_T 25 // Fluid Level
#define STATUS_T        0  // Status
#define TEMP_T          1  // Temperature
#define TEMP2_T         2  // Temperature #2
#define HUMIDITY_T      3  // Relative Humidity
#define PRESSURE_T      4  // Atmospheric Pressure
#define LIGHT_T         5  // Light (lux)
#define SOIL_T          6  // Soil Moisture
#define SOIL2_T         7  // Soil Moisture #2
#define SOILR_T         8 // Soil Resistance
#define SOILR2_T        9 // Soil Resistance #2
#define OXYGEN_T        10 // Oxygen
#define CO2_T           11 // Carbon Dioxide
#define WINDSPD_T       12 // Wind Speed
#define WINDHDG_T       13 // Wind Direction
#define RAINFALL_T      14 // Rainfall
#define MOTION_T        15 // Motion
#define VOLTAGE_T       16 // Voltage
#define VOLTAGE2_T      17 // Voltage #2
#define CURRENT_T       18 // Current
#define CURRENT2_T      19 // Current #2
#define IT_T            20 // Iterations
#define LATITUDE_T      21 // GPS Latitude
#define LONGITUDE_T     22 // GPS Longitude
#define ALTITUDE_T      23 // GPS Altitude
#define HDOP_T          24 // GPS HDOP
#define LEVEL_T         25 // Fluid Level
```
## Under the hood
```
typedef struct __attribute__((packed)) DataReading {
float d;
uint16_t id;
uint8_t t;
  float d;
  uint16_t id;
  uint8_t t;
} DataReading;
```
Each sensor in the system sends its data over ESP-NOW or LoRa as a float 'd' 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.
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.