From 4f1c1c51c866fac92987fd71a5ccd7ea71072fa2 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 26 Sep 2023 15:10:02 +0200 Subject: [PATCH] updated so i can send fresh data to hva api --- arduino/sensor combo/combi/combi.ino | 48 ++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/arduino/sensor combo/combi/combi.ino b/arduino/sensor combo/combi/combi.ino index dda4ace..72d7995 100644 --- a/arduino/sensor combo/combi/combi.ino +++ b/arduino/sensor combo/combi/combi.ino @@ -4,11 +4,16 @@ #include #include #include +#include +#include + // LDR = 12, geeft gaan dat het variable LDR terugwijst naar 12. #define LDR 17 //tegen DHT11 library zeggen dat we het variabel TLV(Temparatuur LuchtVochtigheid) willen geven en dat het de informatie van pin 18 kan halen. DHT11 TLV(18); +WiFiMulti wifiMulti; +HTTPClient http; void setup() { @@ -21,9 +26,29 @@ void setup() { pinMode(6, OUTPUT); digitalWrite(6, HIGH); + + Serial.print("mac adress:"); + Serial.println(WiFi.macAddress()); + //verbinden met wifi + WiFi.mode(WIFI_STA); + wifiMulti.addAP("ObsidianAmstelveen", "drijversstraatmaastricht"); + wifiMulti.addAP("iotroam", "BcgrFpX3kl"); + //een loop zodat het script wacht tot de esp32s3 verbind met het internet + while (wifiMulti.run() != WL_CONNECTED) { + } + //print het ip adress van de esp32s3 naar de console + Serial.println(WiFi.localIP()); + + //gebruikt deze website om posts requests naar toe te sturen + http.begin("http://hva-onto.nl/api/ti/map/measurements/add?api-key=efffc47610ea6282a3416f71b51b3a"); + digitalWrite(4, HIGH); + + } void loop() { + digitalWrite(5, LOW); + //int geeft aan dat het een geheeld nummer moet zijn, als je float gebruikt kan het ook nog decimalen hebben // eerste 2 zijn van DHT om data van af te lezen en op te slaan in het variabel //laatste is om de lichtsensor analoog af te lezen en op te slaan in een variabel @@ -42,16 +67,25 @@ void loop() { Serial.print("LDR reading: "); Serial.println(Lichtsterkte); + delay(400); + + + + + //voeg een header toe aan de post request + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + //de data stoppen in een variabel voor de post request + String httpRequestData = "type=temperature&value=" + String(Temparatuur); + //stuur de post request naar de server toe + int httpResponseCode = http.POST(httpRequestData); + //print de response code naar + Serial.print("HTTP Response code:"); + Serial.println(httpResponseCode); + //wacht x aanal miliseconden digitalWrite(5, HIGH); - digitalWrite(4, HIGH); - delay(100); - digitalWrite(5, LOW); - digitalWrite(4, LOW); -// if (Lichtsterkte > 3000){} - // else{ - // digitalWrite(6, LOW); } + } \ No newline at end of file