2020-05-19 23:32:49 +00:00
|
|
|
#ifndef JsonUtils_h
|
|
|
|
#define JsonUtils_h
|
|
|
|
|
2020-05-14 22:23:45 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <IPAddress.h>
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
|
|
|
|
class JsonUtils {
|
|
|
|
public:
|
2020-05-21 07:42:21 +00: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 22:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-21 07:42:21 +00:00
|
|
|
static void writeIP(JsonObject& root, const String& key, const IPAddress& ip) {
|
|
|
|
if (ip != INADDR_NONE) {
|
|
|
|
root[key] = ip.toString();
|
2020-05-14 22:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-05-19 23:32:49 +00:00
|
|
|
|
|
|
|
#endif // end JsonUtils
|