From 789cab74a9958afeff372d19bf6961dd029f11af Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 3 Apr 2023 16:19:32 +0200 Subject: [PATCH] refactor(iot): change type of connect on api --- IOT/lib/API/src/API.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/IOT/lib/API/src/API.cpp b/IOT/lib/API/src/API.cpp index f458068..f5240a8 100644 --- a/IOT/lib/API/src/API.cpp +++ b/IOT/lib/API/src/API.cpp @@ -27,10 +27,9 @@ bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){ } return true; } - -JSONVar* API::connect(){ +bool API::connect(){ this->client->stop(); - JSONVar* sortie =nullptr; + bool sortie = false; JSONVar data; @@ -69,14 +68,16 @@ JSONVar* API::connect(){ String str = responce.substring(responce.indexOf("{"),responce.lastIndexOf("}")+1); - sortie = new JSONVar(JSONVar::parse(str)); + JSONVar jsonRes = new JSONVar(JSONVar::parse(str)); - this->token = JSONVar::stringify((*sortie)["token"]); + this->token = JSONVar::stringify(jsonRes["token"]); this->token = this->token.substring(1,this->token.length()-1); this->client->stop(); + sortie = true; + return sortie; } @@ -90,7 +91,8 @@ bool API::sendValute(String val, String poubelleID, String valUnit, bool full){ String strData = JSONVar::stringify(data); if(this->token == ""){ - this->connect(); + bool connected = this->connect(); + if(!connected)return false; } if(this->https){ if (!this->client->connectSSL(("https://" + this->serveurHost).c_str(), 443)) {