Skip to content

Commit

Permalink
Update sesami client
Browse files Browse the repository at this point in the history
  • Loading branch information
sktometometo committed Oct 8, 2023
1 parent 7cfe1c9 commit 3ba9d48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
22 changes: 12 additions & 10 deletions arduino_lib/sesami_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ std::optional<String> 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;
}

Expand All @@ -112,13 +110,21 @@ std::optional<String> 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<String> get_sesami_status(String device_uuid, String api_key)
Expand All @@ -129,8 +135,6 @@ std::optional<String> 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;
}

Expand All @@ -157,8 +161,6 @@ std::optional<String> 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;
}

Expand Down
14 changes: 12 additions & 2 deletions sketchbooks/m5atoms3_sesami_client/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 3ba9d48

Please sign in to comment.