refactor(iot): change type of connect on api

This commit is contained in:
Clement 2023-04-03 16:19:32 +02:00
parent 59728b9694
commit 789cab74a9

View File

@ -27,10 +27,9 @@ bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){
} }
return true; return true;
} }
bool API::connect(){
JSONVar* API::connect(){
this->client->stop(); this->client->stop();
JSONVar* sortie =nullptr; bool sortie = false;
JSONVar data; JSONVar data;
@ -69,14 +68,16 @@ JSONVar* API::connect(){
String str = responce.substring(responce.indexOf("{"),responce.lastIndexOf("}")+1); 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->token = this->token.substring(1,this->token.length()-1);
this->client->stop(); this->client->stop();
sortie = true;
return sortie; return sortie;
} }
@ -90,7 +91,8 @@ bool API::sendValute(String val, String poubelleID, String valUnit, bool full){
String strData = JSONVar::stringify(data); String strData = JSONVar::stringify(data);
if(this->token == ""){ if(this->token == ""){
this->connect(); bool connected = this->connect();
if(!connected)return false;
} }
if(this->https){ if(this->https){
if (!this->client->connectSSL(("https://" + this->serveurHost).c_str(), 443)) { if (!this->client->connectSSL(("https://" + this->serveurHost).c_str(), 443)) {