updated so i can send fresh data to hva api
This commit is contained in:
@@ -4,11 +4,16 @@
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiAP.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <HTTPClient.h>
|
||||
|
||||
|
||||
// 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); }
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user