Site icon Renzo Mischianti

Tdata sending and receiving complex structure

Does anybody have a example or experience in sending tdata array using E32 lora module and library. I think with tdata i can get all my values into 1 message. I'm trying to send two values from my each Node (5 nodes in total) and receive them at my server and split the data back up so i can store in modbus registers. I think I have the node code working as below but can't work out how to receive it and split it back up Node sending code.

float tdata[10];

// The loop function is called in an endless loop
void loop()

//attempt for tdata battery node setup
Serial.print("T2=");
tdata[2]=l_hour;
Serial.println(tdata[2]);
Serial.print("T3=");
tdata[3]=volt;// future battery voltage monitor
Serial.println(tdata[3]);

ResponseStatus rs = e32ttl.sendFixedMessage(0,3,4,(uint8_t*)&tdata, sizeof(tdata));
Serial.println(rs.getResponseDescription());
Some of my server receive code is:

float tdata[10];
float rtdata[40];

// The loop function is called in an endless loop
void loop() {

if (e32ttl.available() > 1) {
	ResponseContainer rs = e32ttl.receiveInitialMessage(sizeof(tdata));
	// ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Message));
	struct Message message = *(tdata*) rt.data;
	Serial.println(message.type);

	memcpy( type, rt.data.c_str(), sizeof(type) );

	for (byte i = 2; i < 3; i++)// if you change i=0 to i=1 you get the second value, <2 is the number of rows so if sending more values need to increase at the moment it has 2 rows

	if (from==2)// adding an if statement to try and seperate clients
	{
		Serial.print("T");
		Serial.print(i);
		Serial.print(": ");
		Serial.println(word(rtdata[i])); // T2 will be flow and T3 will be for battery voltage
		regBank.set(40003, (word)(rtdata[i]));// flow reading
	}

	for (byte i = 3; i < 4; i++) // if you change i=0 to i=1 you get the second value, <2 is the number of rows so if sending more values need to increase at the moment it has 2 rows

	if (from==2)// adding an if statement to try and separate clients
	{
		Serial.print("T");
		Serial.print(i);
		Serial.print(": ");
		Serial.println(word(rtdata[i])); // T2 will be flow and T3 will be for battery voltage
		regBank.set(40004, (word)(rtdata[i]));// flow reading
	}
}
Exit mobile version