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");
}
}
}