|
|
|
@ -2,6 +2,7 @@
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
|
|
|
|
|
|
|
|
//Bibliotheken für die Temperatursensoren
|
|
|
|
//Bibliotheken für die Temperatursensoren
|
|
|
|
#include "DHT.h"
|
|
|
|
#include "DHT.h"
|
|
|
|
@ -19,7 +20,7 @@ DHT dht(DHT_PIN, DHT_TYPE);
|
|
|
|
const char* ssid = "Andy";
|
|
|
|
const char* ssid = "Andy";
|
|
|
|
const char* password = "AndyNicoChiara";
|
|
|
|
const char* password = "AndyNicoChiara";
|
|
|
|
|
|
|
|
|
|
|
|
const char* serverName = "http://192.168.178.154/sensordata";
|
|
|
|
const char* serverName = "http://192.168.178.170/sensordata";
|
|
|
|
|
|
|
|
|
|
|
|
// Moisture sensor variables
|
|
|
|
// Moisture sensor variables
|
|
|
|
int sense_Pin = 0; // sensor input at Analog pin A0
|
|
|
|
int sense_Pin = 0; // sensor input at Analog pin A0
|
|
|
|
@ -28,7 +29,7 @@ int value = 0;
|
|
|
|
//Sensor Pin an dVariable
|
|
|
|
//Sensor Pin an dVariable
|
|
|
|
int pos = 0;
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//Konstante für die Zeit in min
|
|
|
|
//Konstante für die ZEit
|
|
|
|
const int timer = 30;
|
|
|
|
const int timer = 30;
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
@ -87,15 +88,26 @@ void loop() {
|
|
|
|
// Your Domain name with URL path or IP address with path
|
|
|
|
// Your Domain name with URL path or IP address with path
|
|
|
|
http.begin(client, serverName);
|
|
|
|
http.begin(client, serverName);
|
|
|
|
// Specify content-type header
|
|
|
|
// Specify content-type header
|
|
|
|
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
//http.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
// Data to send with HTTP POST
|
|
|
|
// Data to send with HTTP POST
|
|
|
|
String httpRequestData = "moisture=" + String(moisture) + "&humidity="+ String(humidity) + "&temperature=" + String(temperature);
|
|
|
|
//String httpRequestData = "moisture=" + String(moisture) + "&humidity="+ String(humidity) + "&temperature=" + String(temperature);
|
|
|
|
// Send HTTP POST request
|
|
|
|
// Send HTTP POST request
|
|
|
|
int httpResponseCode = http.POST(httpRequestData);
|
|
|
|
//int httpResponseCode = http.POST(httpRequestData);
|
|
|
|
|
|
|
|
|
|
|
|
// If you need an HTTP request with a content type: application/json, use the following:
|
|
|
|
// If you need an HTTP request with a content type: application/json, use the following:
|
|
|
|
//http.addHeader("Content-Type", "application/json");
|
|
|
|
http.addHeader("Content-Type", "application/json");
|
|
|
|
//int httpResponseCode = http.POST("{\"api_key\":\"tPmAT5Ab3j7F9\",\"sensor\":\"BME280\",\"value1\":\"24.25\",\"value2\":\"49.54\",\"value3\":\"1005.14\"}");
|
|
|
|
|
|
|
|
|
|
|
|
StaticJsonDocument<200> doc;
|
|
|
|
|
|
|
|
// Add values in the document
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doc["temperature"] = temperature;
|
|
|
|
|
|
|
|
doc["moisture"] = moisture;
|
|
|
|
|
|
|
|
doc["humidity"] = humidity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String requestBody;
|
|
|
|
|
|
|
|
serializeJson(doc, requestBody);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int httpResponseCode = http.POST(requestBody);
|
|
|
|
|
|
|
|
|
|
|
|
// If you need an HTTP request with a content type: text/plain
|
|
|
|
// If you need an HTTP request with a content type: text/plain
|
|
|
|
//http.addHeader("Content-Type", "text/plain");
|
|
|
|
//http.addHeader("Content-Type", "text/plain");
|
|
|
|
@ -114,10 +126,3 @@ void loop() {
|
|
|
|
ESP.deepSleep(timer * 1000000);
|
|
|
|
ESP.deepSleep(timer * 1000000);
|
|
|
|
yield();
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void startDeepSleep(){
|
|
|
|
|
|
|
|
Serial.println("Going to deep sleep...");
|
|
|
|
|
|
|
|
ESP.deepSleep(5 * 1000000);
|
|
|
|
|
|
|
|
yield();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|