From 7b21441976f8575f556c3e9a830b41b255e669f0 Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 14 May 2023 23:16:16 +0200 Subject: [PATCH] fix some thing --- IOT/config.ini | 6 ++++-- IOT/lib/API/include/API.h | 8 +++++--- IOT/lib/API/src/API.cpp | 3 +++ IOT/lib/Capteur/src/HumiTemp.cpp | 10 +++++++++- IOT/lib/Capteur/src/Ultrason.cpp | 6 +++--- IOT/src/Program.cpp | 1 - 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/IOT/config.ini b/IOT/config.ini index 0481ac1..50af406 100644 --- a/IOT/config.ini +++ b/IOT/config.ini @@ -45,7 +45,9 @@ build_flags = -D API_HOST=\"iot.epi.cb85.software\" ;---CAPTEUR FULL CONFIG--- - - -D ULTRA_SOUND_FULL=\"10\" + ;valFull/valReset + -D ULTRA_SOUND_FULL=\"5/10\" + ;tempmin:tempmax/hummin:humax -D DHT_FULL=\"20:30/60:80\" + ;poid max -D POID_FULL=\"100\" \ No newline at end of file diff --git a/IOT/lib/API/include/API.h b/IOT/lib/API/include/API.h index 463f6f6..0fd0b57 100644 --- a/IOT/lib/API/include/API.h +++ b/IOT/lib/API/include/API.h @@ -49,8 +49,6 @@ public: */ bool connect(); - //TODO :: Check wifibegin avant - private: @@ -89,7 +87,11 @@ private: */ String token; - + /** + * @brief wifi démmaré + * + */ + bool init; }; diff --git a/IOT/lib/API/src/API.cpp b/IOT/lib/API/src/API.cpp index a9b45d0..f6e5161 100644 --- a/IOT/lib/API/src/API.cpp +++ b/IOT/lib/API/src/API.cpp @@ -8,11 +8,13 @@ API::API(String user, String password, String host, bool https){ this->https = https; this->token = ""; this->client = new WiFiEspClient(); + this->init = false; } bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){ WiFi.init(espSerial); + this->init = true; // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { @@ -28,6 +30,7 @@ bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){ return true; } bool API::connect(){ + if(!this->init)return false; this->client->stop(); bool sortie = false; diff --git a/IOT/lib/Capteur/src/HumiTemp.cpp b/IOT/lib/Capteur/src/HumiTemp.cpp index 10fbd56..2aeb2a4 100644 --- a/IOT/lib/Capteur/src/HumiTemp.cpp +++ b/IOT/lib/Capteur/src/HumiTemp.cpp @@ -11,8 +11,16 @@ String HumiTemp::read(){ int hum = this->capteur->readHumidity(true); int temp = this->capteur->readTemperature(false,true); + String stemp = this->fullVall.substring(0, this->fullVall.indexOf("/")); + String shum = this->fullVall.substring(this->fullVall.indexOf("/")+1, this->fullVall.length()); + + int mintemp = stemp.substring(0, stemp.indexOf(":")).toInt(); + int maxtemp = stemp.substring(stemp.indexOf(":")+1, stemp.length()).toInt(); + int minhum = shum.substring(0, shum.indexOf(":")).toInt(); + int maxhum = shum.substring(shum.indexOf(":")+1, shum.length()).toInt(); + //valeur pour un élevage d'astico de pèche selon chatGPT - if((temp > 20 && temp < 30) && (hum > 60 && hum < 80)){//TODO: passer les valeurs en config + if((temp > mintemp && temp < maxtemp) && (hum > minhum && hum < maxhum)){ this->full = true; }else{ this->full = false; diff --git a/IOT/lib/Capteur/src/Ultrason.cpp b/IOT/lib/Capteur/src/Ultrason.cpp index 3154f0e..12137cb 100644 --- a/IOT/lib/Capteur/src/Ultrason.cpp +++ b/IOT/lib/Capteur/src/Ultrason.cpp @@ -9,11 +9,11 @@ Ultrason::Ultrason(int trigeur, int echo, String fullVall): String Ultrason::read(){ int sortie = this->capteur->read(); - if (sortie < this->fullVall.toInt()) + if (sortie < this->fullVall.substring(0, this->fullVall.indexOf("/")).toInt()) { this->full = true; - }else{ + }else if (sortie > this->fullVall.substring(this->fullVall.indexOf("/")+1, this->fullVall.length()).toInt()){ this->full = false; } return String(sortie); -}//TODO: faire en sorte que full se reset avec une autre val \ No newline at end of file +} \ No newline at end of file diff --git a/IOT/src/Program.cpp b/IOT/src/Program.cpp index 33f31af..e20c7c9 100644 --- a/IOT/src/Program.cpp +++ b/IOT/src/Program.cpp @@ -45,5 +45,4 @@ void Program::loop(){ Serial.println(); - delay(1000); } \ No newline at end of file