Provisioning a new sensor in deepVibe
This explains how to provision a new sensor in a node, transmit the new data, and finally store, process or visualize it. Based on the requirements of the sensor and required behavior you may deviate from this structure.
Provisioning the new sensor in the Sensor Node
Add a menuconfig entry to enable / disable the new sensor. You may add additional new sensor parameter selectors under the same menu section as necessary. For example the
dallastemperature sensor is enabled / disabled withDALLAS_TEMPERATURE_SENSORIn
mesh_main.c, gotoget_sensor_data()function and add a section for your new sensor based on the required reading and processing steps. Enclose that with the preprocessor directive from the menuconfig. (Remember to add theCONFIG_prefix For example, this is what is present for temperature sensor:#ifdef CONFIG_DALLAS_TEMPERATURE_SENSOR
// Initialzise the dallas one wire sensor and read temperature
init_and_read_dallas_one_wire_sensor(&dallas_temperature);
printf("Dallas temperature sensor measurement: %f\n", dallas_temperature);
#endifDeclare and define the new functions required by the new sensor in
sensor_functions.handsensor_functions.cfiles. Enclose the definition of the new functions under the preprocessor directives to avoid dependency issues.#ifdef CONFIG_DALLAS_TEMPERATURE_SENSOR
/* Dallas OneWire Temperature Sensor */
#define GPIO_DS18B20_0 4 // OneWire Pin
#define MAX_DEVICES (1)
#define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT)
#define SAMPLE_PERIOD (1000) // milliseconds
OneWireBus *owb;
// Create DS18B20 OneWire_devices on the 1-Wire bus
DS18B20_Info *OneWire_devices[MAX_DEVICES] = {0};
OneWireBus_ROMCode device_rom_codes[MAX_DEVICES] = {0};
OneWireBus_SearchState search_state = {0};
// Takes in n measurements and sets the average to dallas_tempearature
void init_and_read_dallas_one_wire_sensor(float *dallas_temperature)
{
int n = 1;
...
#endifIn
config_mesh.h,- Assign a constant to the new sensor type
// Measurement header definitions
#define MEASUREMENT_TYPE_ACCELERATION 1
#define MEASUREMENT_TYPE_DS18B20_T 2
#define MEASUREMENT_TYPE_BME280_PHT 3 // BME280 pressure, humidity and temperature mesurements alltogether
#define MEASUREMENT_TYPE_TOP_FFT 4 // Top frequency components data generated with ESP DSP FFT
#define MEASUREMENT_TYPE_ANALOG_SENSOR 5 // Analog read measurements
- Assign a constant to the new sensor type
In root node,
We read the data segment of the mesh packet in the root node and parse that into a
structure. Configure the server payload structure inconfig_mesh.htypedef struct
{
float temperature;
} server_payload_ds18b20_t;Parse the payload. In
mesh_maih.h, there is a section where it switches between different sensor types and applies the correct parsing logic.// If the recived packet contains acceleration data
if (in->measurement_type == MEASUREMENT_TYPE_ACCELERATION)
{
In deepVibe Server
In
config_socket_app.h, add a new data structure to hold the new sensor data.typedef struct
{
int64_t measurement_rx_time;
float temperature;
} DS18B20_Measurement;In
main_server.c, add a function to parse the new sensor data.// Process DS18B20 data (Dallas temperature sensor)
void process_ds18b20_data(server_payload_ds18b20_t ds18b20_payload, uint8_t mac_addr[])
{
printf("Processing DS18B20 data..\n");
DS18B20_Measurement ds18b20_meas;
ds18b20_meas.measurement_rx_time = get_current_timestamp();
ds18b20_meas.temperature = ds18b20_payload.temperature;
printf("Received temperature value: %f\n", ds18b20_meas.temperature);
#if ENABLE_TD_ENGINE
insert_DS18B20_data_to_TDEngine(mac_addr, &ds18b20_meas);
#endif
#if ENABLE_TIMESCALE_DB
insert_DS18B20_data_to_timescaleDB(mac_addr, &ds18b20_meas);
#endif
}In the
mainfunction of the same file, there is a section which switches between different sensor types. Add the corresponding logic under the new sensor type.else if (payload_header.measurement_type == MEASUREMENT_TYPE_DS18B20_T)
{
server_payload_ds18b20_t ds18b20_payload = {0};
uint8_t *data_pt = (uint8_t *)&ds18b20_payload;
int ret = read_incoming_data(sizeof(server_payload_ds18b20_t), data_pt);
if (ret == ERR_CONNECTION)
{
continue;
}
process_ds18b20_data(ds18b20_payload, payload_header.mac_addr);
}Any required changes for inserting data into the DB should go in
timescaleDB_interface.hand `timescaleDB_interface.cfiles. (ForTDEngineuse the corresponding files to that.)
Grafana
- Create a new panel or add the new sensor data to an existing panel. timescale-DB connection is made through a
plugin. Follow how the existing panels are setup to create / modify the dashboard to accommodate new sensor data.