finished the script so i can send data to api
This commit is contained in:
@@ -4,38 +4,47 @@
|
||||
#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;
|
||||
char humidity = 54;
|
||||
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());
|
||||
|
||||
|
||||
http.begin("http://hva-onto.nl/api/ti/map/measurements/add");
|
||||
//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() {
|
||||
|
||||
String httpRequestData = "api_key=efffc47610ea6282a3416f71b51b3a&temperature=temperature&light=light&humidity=humidity";
|
||||
|
||||
//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);
|
||||
|
||||
Serial.print("HTTP Response code: ");
|
||||
//print de response code naar
|
||||
Serial.print("HTTP Response code:");
|
||||
Serial.println(httpResponseCode);
|
||||
break(10000)
|
||||
//wacht x aanal miliseconden
|
||||
delay(10000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user