51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#include <WiFi.h>
|
|
#include <WiFiClient.h>
|
|
#include <WiFiAP.h>
|
|
#include <WiFiMulti.h>
|
|
#include <HTTPClient.h>
|
|
|
|
//hernoem de libraries zodat ze makkelijker gebruikt kunnen worden
|
|
WiFiMulti wifiMulti;
|
|
HTTPClient http;
|
|
|
|
//voorbeeld waarden geven om te testen
|
|
char temperature = 20;
|
|
char light = 3500;
|
|
const float humidity = 54;
|
|
const char* ssid = "iotroam";
|
|
const char* password = "BcgrFpX3kl";
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
//vraag aand wifi library om mac adress te printen om in dlo te zetten
|
|
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");
|
|
|
|
}
|
|
|
|
void loop() {
|
|
//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(temperature);
|
|
//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
|
|
delay(10000);
|
|
}
|