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 SQLHandler import SQLconnect
from datetime import datetime
import json
app = Flask(__name__)
@ -32,9 +33,13 @@ def add_sensordata():
now = datetime.now()
timestamp = {"timestamp":now}
sensordata.update(timestamp)
sql = "INSERT INTO sensordata (timestamp, temperature, moisture, humidity) VALUES (%s, %s, %s, %s)"
mycursor.execute(sql, now, sensordata)
mycursor.execute(sql, sensordata)
mydb.commit()

@ -1,7 +1,5 @@
//Bibliotheken der API Anbindung
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
//Bibliotheken für die Temperatursensoren
@ -22,6 +20,7 @@ const char* password = "AndyNicoChiara";
const char* serverName = "http://192.168.178.170:3564/sensordata";
// Moisture sensor variables
int sense_Pin = 0; // sensor input at Analog pin A0
int value = 0;
@ -32,6 +31,9 @@ int pos = 0;
//Konstante für die ZEit
const int timer = 30;
void setup() {
Serial.begin(9600);
dht.begin();
@ -96,29 +98,16 @@ void loop() {
WiFiClient client;
HTTPClient http;
// Your Domain name with URL path or IP address with path
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);
// 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.println(httpResponseCode);
// Read response
Serial.print(http.getString());
// Free resources
http.end();
Serial.println("closing connection");
}
else {
Serial.println("WiFi Disconnected");
}

Loading…
Cancel
Save