finished the script so i can send data to api
This commit is contained in:
@@ -4,38 +4,47 @@
|
|||||||
#include <WiFiMulti.h>
|
#include <WiFiMulti.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
|
//hernoem de libraries zodat ze makkelijker gebruikt kunnen worden
|
||||||
WiFiMulti wifiMulti;
|
WiFiMulti wifiMulti;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
|
//voorbeeld waarden geven om te testen
|
||||||
char temperature = 20;
|
char temperature = 20;
|
||||||
char light = 3500;
|
char light = 3500;
|
||||||
char humidity = 54;
|
const float humidity = 54;
|
||||||
const char* ssid = "iotroam";
|
const char* ssid = "iotroam";
|
||||||
const char* password = "BcgrFpX3kl";
|
const char* password = "BcgrFpX3kl";
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
//vraag aand wifi library om mac adress te printen om in dlo te zetten
|
||||||
Serial.print("mac adress:");
|
Serial.print("mac adress:");
|
||||||
Serial.println(WiFi.macAddress());
|
Serial.println(WiFi.macAddress());
|
||||||
|
//verbinden met wifi
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
wifiMulti.addAP("ObsidianAmstelveen", "drijversstraatmaastricht");
|
wifiMulti.addAP("ObsidianAmstelveen", "drijversstraatmaastricht");
|
||||||
wifiMulti.addAP("iotroam", "BcgrFpX3kl");
|
wifiMulti.addAP("iotroam", "BcgrFpX3kl");
|
||||||
|
//een loop zodat het script wacht tot de esp32s3 verbind met het internet
|
||||||
while (wifiMulti.run() != WL_CONNECTED) {
|
while (wifiMulti.run() != WL_CONNECTED) {
|
||||||
}
|
}
|
||||||
|
//print het ip adress van de esp32s3 naar de console
|
||||||
Serial.println(WiFi.localIP());
|
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");
|
http.begin("http://hva-onto.nl/api/ti/map/measurements/add?api-key=efffc47610ea6282a3416f71b51b3a");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
//voeg een header toe aan de post request
|
||||||
String httpRequestData = "api_key=efffc47610ea6282a3416f71b51b3a&temperature=temperature&light=light&humidity=humidity";
|
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);
|
int httpResponseCode = http.POST(httpRequestData);
|
||||||
|
//print de response code naar
|
||||||
Serial.print("HTTP Response code: ");
|
Serial.print("HTTP Response code:");
|
||||||
Serial.println(httpResponseCode);
|
Serial.println(httpResponseCode);
|
||||||
break(10000)
|
//wacht x aanal miliseconden
|
||||||
|
delay(10000);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user