I have an Arduino UNO connected via USB to RPi. The Arduino reads a Temperature-Humidity sensor, forms a JSON object with the ArduinoJson library, and sends it through serial to RPi, received by NodeRED. There I parse the JSON, and everything works fine, except when I disconnect the sensor from Arduino. The values read are nan, and thus the JSON formed carries a NaN instead of a value. This causes the JSON node to report a parsing error. Why? How do I have to handle NaN values?
I wonder if the only way is to filter the incoming JSON string manually with a function node. In this case I could the whole parsing there as well. So, is the JSON node useless?
Here is part of my arduino code:
#include <ArduinoJson.h>
#include <DHT.h>
#include <DHT_U.h>
float hum;
float temp;
StaticJsonBuffer<200> jsonBufferIn;
void loop() {
hum = dht.readHumidity();
temp= dht.readTemperature();
StaticJsonBuffer<200> jsonBufferOut;
JsonObject& root = jsonBufferOut.createObject();
root["AirTemp"] = temp;
root["Humidity"] = hum;
root.printTo(Serial);
delay(30000);
}