|
|
|
|
@ -1,7 +1,21 @@
|
|
|
|
|
//Bibliotheken der API Anbindung
|
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
|
|
|
|
|
|
//Bibliotheken für die Temperatursensoren
|
|
|
|
|
#include "DHT.h"
|
|
|
|
|
#define DHT_TYPE DHT22
|
|
|
|
|
|
|
|
|
|
//Bibliotheken für die Servosteuerung
|
|
|
|
|
#include <Servo.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Servo myservo;
|
|
|
|
|
|
|
|
|
|
const int DHT_PIN = D5;
|
|
|
|
|
DHT dht(DHT_PIN, DHT_TYPE);
|
|
|
|
|
|
|
|
|
|
const char* ssid = "Andy";
|
|
|
|
|
const char* password = "AndyNicoChiara";
|
|
|
|
|
|
|
|
|
|
@ -19,8 +33,12 @@ unsigned long timerDelay = 5000;
|
|
|
|
|
int sense_Pin = 0; // sensor input at Analog pin A0
|
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
|
|
//Sensor Pin an dVariable
|
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(9600);
|
|
|
|
|
dht.begin();
|
|
|
|
|
delay(2000);
|
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
|
Serial.println("Connecting");
|
|
|
|
|
@ -33,19 +51,38 @@ void setup() {
|
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
|
|
|
|
|
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
|
|
|
|
|
|
|
|
|
|
myservo.attach(D4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
|
|
|
|
|
Serial.print("MOISTURE LEVEL : ");
|
|
|
|
|
value= analogRead(sense_Pin);
|
|
|
|
|
/*value= value/10;*/
|
|
|
|
|
Serial.println(value);
|
|
|
|
|
delay(1000);
|
|
|
|
|
Serial.print("MOISTURE LEVEL : ");
|
|
|
|
|
float moisture = analogRead(sense_Pin);
|
|
|
|
|
/*value= value/10;*/
|
|
|
|
|
Serial.println(moisture);
|
|
|
|
|
delay(1000);
|
|
|
|
|
float humidity = dht.readHumidity();
|
|
|
|
|
float temperature = dht.readTemperature();
|
|
|
|
|
Serial.print("Temperatur: ");
|
|
|
|
|
Serial.print(temperature);
|
|
|
|
|
Serial.println("%");
|
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
|
|
Serial.print("°C, Luftfeuchtigkeit: ");
|
|
|
|
|
Serial.print(humidity);
|
|
|
|
|
|
|
|
|
|
for(pos = 0; pos < 180; pos += 1) { // von 0 bis 180 Grad, in Schritten von einem Grad
|
|
|
|
|
myservo.write(pos); // sagt dem Servomotor, in welche Position sich drehen soll
|
|
|
|
|
delay(15); // wartet 15 Millisekunden
|
|
|
|
|
}
|
|
|
|
|
for(pos = 180; pos>=1; pos-=1) { // und das gleiche zurück
|
|
|
|
|
myservo.write(pos);
|
|
|
|
|
delay(15);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if ((millis() - lastTime) > timerDelay) {
|
|
|
|
|
//Check WiFi connection status
|
|
|
|
|
if(WiFi.status()== WL_CONNECTED){
|
|
|
|
|
@ -58,7 +95,7 @@ if ((millis() - lastTime) > timerDelay) {
|
|
|
|
|
// Specify content-type header
|
|
|
|
|
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
// Data to send with HTTP POST
|
|
|
|
|
String httpRequestData = "moisture=" + value;
|
|
|
|
|
String httpRequestData = "moisture=" + String(moisture) + "&humidity="+ String(humidity) + "&temperature=" + String(temperature);
|
|
|
|
|
// Send HTTP POST request
|
|
|
|
|
int httpResponseCode = http.POST(httpRequestData);
|
|
|
|
|
|
|
|
|
|
@ -81,4 +118,5 @@ if ((millis() - lastTime) > timerDelay) {
|
|
|
|
|
}
|
|
|
|
|
lastTime = millis();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|