hello all.
Im using moteinos with RFM95 for sending data from different types of sensors - termo, laser, etc.
several "servers" devices send this data to one "client" (or "receiver") device.
currently in server code I use for data array of float:
float data_buf[23];
//[0]-[14]: ext thermosensors,
//[15]: int sensor,
//[16]: batV,
//[17]: RSSI,
//[18]: Vcc,
//[19]: light,
//[20]: snow_depth,
//[21]: LRF temp,
//[22]: LRF Vcc
on client side I use the same array and print received data like:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 5000, &from)) {
Serial.print(F("T0:"));Serial.println((*(float *)&buf[0])); // buf[0]
Serial.print(F("T1:"));Serial.println((*(float *)&buf[4])); // buf[1]
..............................
etc
Some servers has different number of sensors.
for example - server1 has 5 termosensors, and server2 - has 10 termosensors.
I want implement in code some data packet which will be used on all servers and client side.
something like:
server1 - has 5 termosensors:
typedef struct {
float temp1;
float temp2;
float temp3;
float temp4;
float temp5;
} Payload;
Payload srv_data;
server2 - has 10 termosensors:
typedef struct {
float temp1;
float temp2;
float temp3;
float temp4;
float temp5;
.............................
float temp10;
} Payload;
Payload srv_data;
And on client side I need have a code that will receive data from server1 and server2
is it possible in c++?
what is the best practices for such task?
btw - can I use array in struct?
like:
typedef struct {
float temp_sensors[10];
..........
Any advice and examples would be very helpful.
Thank you.