Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
508 B

  1. #ifndef JsonUtils_h
  2. #define JsonUtils_h
  3. #include <Arduino.h>
  4. #include <IPAddress.h>
  5. #include <ArduinoJson.h>
  6. class JsonUtils {
  7. public:
  8. static void readIP(JsonObject& root, const String& key, IPAddress& ip) {
  9. if (!root[key].is<String>() || !ip.fromString(root[key].as<String>())) {
  10. ip = INADDR_NONE;
  11. }
  12. }
  13. static void writeIP(JsonObject& root, const String& key, const IPAddress& ip) {
  14. if (ip != INADDR_NONE) {
  15. root[key] = ip.toString();
  16. }
  17. }
  18. };
  19. #endif // end JsonUtils