feat: connection OK
This commit is contained in:
parent
3208c2ff6b
commit
7861cfae51
@ -31,7 +31,7 @@ bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){
|
||||
}
|
||||
|
||||
JSONVar* API::connect(){
|
||||
JSONVar* sortie = new JSONVar();
|
||||
JSONVar* sortie =nullptr;
|
||||
|
||||
JSONVar data;
|
||||
|
||||
@ -43,9 +43,7 @@ JSONVar* API::connect(){
|
||||
if(this->https){
|
||||
if (!this->client->connectSSL(this->serveurHost.c_str(), 443)) {
|
||||
Serial.println("NOT Connected to server");
|
||||
return sortie;//TODO: faire meuilleur gestion d'erreur
|
||||
}else{
|
||||
//TODO: implement http (no 's') request
|
||||
return sortie;
|
||||
}
|
||||
this->client->println("POST /api/collections/users/auth-with-password HTTP/1.1");
|
||||
this->client->println("Host: iot.epi.cb85.software");
|
||||
@ -55,7 +53,29 @@ JSONVar* API::connect(){
|
||||
this->client->println(StrData);
|
||||
this->client->println("Connection: close");
|
||||
this->client->println();
|
||||
}else{
|
||||
//TODO: implement http (no 's') request
|
||||
}
|
||||
//TODO: implement connect methods
|
||||
|
||||
|
||||
while (!client->available()) {
|
||||
|
||||
}
|
||||
|
||||
String responce = "";
|
||||
while (client->available()) {
|
||||
responce += (char)client->read();
|
||||
}
|
||||
|
||||
String str = responce.substring(responce.indexOf("{"),responce.lastIndexOf("}")+1);
|
||||
|
||||
sortie = new JSONVar(JSONVar::parse(str));
|
||||
|
||||
this->token = JSONVar::stringify((*sortie)["token"]);
|
||||
|
||||
this->token = this->token.substring(1,this->token.length()-1);
|
||||
|
||||
Serial.println(this->token);
|
||||
|
||||
return sortie;
|
||||
}
|
@ -22,9 +22,9 @@ void setup(){
|
||||
|
||||
testAPI = new API("patrick","Patrick123","https://iot.epi.cb85.software");
|
||||
|
||||
testAPI->wifiBegin("Clement4G","Clement123",&Serial);
|
||||
testAPI->wifiBegin("Clement4G","Clement123",&Serial1);
|
||||
|
||||
Serial.print(JSONVar::stringify(testAPI->connect()));
|
||||
Serial.print(JSONVar::stringify(*(testAPI->connect())));
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user