Gateway Module Firmware Document
Introduction
Gateway module acts as a ESP_Now receiver node in a network containing a group of
Measurement Modules, which listens to the line (WIFI ESP_NOW) and receives sensors data
from them and sends them to the Notehub Cloud through a NoteCard and Note Carrier.
Hardware
Hardware containing the GatewayModule are:
NoteCard: NOTE-NBGL-500
Note Carrier: SparkX Qwiic Cellular
Development Board: Spark Fun Esp32-S2 Think Plus
Software Development Environment and config
The firmware is developed in VisualStudio Code IDE with PlatformIO in Arduino framework and
c and cpp language.
ESP_NOW Receive
Sensor data from measurement modules is received by initializing ESP_NOW in the [Link].
setup () function, which invokes the espnowSetup () function. This function initializes WIFI for
ESP_NOW communication and also activates the callback function to receive messages as an
interrupt. The call-back function is
void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len)
In [Link] file. This function extracts received data from each Measurement
Module and saves it in the following structure format:
typedef struct measured_data{
int DeviceId;
float tempThermocouple;
float tempSHT30;
float humiditySHT30;
float electricCurrent;
float pulseCountedMin;
float flow;
}measured_data;
NoteHub Messages
Sensor data messages received from Measurement Modules via ESP_Now should be
rearranged in a format suitable for Enerinno Dashboard. This is done by invoking
insertSensorDataToHyper() function in [Link](). This function checks if a new message
is received from a Measurement Module, then adds it or replaces it in the array
SensorDataPair HyperSensorsData[600];
Of this struct:
typedef struct SensorDataPair
{String index;
float value;
bool sentStatus;
}SensorDataPair;
The elements of the above struct are determined in the following way:
Index = "&0X"+String(([Link]-1)*6)+Offset
The Offset depends on the measured quantity as:
0 : for Electric Current
1: for temperature form thermocouple
2: for temperature from SHT30 sensor
3: for humidity from SHT30 sensor
4: for digital pulse counted
The final message format to be sent to Notehub is a json message of collection :
"[Link]&0X103": 51.25
“GatewayModule MAC Address +&0x +Idex (as described above)“: sensor value
For all sensor values in the network not sent yet.
The message is sent to Notehub in [Link]() by calling the function SendToNoteHub()
which is called in a scheduled time interval, now every 5 minutes.
Notecard Configuration
The Notecard setup is done as follows:
[Link]("Sending request [Link] ");
JAddStringToObject(req, "product", "[Link]:enerinno");
JAddStringToObject(req, "mode", "periodic"); // Use 'periodic' mode
JAddNumberToObject(req, "inbound", 15); // Check inbound messages every 15 minutes
JAddNumberToObject(req, "outbound", 15); // Sync outbound messages every 15 minutes
JAddStringToObject(req, "health", "periodic"); // Enable periodic health checks
JAddNumberToObject(req, "health-interval", 60); // Set health check interval to 1 hour
Which is done in
void Note_Card::setupNoteCard() function.
This function is defined and declared in Note_Card.cpp and Note_Card.h files. The setup
function for NoteCard is invoked in [Link]().