MOJan R. SeylerAvdylValentin Hirzel
Published

Giess - Beast

A smart solution for demands on watering plants.

AdvancedFull instructions provided1,510
Giess - Beast

Things used in this project

Hardware components

Raspberry Pi Zero
Raspberry Pi Zero
×1
Web of Things Relais Zettler AZ822
×1
GY-BME280
×1
ESP32 - TTGO
×1

Software apps and online services

MQTT
MQTT
Raspbian
Raspberry Pi Raspbian
Node-RED
Node-RED
SAP SQL Anywhere
SAP SQL Anywhere
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

ESP32_Main

Arduino
Includes:
- WIFI
- MQTT
- BME280 Data read
- OLED use
-Relais
//Librarys
#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <SSD1306.h>

//all MQTTT settings
const char* ssid = "Your Wifi Name";
const char* password = "Your Wifi Passowrd";
const char* mqttserver = "192.168.178.58//broker Ip";
const int mqttport = 1883;
const char* mqttUser = "";
const char* mqttPassword = "";
const int LED = 16; //LED port is Pin GPIO16
// Variablen
unsigned long currentMillis = millis(); //used for Delay
unsigned long previousMillis = 0;
long interval = 1000;       //cleaner than Dealy() function
unsigned long pumpTimer = 0;
float temperature;
float pressure;
float humidity;
const char* publish_topic_temperature = "ESP32/temperature";
const char* publish_topic_pressure = "ESP32/pressure";
const char* publish_topic_humidity = "ESP32/humidity";
bool status;
bool pumpOn;
Adafruit_BME280 bme; // I2C
char C[9]; // used as buffer for MQTT
char message;
//calibration Values
float tempoffset;
float pressureoffset;

#define MQTT_VERSION_3_1
#define MQTT_MAX_PACKET_SIZE 128
#define mqtt_port 1883
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
SSD1306 display(0x3c, 5, 4); // instance for the OLED. Addr, SDA, SCL

WiFiClient wifiClient;
PubSubClient client(wifiClient);

void setup() {
  Serial.begin(115200);
  Serial.println("startup");                    //ESP startet
  pinMode(LED,OUTPUT);
  bme_startup();
  setup_wifi();                                 //Connect to Wifi
  display.init();                               //starten des Bildschirms
  display.flipScreenVertically();               // does what is says
  display.setFont(ArialMT_Plain_16);            // does what is says
  display.setTextAlignment(TEXT_ALIGN_LEFT);    // Set the origin of text to top left
  client.setServer(mqttserver, mqttport);       //Setzten der Servervariablen
  client.setCallback(callback);                 //Callback setzten
  reconnect();
  Serial.println("we are connected, lets send a Massage");
  client.publish("esp32/connection", "ESP32 connected");
  subscribe();
  digitalWrite(LED,HIGH);
  display.clear();
}

void loop() {
  unsigned long currentMillis = millis();
  if(WiFi.status() != WL_CONNECTED) {
    setup_wifi();
  }
  reconnect();
  client.loop();
  
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    display.clear(); 
    previousMillis = currentMillis;
      sendValues(); 
  }
  display.display();
  checkPump();
}

Callback

Arduino
The Callback for the MQTT
void callback(char* topic, byte *payload, unsigned int length) {
  Serial.println("-------new message from broker-----");
  Serial.print("topic:");
  Serial.println(topic);
  Serial.print("Message:");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.write(payload, length);
  Serial.println();
  if (String(topic) == "esp32/calibrate/pressure") {
    pressureoffset = byte2float(payload, length);
  }
  if (String(topic) == "esp32/calibrate/temperature") {
    tempoffset = byte2float(payload, length);
  }
  if (String(topic) == "esp32/pump") {
    activatePump(byte2float(payload, length));
  }
  if (String(topic) == "esp32/set/frequency") {
    interval = (int)(1000 * byte2float(payload,length));
  }
}

functions

Arduino
Used functions
void setup_wifi() {
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    digitalWrite(LED, HIGH);
    delay(500);
    Serial.print(".");
    digitalWrite(LED, LOW);
    delay(500);
    if (millis() > 100000 && millis() < 110000) {
      ESP.restart();
    }
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.println("\nConnecting to MQTT...");

    if (client.connect("ESP32Client", mqttUser, mqttPassword )) {
      Serial.println("connected");
    } else {
      Serial.print("failed with state ");
      Serial.print(client.state());
      delay(2000);
    }
  }
}

void sendValues() {
  String text;
  //  Serial.println("Trying to send some Data");
  temperature = bme.readTemperature();
  pressure = bme.readPressure() / 100.0F;
  //  Serial.println(temperature);
  //  Serial.println(pressure);
  humidity = bme.readHumidity();
  //  Serial.println("Data gathered");
  //applying callibration
  pressure += pressureoffset;
  temperature += tempoffset;
  //sending and displaying Data
  float2char(temperature);
  client.publish(publish_topic_temperature, C );
  OLED_writeText("Temperatur: ", 0, 0);
  text = String(temperature, 1);
  OLED_writeText(text, 0, 3);
  // temperature is sent
  float2char(pressure);
  client.publish(publish_topic_pressure, C);
  OLED_writeText("Druck: ", 1, 0);
  text = String(pressure, 1);
  OLED_writeText(text, 1, 2);
  //pressure is sent
  float2char(humidity);
  client.publish(publish_topic_humidity, C);
  OLED_writeText("Luftfeuchte: ", 2, 0);
  text = String(humidity, 1);
  OLED_writeText(text, 2, 3);
  //  Serial.println("Data sent");
}
void bme_startup() {
  Wire.begin(5, 4);
  status = bme.begin(0x76);  //I2C addresse vom BME280
  if (!status) {
    Serial.println("Could not find a valid bmeBME280 sensor, check wiring!");
    //    display.clear();
    //    OLED_writeText("no Sensor detected, check wiring!", 0, 0);
    //    display.display();
    while (1);
    Serial.println("restarting...");
    digitalWrite(LED, LOW);
    delay(1000);
    digitalWrite(LED,HIGH);
    ESP.restart();
  }
  Serial.println("bmeBME280 is working correctly");
  //  OLED_writeText("Sensor is working",0,0);
}
void float2char(float input) {
  sprintf(C, "%f", input);
}

float byte2float(byte* b, int length) {
  bool negative;
  double f;
  int fullStop;
  int a;
  int position;
  position = length;

  float temp;
  if ( b[0] == 0x2d ) {
    negative = true;
    a = 1;
    //    Serial.println("negative");
  }
  else {
    negative = false;
    a = 0;
    //    Serial.println("positiv");
  }
  for (int i = a; i < length ; i++) {
    if ( b[i] == 0x2e ) {
      fullStop = length - i + a;
      //      Serial.println(fullStop);
      continue;
    }
    temp = 0;
    temp = float(b[i]) - 48;
//    Serial.println(temp);

    if (position > 0) {
      f += temp * (toPowerOf(10, position--));
//      Serial.print(f);
//      Serial.print(" ");
    }
  }
  if (negative == true) {
    f *= -1;
  }
  if (fullStop > length || fullStop <= 1) {
    fullStop = 0;
  }
  if (negative == true && fullStop < 1) {
    f /= 10;
  }
  if (fullStop > 1) {
    f = f / (toPowerOf(10, fullStop));
  }
  f /= 10;
//  Serial.print("Float: ");
//  Serial.println(f);
  return f;
}
int toPowerOf(float base, float power) {
  int result = base;
  if (power == 1) {
    return base;
  }
  else {
    for (int a = 1; a < power; a++) {
      result = base * result;
    }
    return result;
  }
}

void activatePump(float time) {
  if (1000 * time + millis() <= 4294967295) {
    pumpTimer = millis() + (int)time * 1000;
  } else {
    pumpTimer = (int) (time * 1000 - (4294967295 - millis()));
    Serial.println("Pump running for: ");
  }
  digitalWrite(LED, LOW);
  digitalWrite(pump, High);
  pumpOn = true;
}
void checkPump() {
  if (pumpTimer >= millis() && pumpTimer <= millis() + 1000 && pumpOn) {
    digitalWrite(LED, HIGH);
    digitalWrite(pump, LOW);
    pumpOn = false;
  }
}

MQTT subscribe Topics

Arduino
void subscribe(){
  client.subscribe("esp32/calibrate/temperature");
  client.subscribe("esp32/calibrate/pressure");
  client.subscribe("esp32/calibrate/humidity");
  client.subscribe("esp32/set/frequency");
  client.subscribe("esp32/pump");
}

OLED

Arduino
controlling of the OLED screen
void OLED_writeText(String text, uint8_t lOffset, uint8_t tab) {
  uint8_t lineOffset = lOffset * 16;
  uint8_t tabOffset = tab * 32;
  display.drawString(tabOffset, lineOffset, text);
}

Weather Flow

JSON
[{"id":"2b71fea8.da02b2","type":"tab","label":"WeatherForecast","disabled":false,"info":""},{"id":"2f2f1f4b.64081","type":"ui_gauge","z":"2b71fea8.da02b2","name":"","group":"da844983.55475","order":1,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"C","format":"{{msg.payload}}","min":"-20","max":"40","colors":["#0125ff","#3be23a","#ff0000"],"seg1":"","seg2":"","x":750,"y":340,"wires":[]},{"id":"a34c3b67.5231c8","type":"openweathermap","z":"2b71fea8.da02b2","name":"Weather","wtype":"current","lon":"","lat":"","city":"Stuttgart","country":"Germany","language":"en","x":380,"y":260,"wires":[["219f5fc5.ff3db","7762caeb.e152c4","ebd6562c.839838","174ac8b5.beee67"]]},{"id":"a8d7ab2f.7a5a38","type":"ui_button","z":"2b71fea8.da02b2","name":"","group":"9fbc682c.2e9918","order":2,"width":0,"height":0,"passthru":false,"label":"Update","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"time","x":220,"y":260,"wires":[["a34c3b67.5231c8","e8c0ac90.dbc34"]]},{"id":"3be3e191.4ab81e","type":"ui_gauge","z":"2b71fea8.da02b2","name":"Barometer","group":"ed338719.cde5c","order":1,"width":0,"height":0,"gtype":"gage","title":"Barometer","label":"hPa","format":"{{msg.payload}}","min":"850","max":"1150","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":750,"y":180,"wires":[]},{"id":"91d2ccfb.d087a","type":"ui_text","z":"2b71fea8.da02b2","group":"9fbc682c.2e9918","order":3,"width":0,"height":0,"name":"","label":"last update:","format":"{{msg.payload}}","layout":"col-center","x":750,"y":420,"wires":[]},{"id":"e8c0ac90.dbc34","type":"moment","z":"2b71fea8.da02b2","name":"","topic":"time","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"0","adjType":"minutes","adjDir":"add","format":"DD.MM.YYYY  hh:mm:ss","locale":"de_DE","output":"payload","outputType":"msg","outTz":"Europe/Berlin","x":410,"y":440,"wires":[["91d2ccfb.d087a","efaa48e1.678618"]]},{"id":"5bca8a8d.45bcc4","type":"ui_text","z":"2b71fea8.da02b2","group":"9fbc682c.2e9918","order":1,"width":0,"height":0,"name":"","label":"Current weather:","format":"{{msg.payload}}","layout":"col-center","x":770,"y":140,"wires":[]},{"id":"84d84d37.2956e","type":"ui_gauge","z":"2b71fea8.da02b2","name":"","group":"4ffec3be.1eda6c","order":1,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{msg.payload}}","min":"0","max":"100","colors":["#0125ff","#3be23a","#ff0000"],"seg1":"","seg2":"","x":740,"y":260,"wires":[]},{"id":"efaa48e1.678618","type":"ui_toast","z":"2b71fea8.da02b2","position":"top right","displayTime":"1","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"Update","name":"Aktualisierung","x":760,"y":460,"wires":[]},{"id":"89690862.b4d018","type":"ui_chart","z":"2b71fea8.da02b2","name":"","group":"da844983.55475","order":2,"width":0,"height":0,"label":"Temperature diagramm","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"waiting for input","dot":false,"ymin":"20","ymax":"40","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":790,"y":380,"wires":[[]]},{"id":"219f5fc5.ff3db","type":"function","z":"2b71fea8.da02b2","name":"tempc","func":"return {payload: msg.payload.tempc};","outputs":1,"noerr":0,"x":590,"y":360,"wires":[["89690862.b4d018","2f2f1f4b.64081"]]},{"id":"7762caeb.e152c4","type":"function","z":"2b71fea8.da02b2","name":"humidity","func":"return {payload: msg.payload.humidity};","outputs":1,"noerr":0,"x":580,"y":280,"wires":[["84d84d37.2956e","faae54e9.f0d018"]]},{"id":"ebd6562c.839838","type":"function","z":"2b71fea8.da02b2","name":"pressure","func":"return {payload: msg.payload.pressure};","outputs":1,"noerr":0,"x":580,"y":200,"wires":[["3be3e191.4ab81e","cef79895.c96238"]]},{"id":"174ac8b5.beee67","type":"function","z":"2b71fea8.da02b2","name":"tempc","func":"return {payload: msg.payload.detail};","outputs":1,"noerr":0,"x":570,"y":140,"wires":[["5bca8a8d.45bcc4"]]},{"id":"faae54e9.f0d018","type":"ui_chart","z":"2b71fea8.da02b2","name":"","group":"4ffec3be.1eda6c","order":2,"width":0,"height":0,"label":"Humidity diagramm","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"waiting for input","dot":false,"ymin":"0","ymax":"100","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":770,"y":300,"wires":[[]]},{"id":"cef79895.c96238","type":"ui_chart","z":"2b71fea8.da02b2","name":"","group":"ed338719.cde5c","order":2,"width":0,"height":0,"label":"Pressure diagramm","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"waiting for input","dot":false,"ymin":"900","ymax":"1100","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":770,"y":220,"wires":[[]]},{"id":"e326f58e.cf7768","type":"inject","z":"2b71fea8.da02b2","name":"update","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":260,"wires":[["a8d7ab2f.7a5a38"]]},{"id":"da844983.55475","type":"ui_group","z":"","name":"Temperature","tab":"fa94a0fc.02a6a","order":3,"disp":true,"width":"6","collapse":true},{"id":"9fbc682c.2e9918","type":"ui_group","z":"","name":"Beschreibung","tab":"fa94a0fc.02a6a","order":1,"disp":true,"width":"6","collapse":false},{"id":"ed338719.cde5c","type":"ui_group","z":"","name":"Pressure","tab":"fa94a0fc.02a6a","order":4,"disp":true,"width":"6","collapse":false},{"id":"4ffec3be.1eda6c","type":"ui_group","z":"","name":"Humidity","tab":"fa94a0fc.02a6a","order":5,"disp":true,"width":"6","collapse":false},{"id":"fa94a0fc.02a6a","type":"ui_tab","z":"","name":"Wetter","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Sensor Data

JSON
[{"id":"bf7aba69.287a78","type":"tab","label":"Sensor Data","disabled":false,"info":""},{"id":"93381021.6eab7","type":"mqtt in","z":"bf7aba69.287a78","name":"ESP32","topic":"ESP32/temperature","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":110,"y":40,"wires":[["f75ad0d0.360ac","7a465428.4a114c"]]},{"id":"e57bb00f.237e1","type":"mqtt in","z":"bf7aba69.287a78","name":"ESP32","topic":"ESP32/pressure","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":110,"y":120,"wires":[["539fb883.34fe88","cb492ff6.4a331"]]},{"id":"d29c1d7a.61c81","type":"mqtt in","z":"bf7aba69.287a78","name":"Verbindungsstatus","topic":"esp32/connection","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":150,"y":260,"wires":[["2253fd0c.97abf2","dc042640.b8cb18"]]},{"id":"aa94edf1.5d713","type":"ui_gauge","z":"bf7aba69.287a78","name":"","group":"1907e2e4.438f45","order":1,"width":0,"height":0,"gtype":"gage","title":"Thermometer","label":"C","format":"{{payload}}","min":"-10","max":"40","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":500,"y":20,"wires":[]},{"id":"f3f4e303.0ce34","type":"ui_gauge","z":"bf7aba69.287a78","name":"","group":"1f6bd5bc.8be7c2","order":1,"width":0,"height":0,"gtype":"gage","title":"Barometer","label":"hPa","format":"{{payload}}","min":"850","max":"1150","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":490,"y":100,"wires":[]},{"id":"7a465428.4a114c","type":"ui_chart","z":"bf7aba69.287a78","name":"","group":"1907e2e4.438f45","order":2,"width":0,"height":0,"label":"Temperatur Diagramm","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"waiting for input","dot":false,"ymin":"18","ymax":"26","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":520,"y":60,"wires":[[]]},{"id":"539fb883.34fe88","type":"ui_chart","z":"bf7aba69.287a78","name":"","group":"1f6bd5bc.8be7c2","order":2,"width":0,"height":0,"label":"Luftdruck Diagramm","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"waiting for input","dot":false,"ymin":"900","ymax":"1100","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":520,"y":140,"wires":[[]]},{"id":"2253fd0c.97abf2","type":"ui_toast","z":"bf7aba69.287a78","position":"top right","displayTime":"1","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"Connection","name":"Benachrichtugung Verbindung","x":550,"y":260,"wires":[]},{"id":"f75ad0d0.360ac","type":"string","z":"bf7aba69.287a78","name":"Shorten","methods":[{"name":"left","params":[{"type":"num","value":"4"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":280,"y":20,"wires":[["aa94edf1.5d713"]]},{"id":"cb492ff6.4a331","type":"string","z":"bf7aba69.287a78","name":"Shorten","methods":[{"name":"left","params":[{"type":"num","value":"6"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":280,"y":100,"wires":[["f3f4e303.0ce34"]]},{"id":"dc042640.b8cb18","type":"ui_audio","z":"bf7aba69.287a78","name":"Gert verbunden","group":"4a394ee7.7e058","voice":"en-GB","always":true,"x":510,"y":300,"wires":[]},{"id":"671a587d.ac9a88","type":"mqtt in","z":"bf7aba69.287a78","name":"ESP32","topic":"ESP32/humidity","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":110,"y":200,"wires":[["c8a8fa3d.4dac18","a6c57dbf.01eb9"]]},{"id":"b139e3f4.2e06d","type":"ui_gauge","z":"bf7aba69.287a78","name":"","group":"d4de7e35.97e9c8","order":1,"width":0,"height":0,"gtype":"gage","title":"Hygrometer","label":"%","format":"{{payload}}","min":"0","max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":490,"y":180,"wires":[]},{"id":"c8a8fa3d.4dac18","type":"ui_chart","z":"bf7aba69.287a78","name":"","group":"d4de7e35.97e9c8","order":2,"width":0,"height":0,"label":"Luftfeuchtigkeit Diagramm","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"waiting for input","dot":false,"ymin":"0","ymax":"100","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":540,"y":220,"wires":[[]]},{"id":"a6c57dbf.01eb9","type":"string","z":"bf7aba69.287a78","name":"Shorten","methods":[{"name":"left","params":[{"type":"num","value":"4"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":280,"y":180,"wires":[["b139e3f4.2e06d"]]},{"id":"7473d2fd.c0b3d4","type":"sqlite","z":"bf7aba69.287a78","mydb":"23fdd02a.bb88f","sqlquery":"msg.topic","sql":"","name":"create Database","x":310,"y":400,"wires":[["eb4aca9d.ecce78"]]},{"id":"19b317e.8c5b8e8","type":"inject","z":"bf7aba69.287a78","name":"create","topic":"CREATE TABLE SensorData( Timestamp TEXT PRIMARY KEY NOT NULL, Temperature REAL NOT NULL, Pressure REAL NOT NULL, Humidity REAL NOT NULL)","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":400,"wires":[["7473d2fd.c0b3d4"]]},{"id":"eb4aca9d.ecce78","type":"debug","z":"bf7aba69.287a78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":400,"wires":[]},{"id":"348ceed5.8344f2","type":"ui_template","z":"bf7aba69.287a78","group":"4a394ee7.7e058","name":"UI Table","order":2,"width":0,"height":0,"format":"<table style=\"width:100%\">\n  <tr>\n    <th>Timestamp</th>\n    <th>Temperature</th> \n    <th>Pressure</th>\n    <th>Humidity</th>\n  </tr>\n  <tr ng-repeat=\"x in msg.payload | limitTo:20\">\n    <td>{{msg.payload[$index].Timestamp}}</td>\n    <td>{{msg.payload[$index].Temperature}}</td> \n    <td>{{msg.payload[$index].Pressure}}</td>\n    <td>{{msg.payload[$index].Humidity}}</td>\n  </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":840,"y":600,"wires":[[]]},{"id":"1cda99f7.4560a6","type":"sqlite","z":"bf7aba69.287a78","mydb":"23fdd02a.bb88f","sqlquery":"msg.topic","sql":"","name":"read Query","x":690,"y":600,"wires":[["348ceed5.8344f2"]]},{"id":"68a444aa.2c5c94","type":"mqtt in","z":"bf7aba69.287a78","name":"","topic":"ESP32/temperature","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":130,"y":520,"wires":[["7494778b.7b1868"]]},{"id":"a8106b6b.b6fff","type":"mqtt in","z":"bf7aba69.287a78","name":"","topic":"ESP32/pressure","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":120,"y":560,"wires":[["22b3c9c5.fd334e"]]},{"id":"287ddcf5.81f824","type":"mqtt in","z":"bf7aba69.287a78","name":"","topic":"ESP32/humidity","qos":"0","datatype":"auto","broker":"c539eb9e.c5cfd8","x":120,"y":600,"wires":[["733f3573.20e96c","6aa97831.eadd28"]]},{"id":"7494778b.7b1868","type":"function","z":"bf7aba69.287a78","name":"set flow \"temperature\" variable","func":"flow.set(\"temperature\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":520,"wires":[[]]},{"id":"22b3c9c5.fd334e","type":"function","z":"bf7aba69.287a78","name":"set flow \"pressure\" variable","func":"flow.set(\"pressure\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":560,"wires":[[]]},{"id":"733f3573.20e96c","type":"function","z":"bf7aba69.287a78","name":"set flow \"humidity\" variable","func":"flow.set(\"humidity\",msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":600,"wires":[[]]},{"id":"6aa97831.eadd28","type":"function","z":"bf7aba69.287a78","name":"combine all variables","func":"msg.topic = \"sensor Data\"\nmsg.temperature = flow.get(\"temperature\");\nmsg.pressure = flow.get(\"pressure\");\nmsg.humidity = flow.get(\"humidity\");\nmsg.payload = 0;\nreturn msg;\n","outputs":1,"noerr":0,"x":320,"y":640,"wires":[["b1a9cc75.c964b"]],"info":"This Node uses the MQTT's humidity node as trigger, since it's the last transmission coming from the Microcontroller"},{"id":"2fbd04f1.9fe8e4","type":"comment","z":"bf7aba69.287a78","name":"Get one JSON Object of the recieved Data","info":"","x":300,"y":480,"wires":[]},{"id":"b1a9cc75.c964b","type":"moment","z":"bf7aba69.287a78","name":"","topic":"","input":"","inputType":"date","inTz":"Europe/Berlin","adjAmount":"0","adjType":"minutes","adjDir":"add","format":"","locale":"de_DE","output":"payload","outputType":"msg","outTz":"Europe/Berlin","x":540,"y":640,"wires":[["ae15a733.78b62"]]},{"id":"ae15a733.78b62","type":"function","z":"bf7aba69.287a78","name":"write to dB","func":"var newMsg = {\n \"topic\" : \"INSERT INTO SensorData (Timestamp, temperature, pressure, humidity) values ( '\" + msg.payload +  \"', \"+  msg.temperature + \", \"+ msg.pressure + \", \" + msg.humidity + \")\"\n}\nreturn newMsg;","outputs":1,"noerr":0,"x":730,"y":640,"wires":[["2abdece6.d2b124"]]},{"id":"2abdece6.d2b124","type":"sqlite","z":"bf7aba69.287a78","mydb":"23fdd02a.bb88f","sqlquery":"msg.topic","sql":"","name":"write Query","x":890,"y":640,"wires":[[]]},{"id":"a01dcfcf.6576e","type":"inject","z":"bf7aba69.287a78","name":"read","topic":"SELECT * FROM SensorData ORDER BY Timestamp DESC LIMIT 100;","payload":"","payloadType":"date","repeat":"30","crontab":"","once":false,"onceDelay":0.1,"x":550,"y":600,"wires":[["1cda99f7.4560a6"]]},{"id":"4be2de59.4afba","type":"comment","z":"bf7aba69.287a78","name":"Create your Database for Sensor Data","info":"","x":310,"y":360,"wires":[]},{"id":"c539eb9e.c5cfd8","type":"mqtt-broker","z":"","name":"","broker":"192.168.178.58","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"Connection","birthQos":"0","birthPayload":"ESP Verbunden","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1907e2e4.438f45","type":"ui_group","z":"","name":"Temperature","tab":"4d89f00b.44ec1","order":2,"disp":true,"width":"6","collapse":true},{"id":"1f6bd5bc.8be7c2","type":"ui_group","z":"","name":"Pressure","tab":"4d89f00b.44ec1","order":3,"disp":true,"width":"6","collapse":true},{"id":"4a394ee7.7e058","type":"ui_group","z":"","name":"Sensor Data","tab":"4d89f00b.44ec1","order":5,"disp":true,"width":"12","collapse":true},{"id":"d4de7e35.97e9c8","type":"ui_group","z":"","name":"Humidity","tab":"4d89f00b.44ec1","order":4,"disp":true,"width":"6","collapse":true},{"id":"23fdd02a.bb88f","type":"sqlitedb","z":"","db":"/home/pi/Documents/Sqlite/database","mode":"RWC"},{"id":"4d89f00b.44ec1","type":"ui_tab","z":"","name":"Sensor Data","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Settings and Pump

JSON
[{"id":"9ab5060d.1bf72","type":"tab","label":"Settings and Pump","disabled":false,"info":""},{"id":"ddd5dd2b.257168","type":"openweathermap","z":"9ab5060d.1bf72","name":"Wetter Stuttgart","wtype":"current","lon":"","lat":"","city":"Stuttgart","country":"Germany","language":"en","x":460,"y":100,"wires":[["bcf9a772.d75d18"]]},{"id":"9b519bf0.88b3c8","type":"mqtt out","z":"9ab5060d.1bf72","name":"set frequency","topic":"esp32/set/frequency","qos":"","retain":"","broker":"c539eb9e.c5cfd8","x":1360,"y":560,"wires":[]},{"id":"a6ec1a93.ae7958","type":"inject","z":"9ab5060d.1bf72","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 09 * * *","once":false,"onceDelay":0.1,"x":130,"y":100,"wires":[["cafe4563.5faf2"]]},{"id":"bcf9a772.d75d18","type":"function","z":"9ab5060d.1bf72","name":"Calculate TimeOn","func":"var delay = -(msg.timestamp/1000 - msg.payload.sunset);\nvar waterNeeded = flow.get(\"plant\") * flow.get(\"numberOfPlants\");\nvar time = (waterNeeded/flow.get(\"pumpFlow\")) * 3600;\nmsg.delay = delay;\nmsg.payload = time;\nmsg.pump = \"On\";\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":100,"wires":[["c029b595.861fd"]],"info":"Claculates the on time of the Pump as well as the wait time to the activation."},{"id":"c029b595.861fd","type":"delay","z":"9ab5060d.1bf72","name":"Delay till Sunset","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":840,"y":100,"wires":[["ebe32c1e.a561","83d490fb.bf3ce8","50722e67.bf839"]]},{"id":"cafe4563.5faf2","type":"function","z":"9ab5060d.1bf72","name":"conversion","func":"msg.timestamp = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":100,"wires":[["ddd5dd2b.257168"]]},{"id":"ebe32c1e.a561","type":"mqtt out","z":"9ab5060d.1bf72","name":"Power on","topic":"esp32/pump","qos":"2","retain":"","broker":"c539eb9e.c5cfd8","x":1000,"y":100,"wires":[]},{"id":"d607baf.626c4c8","type":"json","z":"9ab5060d.1bf72","name":"","property":"payload","action":"str","pretty":false,"x":890,"y":620,"wires":[["b459f2cb.259448"]]},{"id":"d9adead6.51e2c","type":"function","z":"9ab5060d.1bf72","name":"create config","func":"var config = {\n    \"plantconfig\" : {\n        \"plant\" : flow.get(\"plant\"),\n        \"numberOfPlants\" : flow.get(\"numberOfPlants\"),\n    },\n    \"pumpParameter\" : {\n        \"pumpFlow\" : flow.get(\"pumpFlow\"),\n    },\n    \"measurement\"  : {\n        \"measurementFrequency\" : flow.get(\"measurementFrequency\"),\n        \"tOffset\" : flow.get(\"tOffset\"),\n        \"pOffset\" : flow.get(\"pOffset\"),\n        \"hOffset\" : flow.get(\"hOffset\")\n    }\n}\nmsg.payload = config;\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":620,"wires":[["d607baf.626c4c8"]]},{"id":"e54675fd.5d9bc","type":"ui_button","z":"9ab5060d.1bf72","name":"","group":"1abbd1ac.b30806","order":5,"width":0,"height":0,"passthru":false,"label":"Save","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":610,"y":620,"wires":[["d9adead6.51e2c"]]},{"id":"5c9cf360.2c563c","type":"ui_numeric","z":"9ab5060d.1bf72","name":"","label":"calibrate temperature offset","tooltip":"This calibrates the sensor","group":"6b4bed71.0020b4","order":1,"width":0,"height":0,"passthru":true,"topic":"esp32/calibrate/temperature","format":"{{payload}}","min":"-5","max":"5","step":"0.1","x":840,"y":320,"wires":[["4aa3dc72.0e71dc"]],"outputLabels":["Kallibrierwert"]},{"id":"fb905b5.e464da8","type":"mqtt out","z":"9ab5060d.1bf72","name":"send calibration data","topic":"esp32/calibrate/temperature","qos":"","retain":"","broker":"c539eb9e.c5cfd8","x":1380,"y":320,"wires":[]},{"id":"62e46e17.a6e7b8","type":"ui_numeric","z":"9ab5060d.1bf72","name":"","label":"calibrate pressure offset (in 10 hPa steps)","tooltip":"This calibrates the sensor","group":"6b4bed71.0020b4","order":2,"width":0,"height":0,"passthru":true,"topic":"esp32/calibrate/pressure","format":"{{payload}}","min":"-100","max":"100","step":"0.1","x":890,"y":360,"wires":[["210f7be6.e4b67c"]],"outputLabels":["Kallibrierwert"]},{"id":"2ebddb90.36b20c","type":"mqtt out","z":"9ab5060d.1bf72","name":"send calibration data","topic":"esp32/calibrate/pressure","qos":"","retain":"","broker":"c539eb9e.c5cfd8","x":1380,"y":360,"wires":[]},{"id":"dcddbb60.19828","type":"ui_numeric","z":"9ab5060d.1bf72","name":"","label":"calibrate humidity offset in 0.1% steps","tooltip":"This calibrates the sensor","group":"6b4bed71.0020b4","order":3,"width":0,"height":0,"passthru":true,"topic":"esp32/calibrate/humidity","format":"{{payload}}","min":"-20","max":"20","step":"0.1","x":870,"y":400,"wires":[["1b878c7e.01afac"]],"outputLabels":["Kallibrierwert"]},{"id":"a63bb0e9.7874b8","type":"mqtt out","z":"9ab5060d.1bf72","name":"send calibration data","topic":"esp32/calibrate/pressure","qos":"","retain":"","broker":"c539eb9e.c5cfd8","x":1380,"y":400,"wires":[]},{"id":"4aa3dc72.0e71dc","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"tOffset\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":320,"wires":[["fb905b5.e464da8"]]},{"id":"210f7be6.e4b67c","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"pOffset\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":360,"wires":[["2ebddb90.36b20c"]]},{"id":"1b878c7e.01afac","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"hOffset\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":400,"wires":[["a63bb0e9.7874b8"]]},{"id":"b459f2cb.259448","type":"file","z":"9ab5060d.1bf72","name":"write to config","filename":"/home/pi/Documents/NodeRed/config","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":1040,"y":620,"wires":[[]]},{"id":"a3e27fad.1dee8","type":"ui_button","z":"9ab5060d.1bf72","name":"","group":"1abbd1ac.b30806","order":6,"width":0,"height":0,"passthru":false,"label":"Load Saved","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":110,"y":440,"wires":[["2c26307c.46aa2"]]},{"id":"2c26307c.46aa2","type":"file in","z":"9ab5060d.1bf72","name":"read forom config","filename":"/home/pi/Documents/NodeRed/config","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":290,"y":440,"wires":[["9c6cbf0a.bd9818"]]},{"id":"9c6cbf0a.bd9818","type":"json","z":"9ab5060d.1bf72","name":"","property":"payload","action":"obj","pretty":false,"x":450,"y":440,"wires":[["404185bc.bbe074","9e667dd2.0241a8","3cc88f02.7b7e08","ee3d04d7.739178","b70a9e7a.858d78","7c9104fb.258824","8b2a6f8f.0fd64"]]},{"id":"404185bc.bbe074","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.measurement.tOffset;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":320,"wires":[["5c9cf360.2c563c"]]},{"id":"9e667dd2.0241a8","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.measurement.pOffset;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":360,"wires":[["62e46e17.a6e7b8"]]},{"id":"3cc88f02.7b7e08","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.measurement.hOffset;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":400,"wires":[["dcddbb60.19828"]]},{"id":"3b3c66ce.461882","type":"ui_dropdown","z":"9ab5060d.1bf72","name":"","label":"Plant","tooltip":"select your Plant","place":"Select option","group":"1abbd1ac.b30806","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"Tomate","value":0.5,"type":"num"},{"label":"Gurke","value":0.3,"type":"num"}],"payload":"","topic":"","x":770,"y":480,"wires":[["6e323190.aabc5"]]},{"id":"baf7c5d4.bede38","type":"ui_text_input","z":"9ab5060d.1bf72","name":"","label":"Pump Flow","tooltip":"Insert your Pumpflow (liters per hour (l/h))","group":"1abbd1ac.b30806","order":3,"width":0,"height":0,"passthru":true,"mode":"number","delay":300,"topic":"pumpFlow","x":790,"y":440,"wires":[["19b7440d.727824"]]},{"id":"a572ea56.95047","type":"ui_text_input","z":"9ab5060d.1bf72","name":"","label":"Measurement Frequency","tooltip":"Insert Measurement Interval","group":"1abbd1ac.b30806","order":4,"width":0,"height":0,"passthru":true,"mode":"number","delay":300,"topic":"esp32/set/frequency","x":830,"y":560,"wires":[["5afcc448.ac9b3c"]]},{"id":"d84d77e5.11843","type":"ui_text_input","z":"9ab5060d.1bf72","name":"","label":"number of Plants","tooltip":"","group":"1abbd1ac.b30806","order":2,"width":0,"height":0,"passthru":true,"mode":"number","delay":300,"topic":"","x":810,"y":520,"wires":[["6eaf6404.2a5854"]]},{"id":"19b7440d.727824","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"pumpFlow\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":440,"wires":[[]]},{"id":"6e323190.aabc5","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"plant\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":480,"wires":[[]]},{"id":"6eaf6404.2a5854","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"numberOfPlants\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":520,"wires":[[]]},{"id":"5afcc448.ac9b3c","type":"function","z":"9ab5060d.1bf72","name":"setFLowVariable","func":"flow.set(\"measurementFrequency\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1170,"y":560,"wires":[["9b519bf0.88b3c8"]]},{"id":"ee3d04d7.739178","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.pumpParameter.pumpFlow;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":440,"wires":[["baf7c5d4.bede38"]]},{"id":"b70a9e7a.858d78","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.plantconfig.plant;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":480,"wires":[["3b3c66ce.461882"]]},{"id":"7c9104fb.258824","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.plantconfig.numberOfPlants;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":520,"wires":[["d84d77e5.11843"]]},{"id":"8b2a6f8f.0fd64","type":"function","z":"9ab5060d.1bf72","name":"get from config","func":"msg.payload = msg.payload.measurement.measurementFrequency;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":560,"wires":[["a572ea56.95047"]]},{"id":"10b74a31.6aeece","type":"comment","z":"9ab5060d.1bf72","name":"handles the read and write to the config File, config file is structured as JSON","info":"","x":930,"y":260,"wires":[]},{"id":"935f40cb.03e51","type":"ui_text","z":"9ab5060d.1bf72","group":"6b4bed71.0020b4","order":3,"width":0,"height":0,"name":"","label":"Pump Status","format":"{{msg.pump}}","layout":"row-spread","x":1110,"y":160,"wires":[]},{"id":"83d490fb.bf3ce8","type":"function","z":"9ab5060d.1bf72","name":"","func":"msg.delay = msg.payload;\nmsg.pump = \"Off\";\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":160,"wires":[["935f40cb.03e51"]]},{"id":"50722e67.bf839","type":"delay","z":"9ab5060d.1bf72","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":960,"y":160,"wires":[["935f40cb.03e51"]]},{"id":"c539eb9e.c5cfd8","type":"mqtt-broker","z":"","name":"","broker":"192.168.178.58","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"Connection","birthQos":"0","birthPayload":"ESP Verbunden","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1abbd1ac.b30806","type":"ui_group","z":"","name":"Settings","tab":"a528e1a0.df4838","order":1,"disp":true,"width":"6","collapse":false},{"id":"6b4bed71.0020b4","type":"ui_group","z":"","name":"Callibrate","tab":"4d89f00b.44ec1","order":1,"disp":true,"width":"6","collapse":true},{"id":"a528e1a0.df4838","type":"ui_tab","z":"","name":"Settings","icon":"dashboard","order":3,"disabled":false,"hidden":false},{"id":"4d89f00b.44ec1","type":"ui_tab","z":"","name":"Sensor Data","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Credits

MO
1 project • 2 followers
Jan R. Seyler
13 projects • 15 followers
Avdyl
1 project • 2 followers
Valentin Hirzel
1 project • 1 follower

Comments