I use 2 sensor modules (DHT11 and TSL2561) with an Arduino Nano and want to send the meassured values via nRF24L01 Module to another nRF24L01 Module. I checked the other Topics but nothing worked so far.
Thats the Transmitter Code:
void loop() {
String stringAll, stringTemp1, stringTemp2, stringHum1, stringHum2, stringLux1, stringLux2;
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
Serial.print("Read DHT11 failed");
return;
}
stringAll += (int)temperature;
stringAll += ", ";
stringAll += (int)humidity;
stringAll += ", ";
sensors_event_t event;
tsl.getEvent(&event);
if (event.light) {
stringAll += event.light;
stringAll += " lux";
}
radio.write(&stringAll, sizeof(stringAll));
// Serial.println(stringAll);
delay(1100);
}
Thats the format (example) of the string if I test with "Serial.println(stringAll)": 25, 36, 123.00 lux
Thats the Receiver Code:
void loop() {
//Serial.println("omfg");
if (radio.available()) {
// char stringAll[1000] = "";
String stringAll;
len = radio.getDynamicPayloadSize();
radio.read( &stringAll, len );
Serial.println(stringAll);
}
}
In this case nothing appears in the serial monitor of the Receiver. If I use " char stringAll[1000] = ""; " instead of " String stringAll; " just two squares appear in each line of the Serial monitor.
I have no clue how to solve this problem and would be grateful if someone could help me.