2020-05-20 00:32:49 +01:00
|
|
|
#ifndef JsonUtils_h
|
|
|
|
#define JsonUtils_h
|
|
|
|
|
2020-05-14 23:23:45 +01:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <IPAddress.h>
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
|
|
|
|
class JsonUtils {
|
|
|
|
public:
|
2020-05-21 08:42:21 +01:00
|
|
|
static void readIP(JsonObject& root, const String& key, IPAddress& ip) {
|
|
|
|
if (!root[key].is<String>() || !ip.fromString(root[key].as<String>())) {
|
|
|
|
ip = INADDR_NONE;
|
2020-05-14 23:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
2020-05-21 08:42:21 +01:00
|
|
|
static void writeIP(JsonObject& root, const String& key, const IPAddress& ip) {
|
|
|
|
if (ip != INADDR_NONE) {
|
|
|
|
root[key] = ip.toString();
|
2020-05-14 23:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-05-20 00:32:49 +01:00
|
|
|
|
|
|
|
#endif // end JsonUtils
|