introduced soil thresholds
This commit is contained in:
parent
4d685c8edf
commit
47d58777c5
@ -19,6 +19,7 @@ lib_deps =
|
||||
19 #DHT sensor library
|
||||
31 #Adafruit Unified Sensor
|
||||
AutoConnect@^1.1.7
|
||||
; ESPRandom@^1.3.3
|
||||
AsyncMqttClient@^0.8.2
|
||||
ArduinoJson@^6.15.2
|
||||
; ESPRandom@^1.3.3
|
||||
; PubSubClient@^2.8
|
||||
@ -1,4 +1,5 @@
|
||||
#include <header.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -6,6 +7,9 @@ extern "C"
|
||||
#include "freertos/timers.h"
|
||||
}
|
||||
|
||||
#define MQTT_VALVE_COMMAND MQTT_TOPIC_BASE_SUB "/" MQTT_DEVICE_ID "/valve"
|
||||
#define MQTT_SOIL_PROPERTIES MQTT_TOPIC_BASE_SUB "/" MQTT_DEVICE_ID "/soil"
|
||||
|
||||
AsyncMqttClient mqttClient;
|
||||
TimerHandle_t mqttReconnectTimer;
|
||||
TimerHandle_t wifiReconnectTimer;
|
||||
@ -87,7 +91,7 @@ void onMqttSubscribe(uint16_t packetId, uint8_t qos)
|
||||
|
||||
void onMqttUnsubscribe(uint16_t packetId)
|
||||
{
|
||||
Serial.println("Unsubscribe acknowledged.");
|
||||
Serial.print("Unsubscribe acknowledged.");
|
||||
Serial.print(" packetId: ");
|
||||
Serial.println(packetId);
|
||||
}
|
||||
@ -98,18 +102,36 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
if (strcmp(topic, "smartgarden/commands") == 0 ) {
|
||||
Serial.println("executing command...");
|
||||
if (strcmp(topic, MQTT_VALVE_COMMAND) == 0 ) {
|
||||
Serial.println("toggling valve...");
|
||||
Serial.println(topic);
|
||||
toggleValve();
|
||||
}
|
||||
if (strcmp(topic, MQTT_SOIL_PROPERTIES) == 0 ) {
|
||||
Serial.println("recieving soil thresholds...");
|
||||
Serial.println(topic);
|
||||
Serial.println(payload);
|
||||
// const int capacity = JSON_OBJECT_SIZE(3) + 2 * JSON_OBJECT_SIZE(1);
|
||||
StaticJsonDocument<1024> doc;
|
||||
DeserializationError err = deserializeJson(doc, payload);
|
||||
if (err == DeserializationError::Ok) {
|
||||
int fc = doc["fc"];
|
||||
int pwp = doc["pwp"];
|
||||
int sat = doc["sat"];
|
||||
Serial.println(doc.size());
|
||||
Serial.println(doc["fc"].as<char *>());
|
||||
Serial.println(doc["pwp"].as<char *>());
|
||||
Serial.println(doc["sat"].as<char *>());
|
||||
setSoilProperties(fc, pwp, sat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onMqttPublish(uint16_t packetId)
|
||||
{
|
||||
Serial.print("Publish acknowledged: ");
|
||||
Serial.print(" packetId: ");
|
||||
Serial.println(packetId);
|
||||
// Serial.print("Publish acknowledged: ");
|
||||
// Serial.print(" packetId: ");
|
||||
// Serial.println(packetId);
|
||||
}
|
||||
|
||||
void setupConnections()
|
||||
|
||||
@ -17,6 +17,10 @@
|
||||
#include <AutoConnect.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
|
||||
// fix for core panic during wifi initialization
|
||||
// #define configMINIMAL_STACK_SIZE 2048
|
||||
// #define CONFIG_TIMER_TASK_STACK_SIZE 8192
|
||||
|
||||
// DHT11
|
||||
#define PIN_DHT11 14
|
||||
|
||||
@ -70,4 +74,5 @@ extern void publishMessage(const char *topic, const char *msg);
|
||||
|
||||
// sensors
|
||||
void readSensors();
|
||||
void toggleValve();
|
||||
void toggleValve();
|
||||
void setSoilProperties(int FC, int PWP, int SAT);
|
||||
@ -14,6 +14,13 @@ extern "C"
|
||||
|
||||
char buffer[16];
|
||||
|
||||
// Feldkapazität des Bodens in Prozent: Standard ist Humus
|
||||
int fieldCapacity = 44;
|
||||
// PWP des Bodens in Prozent: Standard ist Humus
|
||||
int permanentWiltingPoint = 25;
|
||||
// Boden vollständig gesättigt bei (Prozent): Standard ist Humus
|
||||
int soilSaturation = 69;
|
||||
|
||||
void readSensors()
|
||||
{
|
||||
float lxValue = readLightSensorValue();
|
||||
@ -88,3 +95,15 @@ void toggleValve()
|
||||
1, /* Priority of the task. */
|
||||
NULL); /* Task handle. */
|
||||
}
|
||||
|
||||
void setSoilProperties(int FC, int PWP, int SAT) {
|
||||
fieldCapacity = FC;
|
||||
permanentWiltingPoint = PWP;
|
||||
soilSaturation = SAT;
|
||||
Serial.print("fieldCapacity: ");
|
||||
Serial.println(fieldCapacity);
|
||||
Serial.print("permanentWiltingPoint: ");
|
||||
Serial.println(permanentWiltingPoint);
|
||||
Serial.print("soilSaturation: ");
|
||||
Serial.println(soilSaturation);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user