WorkerNode should work and api fixed

main
thunic 3 years ago
parent d1a1fc3dc2
commit 281585a408

@ -2,6 +2,7 @@ from flask import Flask, jsonify, request
from DatabaseObject import sensordata from DatabaseObject import sensordata
from SQLHandler import SQLconnect from SQLHandler import SQLconnect
from datetime import datetime from datetime import datetime
import json
app = Flask(__name__) app = Flask(__name__)
@ -32,9 +33,13 @@ def add_sensordata():
now = datetime.now() now = datetime.now()
timestamp = {"timestamp":now}
sensordata.update(timestamp)
sql = "INSERT INTO sensordata (timestamp, temperature, moisture, humidity) VALUES (%s, %s, %s, %s)" sql = "INSERT INTO sensordata (timestamp, temperature, moisture, humidity) VALUES (%s, %s, %s, %s)"
mycursor.execute(sql, now, sensordata) mycursor.execute(sql, sensordata)
mydb.commit() mydb.commit()

@ -1,7 +1,5 @@
//Bibliotheken der API Anbindung
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
//Bibliotheken für die Temperatursensoren //Bibliotheken für die Temperatursensoren
@ -22,6 +20,7 @@ const char* password = "AndyNicoChiara";
const char* serverName = "http://192.168.178.170:3564/sensordata"; const char* serverName = "http://192.168.178.170:3564/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
int value = 0; int value = 0;
@ -32,6 +31,9 @@ int pos = 0;
//Konstante für die ZEit //Konstante für die ZEit
const int timer = 30; const int timer = 30;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
dht.begin(); dht.begin();
@ -96,29 +98,16 @@ void loop() {
WiFiClient client; WiFiClient client;
HTTPClient http; HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(client, serverName); http.begin(client, serverName);
// 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(requestBody); int httpResponseCode = http.POST(requestBody);
// If you need an HTTP request with a content type: text/plain
//http.addHeader("Content-Type", "text/plain");
//int httpResponseCode = http.POST("Hello, World!");
Serial.print("HTTP Response code: "); Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode); Serial.println(httpResponseCode);
// Read response
Serial.print(http.getString());
// Free resources
http.end(); http.end();
Serial.println("closing connection");
} }
else { else {
Serial.println("WiFi Disconnected"); Serial.println("WiFi Disconnected");
} }

Loading…
Cancel
Save