diff --git a/arduino_lib/sesami_util.h b/arduino_lib/sesami_util.h index 320c846e..b7852e44 100644 --- a/arduino_lib/sesami_util.h +++ b/arduino_lib/sesami_util.h @@ -98,8 +98,6 @@ std::optional operation_sesami(String device_uuid, String api_key, int c if (!http.begin(url)) { - USBSerial.println("Connection failed.\nWaiting 5 seconds before retrying...\n"); - delay(5000); return std::nullopt; } @@ -112,13 +110,21 @@ std::optional operation_sesami(String device_uuid, String api_key, int c http.addHeader("x-api-key", api_key); int responseCode = http.POST(body); String result_body = http.getString(); + http.end(); USBSerial.printf("** POST result **\n"); USBSerial.printf("responseCode: %d\n", responseCode); - body.replace("\\\"", "\""); - USBSerial.println("body: " + result_body); - http.end(); + USBSerial.println("result_body: " + result_body); - return result_body; + if (responseCode != 200) + { + return std::nullopt; + } + else + { + body.replace("\\\"", "\""); + USBSerial.println("body: " + result_body); + return result_body; + } } std::optional get_sesami_status(String device_uuid, String api_key) @@ -129,8 +135,6 @@ std::optional get_sesami_status(String device_uuid, String api_key) if (!http.begin(url)) { - USBSerial.println("Connection failed.\nWaiting 5 seconds before retrying...\n"); - delay(5000); return std::nullopt; } @@ -157,8 +161,6 @@ std::optional get_sesami_history(String device_uuid, String api_key) if (!http.begin(url)) { - USBSerial.println("Connection failed.\nWaiting 5 seconds before retrying...\n"); - delay(5000); return std::nullopt; } diff --git a/sketchbooks/m5atoms3_sesami_client/src/main.cpp b/sketchbooks/m5atoms3_sesami_client/src/main.cpp index f16f80aa..d753d8a5 100644 --- a/sketchbooks/m5atoms3_sesami_client/src/main.cpp +++ b/sketchbooks/m5atoms3_sesami_client/src/main.cpp @@ -106,8 +106,18 @@ void loop() } if (ret) { - response_json["success"] = true; - response_json["message"] = command + " success"; + DeserializationError error = deserializeJson(result_json, ret.value().c_str()); + if (error) + { + response_json["success"] = false; + response_json["message"] = "deserializeJson() failed during operation_sesami: " + String(error.c_str()) + ", result: " + ret.value(); + } + else + { + response_json["success"] = true; + response_json["message"] = command + " success"; + response_json["result"] = result_json; + } } else {