NRF24L01+ RadioHead, message assembling

Hello,

I would like to kindly ask you for your help. RadioHead library is great but i did not find proper manual how to send more complicated message via NRF24.

My project idea is simple. I want to have one server and several clients. Client send sensor value to server.

I managed to send int value but for example DHT22 can send temperature and humidity. It cause mess on server and it is really hard to read it.

Example
got request from : 0x1: 230
got request from : 0x2: -1
got request from : 0x2: 27
got request from : 0x2: -2
got request from : 0x2: 24
got request from : 0x1: 230

I used -1 and -2 as pointer -1/humidity, -2/temperature. But in case that one value is not going to be send, than it break all my logic. Co I would like to have format like this:

got request from : 0x1: AirQuality 230
got request from : 0x2: Humidity 27
got request from : 0x2: Temperature 24
got request from : 0x1: AirQuality 230

I tried to implement it but I cannot see any change on Server side.

I really appreciate if you can provide me with any recommendation.

My code for client.

  void transmiter(int SensorValue)
  {
    uint8_t TypeOfData[] = "Air Quality: ";
    uint16_t DataToSend = SensorValue;
    uint8_t data[3] = {TypeOfData, (DataToSend >> 8), (DataToSend >> 8)}; // extract as {lower byte, upper byte)
    Serial.println("Sending to nrf24_reliable_datagram_server");

    // Send a message to manager_server
    if (manager.sendtoWait(data, sizeof(data, 2), SERVER_ADDRESS))
    {
      // Now wait for a reply from the server
      uint8_t len = sizeof(buf);
      uint8_t from;
      if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
      {
        Serial.print("got reply from : 0x");
        Serial.print(from, HEX);
        Serial.print(": ");
        Serial.println((char*)buf);
      }
      else
      {
        Serial.println("No reply, is nrf24_reliable_datagram_server running?");
      }
    }
    else
      Serial.println("sendtoWait failed");
    delay(500);
  }

Server code

void loop()
{
  if (manager.available())
  {
    // Wait for a message addressed to us from the client
    uint8_t len = sizeof(buf);
    uint8_t from;
    if (manager.recvfromAck(buf, &len, &from))
    {
      Serial.print("got request from : 0x");
      Serial.print(from, HEX);
      Serial.print(": ");
      //Serial.println((char*)buf);
      //Serial.println((buf[1] << 8) | buf[0]);
      Serial.println((buf[2] << 8) | (buf[1] << 8) | buf[0]);

      // Send a reply back to the originator client
      if (!manager.sendtoWait(data, sizeof(data), from))
        Serial.println("sendtoWait failed");
    }
  }
}
    uint8_t TypeOfData[] = "Air Quality: ";
    uint16_t DataToSend = SensorValue;
    uint8_t data[3] = {TypeOfData, (DataToSend >> 8), (DataToSend >> 8)}; // extract as {lower byte, upper byte)

What do you think this does (ie what do you think ends up in the data array) ??

if you read the documentation, what do you think
sizeof(data, 2)does?

I am not familiar with the RadioHead library. This Simple nRF24L01+ Tutorial uses the TMRh20 library.

...R

Put the data that you want to send in a struct. Provide .sendtoWait with a pointer to that struct and it's length. Receive a struct on the RX side and confirm its length.

gfvalvo:
Put the data that you want to send in a struct. Provide .sendtoWait with a pointer to that struct and it’s length. Receive a struct on the RX side and confirm its length.

The way the nRF24 works I reckon there is almost a NIL chance of there being an error in the message if the sender receives an auto-acknowledgement

…R

Probably true. RadioHead also inserts a checksum.

J-M-L:

    uint8_t TypeOfData[] = "Air Quality: ";

uint16_t DataToSend = SensorValue;
   uint8_t data[3] = {TypeOfData, (DataToSend >> 8), (DataToSend >> 8)}; // extract as {lower byte, upper byte)



What do you think this does (ie what do you think ends up in the data array) ??


if you read the [documentation](http://en.cppreference.com/w/cpp/language/sizeof), what do you think 


sizeof(data, 2)



does?

I expect that on the end in array is going to be ["Air Quality: "][Value part 1(8b)][Value part 2(8b)]

With this it workslike acharm and int value is send.

    uint16_t DataToSend = SensorValue;
    uint8_t data[2] = {DataToSend, (DataToSend >> 8)};

you are right, there should be

sizeof(data, 3)

but result is the same

qobouky:
I expect that on the end in array is going to be ["Air Quality: "][Value part 1(8b)][Value part 2(8b)]

With this it workslike acharm and int value is send.

    uint16_t DataToSend = SensorValue;

uint8_t data[2] = {DataToSend, (DataToSend >> 8)};

your expectation is wrong... how could all this fit in 2 bytes anyway...?

So basically your 2 bytes in the array are the very same two bytes at address DataToSend... not really useful

qobouky:
you are right, there should be

sizeof(data, 3)

but result is the same

Nope... read the doc...