#include "../include/API.h" API::API(String user, String password, String host, bool https = true){ this->user = user; this->password = password; this->serveurHost = host; this->https = https; this->token = ""; this->client = new WiFiEspClient(); } bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){ WiFi.init(espSerial); // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present");//FIXME: rm debug return false; } // attempt to connect to WiFi network int status = WL_IDLE_STATUS; // the Wifi radio's status while (status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: ");//FIXME: rm debug Serial.println(wifiId);//FIXME: rm debug status = WiFi.begin(wifiId.c_str(), wifiPass.c_str()); } return true; } JSONVar* API::connect(){ JSONVar* sortie = new JSONVar(); JSONVar data; data["identity"] = this->user; data["password"] = this->password; String StrData = JSONVar::stringify(data); 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 } this->client->println("POST /api/collections/users/auth-with-password HTTP/1.1"); this->client->println("Host: iot.epi.cb85.software"); this->client->println("Content-Type: application/json"); this->client->println("Content-Length: " + String(StrData.length())); this->client->println(); this->client->println(StrData); this->client->println("Connection: close"); this->client->println(); } //TODO: implement connect methods return sortie; }