Pratik_Roy98
Published © LGPL

WaterTank Supervisory control and Data visualization

WaterTank Supervisory control and Data visulaization using NODE-RED and MQTT protocol with data storage in MySQL.

IntermediateFull instructions provided15 hours5,236
WaterTank Supervisory control and Data visualization

Things used in this project

Hardware components

Flow Sensor, Analog Output
Flow Sensor, Analog Output
×1
Soil Moisture & Temperature Sensor
Seeed Studio Soil Moisture & Temperature Sensor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Solenoid Valve, 2 Way
Solenoid Valve, 2 Way
×1
water pump
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
4-CHANNEL RELAY CONTROLLER FOR I2C
ControlEverything.com 4-CHANNEL RELAY CONTROLLER FOR I2C
×1

Software apps and online services

Node-RED
Node-RED
Arduino IDE
Arduino IDE
MQTT
MQTT

Story

Read more

Code

Tank Control

C/C++
Node MCU controls for the switches using SUB client MQTT
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssid";
const char* password = "pwd";

const char* mqtt_server = "192.168.x.xxx";

WiFiClient espClient;
PubSubClient client(espClient);

const int valve1=14;//D5
const int pump=12;//D6
const int valve2=13;//D7

long now = millis();
long lastMeasure = 0;

void setup() {  

  pinMode(valve1,OUTPUT);
  pinMode(valve2,OUTPUT);
  pinMode(pump,OUTPUT);
  
  Serial.begin(115200);
  
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  
}
void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}



void callback(String topic, byte* message, unsigned int length) {
  Serial.print("Message arrived on topic: ");
  Serial.print(topic);
  Serial.print(". Message: ");
  String messageTemp;
  
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
  }
  Serial.println();

  // Feel free to add more if statements to control more GPIOs with MQTT

  // If a message is received on the topic valves/pump, you check if the message is either on or off. Turns the valves/pump GPIO according to the message
  if(topic=="valve1"){
      Serial.print("Switching valve1 to ");
      if(messageTemp == "1"){
        digitalWrite(valve1, HIGH);
        Serial.print("On");
      }
      else if(messageTemp == "0"){
        digitalWrite(valve1, LOW);
        Serial.print("Off");
      }
  }
  if(topic=="valve2"){
      Serial.print("Switching valve2 to  ");
      if(messageTemp == "1"){
        digitalWrite(valve2, HIGH);
        Serial.print("On");
      }
      else if(messageTemp == "0"){
        digitalWrite(valve2, LOW);
        Serial.print("Off");
      }
  }
  if(topic=="pump"){
      Serial.print("Switching pump to  ");
      if(messageTemp == "1"){
        digitalWrite(pump, HIGH);
        Serial.print("On");
      }
      else if(messageTemp == "0"){
        digitalWrite(pump, LOW);
        Serial.print("Off");
      }
  }
  
  Serial.println();
}

// This functions reconnects your ESP8266 to your MQTT broker
// Change the function below if you want to subscribe to more topics with your ESP8266 
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");  
      // Subscribe or resubscribe to a topic
      // You can subscribe to more topics
      //Serial.println("msg valve1");
      client.subscribe("valve1");
      //Serial.println("msg pump");
      client.subscribe("pump");
      //Serial.println("msg valve2");
      client.subscribe("valve2");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(3000);
    }
  }
}


void loop() {
  if (!client.connected()) {
    reconnect();
  }
  if(!client.loop())
    client.connect("ESP8266Client");

  }

Tank Data Visualization

C/C++
Node MCU data publish to dashboard using MQTT pub client.
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssid";
const char* password = "pwd";

const char* mqtt_server = "192.168.x.xxx";

WiFiClient espClient;
PubSubClient client(espClient);

const int trig_pin_u1 = 16;//D0
const int echo_pin_u1 = 5;//D1


const int trig_pin_u2 = 4;//D2
const int echo_pin_u2 = 0;//D3

long duration_u1, duration_u2;
int distance_u1, distance_u2;


void setup() {
  pinMode(trig_pin_u1, OUTPUT);
  pinMode(echo_pin_u1, INPUT);

  pinMode(trig_pin_u2, OUTPUT);
  pinMode(echo_pin_u2, INPUT);


  Serial.begin(115200);

  setup_wifi();
  client.setServer(mqtt_server, 1883);

}
void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}

void level()
{

  digitalWrite(trig_pin_u1, LOW);
  delayMicroseconds(2);
  digitalWrite(trig_pin_u1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig_pin_u1, LOW);
 

  duration_u1 = pulseIn(echo_pin_u1, HIGH);
  distance_u1 = (duration_u1 / 2) / 29.41;
  distance_u1=9-distance_u1;
  
  delay(500);

  digitalWrite(trig_pin_u2, LOW);
  delayMicroseconds(2);
  digitalWrite(trig_pin_u2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig_pin_u2, LOW);

  duration_u2 = pulseIn(echo_pin_u2, HIGH);
  distance_u2 = (duration_u2 / 2) / 29.41;
  distance_u2=9-distance_u2;
  Serial.println(distance_u2);
}

void loop() {
  if (!client.loop())
    client.connect("ESP8266Client");
    
    level();

    static char d_u1[7];
    static char d_u2[7];
    dtostrf(distance_u1, 3, 0, d_u1);
    dtostrf(distance_u2, 3, 0, d_u2);
    Serial.println(d_u1);
    Serial.println(d_u2);
    client.publish("u1", d_u1);
    client.publish("u2", d_u2);
    delay(1000);
}

Soil data

C/C++
Node MCU soil mositure data publlish
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssid";
const char* password = "pwd";

const char* mqtt_server = "192.168.x.xxx";

WiFiClient espClient;
PubSubClient client(espClient);

const long soil=A0;//A0

void setup()
{
  pinMode(soil,INPUT);
  
  Serial.begin(115200);

  setup_wifi();
  client.setServer(mqtt_server, 1883);
}

void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}

// This functions reconnects your ESP8266 to your MQTT broker
// Change the function below if you want to subscribe to more topics with your ESP8266 
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    /*
     YOU MIGHT NEED TO CHANGE THIS LINE, IF YOU'RE HAVING PROBLEMS WITH MQTT MULTIPLE CONNECTIONS
     To change the ESP device ID, you will have to give a new name to the ESP8266.
     Here's how it looks:
       if (client.connect("ESP8266Client")) {
     You can do it like this:
       if (client.connect("ESP1_Office")) {
     Then, for the other ESP:
       if (client.connect("ESP2_Garage")) {
      That should solve your MQTT multiple connections problem
    */
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");  
      // Subscribe or resubscribe to a topic
      // You can subscribe to more topics
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  if(!client.loop())
    client.connect("ESP8266Client");
    
    
    double soil_value=analogRead(soil);
    static char soil_v[7];
 
    dtostrf(soil_value, 6, 2, soil_v);

    client.publish("soil", soil_v);
    Serial.println(soil_value);

    delay(10000);
}

Flow sensor data

C/C++
Arduino Interrupt pin is used for Flow sensor data acquisition
#include <SoftwareSerial.h>
SoftwareSerial s(5,6);

unsigned long currentTime;
unsigned long cloopTime;

volatile int flow_frequency1; 
unsigned int l_hour1; 
const  int flowsensor1 = 2;


volatile int flow_frequency2; 
unsigned int l_hour2; 
const  int flowsensor2 = 2;


void flow1() 
{
   flow_frequency1++;
}


void flow2() 
{
   flow_frequency2++;
}

void setup()
{
   pinMode(flowsensor1, INPUT);
   digitalWrite(flowsensor1, HIGH); 

    pinMode(flowsensor2, INPUT);
   digitalWrite(flowsensor2, HIGH); 
   
   Serial.begin(9600);
   s.begin(9600);
   
   attachInterrupt(0, flow1, RISING); 

   attachInterrupt(1, flow2, RISING); 
   
   sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
}
void loop ()
{
   currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour1 = (flow_frequency1 * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency1 = 0; // Reset Counter
      Serial.print(l_hour1, DEC); // Print litres/hour
      Serial.println(" 1 L/hour ");
     // s.write(" 1 L/hour ");
       s.write(l_hour1);

       cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour1 = (flow_frequency2 * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency2 = 0; // Reset Counter
      Serial.print(l_hour2, DEC); // Print litres/hour
      Serial.println(" 2 L/hour ");
      //s.write(" 2 L/hour ");
       s.write(l_hour2);
   }
}

Flow sensor data

C/C++
Node MCU serially reading the data from Arduino UNO and publishing in the Dashboard using MQTT PUB.
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5);
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssid";
const char* password = "pwd";

const char* mqtt_server = "192.168.x.xxx";

WiFiClient espClient;
PubSubClient client(espClient);

int flowdata1;
int flowdata2;

void setup() {
  
s.begin(9600);
Serial.begin(9600);

  setup_wifi();
  client.setServer(mqtt_server, 1883);
  
}

void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}

 
void loop() {
  //s.write("s");
  if (s.available()>0)
  {
    flowdata1=s.read();
    flowdata2=s.read();
    Serial.println(flowdata1);
    Serial.println(flowdata2);
  }

  if (!client.loop())
    client.connect("ESP8266Client");
    

    static char d_f1[7];
    static char d_f2[7];
    dtostrf(flowdata1, 3, 0, d_f1);
    dtostrf(flowdata2, 3, 0, d_f2);
    Serial.println(d_f1);
    Serial.println(d_f2);
    client.publish("f1", d_f1);
    client.publish("f2", d_f2);
    delay(500);
 
 
}

Node Red flow code

JSON
[
    {
        "id": "c855e9c5.011388",
        "type": "tab",
        "label": "Water scada",
        "disabled": false,
        "info": ""
    },
    {
        "id": "478bd80d.d86d98",
        "type": "ui_switch",
        "z": "c855e9c5.011388",
        "name": "valve1",
        "label": "Valve 1",
        "tooltip": "",
        "group": "3220d566.3df42a",
        "order": 26,
        "width": 3,
        "height": 2,
        "passthru": true,
        "decouple": "false",
        "topic": "",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "x": 630,
        "y": 520,
        "wires": [
            [
                "66a7b37f.1dbe3c",
                "e8c3b069.5d3e8"
            ]
        ]
    },
    {
        "id": "dfb491d5.b4d48",
        "type": "ui_switch",
        "z": "c855e9c5.011388",
        "name": "",
        "label": "Pump",
        "tooltip": "",
        "group": "3220d566.3df42a",
        "order": 28,
        "width": 3,
        "height": 2,
        "passthru": true,
        "decouple": "false",
        "topic": "",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "x": 630,
        "y": 600,
        "wires": [
            [
                "6f556440.9993ac",
                "89af0749.ee26f8"
            ]
        ]
    },
    {
        "id": "7e4780f6.043cf",
        "type": "ui_switch",
        "z": "c855e9c5.011388",
        "name": "",
        "label": "Valve 2",
        "tooltip": "",
        "group": "3220d566.3df42a",
        "order": 30,
        "width": 3,
        "height": 2,
        "passthru": true,
        "decouple": "false",
        "topic": "",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "x": 640,
        "y": 700,
        "wires": [
            [
                "53308e00.f4e86",
                "530efc4c.279294"
            ]
        ]
    },
    {
        "id": "dabdca45.254408",
        "type": "ui_gauge",
        "z": "c855e9c5.011388",
        "name": "f1",
        "group": "3220d566.3df42a",
        "order": 11,
        "width": 4,
        "height": 4,
        "gtype": "gage",
        "title": "",
        "label": "L/min",
        "format": "{{value}}",
        "min": 0,
        "max": "1000",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 930,
        "y": 200,
        "wires": []
    },
    {
        "id": "8ff1e461.64ee78",
        "type": "ui_chart",
        "z": "c855e9c5.011388",
        "name": "f1",
        "group": "3220d566.3df42a",
        "order": 38,
        "width": 4,
        "height": 4,
        "label": "Supply Tank Inlet Flow",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 930,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "4234eb21.e8d9a4",
        "type": "mqtt in",
        "z": "c855e9c5.011388",
        "name": "F1",
        "topic": "f1",
        "qos": "2",
        "datatype": "auto",
        "broker": "7cb01c98.abb984",
        "x": 800,
        "y": 240,
        "wires": [
            [
                "dabdca45.254408",
                "8ff1e461.64ee78",
                "5aa82413.e6a61c"
            ]
        ]
    },
    {
        "id": "27afcc60.e307c4",
        "type": "ui_gauge",
        "z": "c855e9c5.011388",
        "name": "u2",
        "group": "3220d566.3df42a",
        "order": 13,
        "width": 4,
        "height": 4,
        "gtype": "wave",
        "title": "",
        "label": "cm",
        "format": "{{value}}",
        "min": 0,
        "max": "10",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 1270,
        "y": 140,
        "wires": []
    },
    {
        "id": "f369e81e.4a7d28",
        "type": "ui_chart",
        "z": "c855e9c5.011388",
        "name": "u2",
        "group": "3220d566.3df42a",
        "order": 40,
        "width": 4,
        "height": 4,
        "label": "Supply Tank Level",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 1270,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "391458e0.2db318",
        "type": "mqtt in",
        "z": "c855e9c5.011388",
        "name": "U2",
        "topic": "u2",
        "qos": "2",
        "datatype": "auto",
        "broker": "2be9a8c0.b410d8",
        "x": 1140,
        "y": 200,
        "wires": [
            [
                "27afcc60.e307c4",
                "f369e81e.4a7d28",
                "876a0ee9.4524e"
            ]
        ]
    },
    {
        "id": "f1da0f51.9d594",
        "type": "ui_gauge",
        "z": "c855e9c5.011388",
        "name": "f2",
        "group": "3220d566.3df42a",
        "order": 15,
        "width": 4,
        "height": 4,
        "gtype": "gage",
        "title": "",
        "label": "L/min",
        "format": "{{value}}",
        "min": 0,
        "max": "1000",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 1800,
        "y": 260,
        "wires": []
    },
    {
        "id": "edf62057.5ad1b",
        "type": "ui_chart",
        "z": "c855e9c5.011388",
        "name": "f2",
        "group": "3220d566.3df42a",
        "order": 42,
        "width": 4,
        "height": 4,
        "label": "Outlet Flow",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 1800,
        "y": 360,
        "wires": [
            []
        ]
    },
    {
        "id": "d6780b91.d5c718",
        "type": "mqtt in",
        "z": "c855e9c5.011388",
        "name": "F2",
        "topic": "f2",
        "qos": "0",
        "datatype": "auto",
        "broker": "7cb01c98.abb984",
        "x": 1670,
        "y": 300,
        "wires": [
            [
                "f1da0f51.9d594",
                "edf62057.5ad1b",
                "96ec9075.82fdf"
            ]
        ]
    },
    {
        "id": "ec92c37b.00f0b",
        "type": "ui_chart",
        "z": "c855e9c5.011388",
        "name": "u1",
        "group": "3220d566.3df42a",
        "order": 36,
        "width": 4,
        "height": 4,
        "label": "Reserve Tank Level",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 290,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "17b8d16f.6cec6f",
        "type": "ui_gauge",
        "z": "c855e9c5.011388",
        "name": "u1",
        "group": "3220d566.3df42a",
        "order": 9,
        "width": 4,
        "height": 4,
        "gtype": "wave",
        "title": "",
        "label": "cm",
        "format": "{{value}}",
        "min": 0,
        "max": "10",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 290,
        "y": 80,
        "wires": []
    },
    {
        "id": "99f522db.3849f",
        "type": "mqtt in",
        "z": "c855e9c5.011388",
        "name": "U1",
        "topic": "u1",
        "qos": "2",
        "datatype": "auto",
        "broker": "2be9a8c0.b410d8",
        "x": 140,
        "y": 140,
        "wires": [
            [
                "17b8d16f.6cec6f",
                "ec92c37b.00f0b",
                "fa621d17.e7174"
            ]
        ]
    },
    {
        "id": "19290f7d.3ef741",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "3220d566.3df42a",
        "order": 2,
        "width": 4,
        "height": 1,
        "name": "u1",
        "label": "",
        "format": "Reserve Tank Level",
        "layout": "row-left",
        "x": 300,
        "y": 140,
        "wires": []
    },
    {
        "id": "3c6653ed.128c3c",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "3220d566.3df42a",
        "order": 4,
        "width": 4,
        "height": 1,
        "name": "f1",
        "label": "",
        "format": "Supply Tank Inlet Flow",
        "layout": "row-left",
        "x": 960,
        "y": 240,
        "wires": []
    },
    {
        "id": "4d9f620e.8a1f0c",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "3220d566.3df42a",
        "order": 6,
        "width": 4,
        "height": 1,
        "name": "u2",
        "label": "",
        "format": "Supply Tank Level",
        "layout": "row-left",
        "x": 1300,
        "y": 200,
        "wires": []
    },
    {
        "id": "1964483a.9f7538",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "3220d566.3df42a",
        "order": 8,
        "width": 4,
        "height": 1,
        "name": "f2",
        "label": "",
        "format": "Outlet Flow",
        "layout": "row-left",
        "x": 1820,
        "y": 320,
        "wires": []
    },
    {
        "id": "365f0927.ca4716",
        "type": "ui_gauge",
        "z": "c855e9c5.011388",
        "name": "soil",
        "group": "b935fee8.94039",
        "order": 6,
        "width": 4,
        "height": 4,
        "gtype": "donut",
        "title": "",
        "label": "MU",
        "format": "{{value}}",
        "min": 0,
        "max": "1000",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 1190,
        "y": 800,
        "wires": []
    },
    {
        "id": "f726206d.21911",
        "type": "ui_chart",
        "z": "c855e9c5.011388",
        "name": "soil",
        "group": "b935fee8.94039",
        "order": 14,
        "width": 30,
        "height": 5,
        "label": "Soil moisture",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "86400",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 1190,
        "y": 880,
        "wires": [
            []
        ]
    },
    {
        "id": "4d9aef11.e81fc",
        "type": "mqtt in",
        "z": "c855e9c5.011388",
        "name": "soil",
        "topic": "soil",
        "qos": "0",
        "datatype": "auto",
        "broker": "2be9a8c0.b410d8",
        "x": 1010,
        "y": 840,
        "wires": [
            [
                "365f0927.ca4716",
                "f726206d.21911",
                "1ac88e8a.700581"
            ]
        ]
    },
    {
        "id": "8910f631.89f088",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "b935fee8.94039",
        "order": 3,
        "width": 4,
        "height": 1,
        "name": "soil",
        "label": "",
        "format": "Soil Moisture",
        "layout": "row-left",
        "x": 1220,
        "y": 840,
        "wires": []
    },
    {
        "id": "d5622bb9.f0c828",
        "type": "moment",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "",
        "input": "payload",
        "inputType": "msg",
        "inTz": "Asia/Calcutta",
        "adjAmount": "",
        "format": "DD/MM/YYYY HH:mm:ss",
        "locale": "en_IN",
        "output": "payload",
        "outputType": "msg",
        "outTz": "Asia/Calcutta",
        "x": 380,
        "y": 860,
        "wires": [
            [
                "d1e1e651.de1458",
                "b1947baf.8e27f8"
            ]
        ]
    },
    {
        "id": "c03d22c3.5548a",
        "type": "inject",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 170,
        "y": 860,
        "wires": [
            [
                "d5622bb9.f0c828"
            ]
        ]
    },
    {
        "id": "9cb38005.a4c36",
        "type": "moment",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "",
        "input": "payload",
        "inputType": "msg",
        "inTz": "Asia/Calcutta",
        "adjAmount": "",
        "format": "DD/MM/YYYY HH:mm:ss",
        "locale": "en_IN",
        "output": "payload",
        "outputType": "msg",
        "outTz": "Asia/Calcutta",
        "x": 360,
        "y": 820,
        "wires": [
            [
                "72b2ba1f.09a4a4",
                "f85ed5b2.5063b8"
            ]
        ]
    },
    {
        "id": "3bff87fc.ef1478",
        "type": "inject",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 170,
        "y": 820,
        "wires": [
            [
                "9cb38005.a4c36"
            ]
        ]
    },
    {
        "id": "72b2ba1f.09a4a4",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "3220d566.3df42a",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "SCADA d/m",
        "label": "Date/Time",
        "format": "{{msg.payload}}",
        "layout": "row-right",
        "x": 620,
        "y": 800,
        "wires": []
    },
    {
        "id": "d1e1e651.de1458",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "b935fee8.94039",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "soil d/m",
        "label": "Date/Time",
        "format": "{{msg.payload}}",
        "layout": "row-left",
        "x": 610,
        "y": 840,
        "wires": []
    },
    {
        "id": "6e3f2fee.53562",
        "type": "mysql",
        "z": "c855e9c5.011388",
        "mydb": "2e1d0fc3.f11a9",
        "name": "",
        "x": 570,
        "y": 980,
        "wires": [
            []
        ]
    },
    {
        "id": "cc7909ca.6941f8",
        "type": "ui_switch",
        "z": "c855e9c5.011388",
        "name": "override",
        "label": "Override",
        "tooltip": "",
        "group": "82ffe014.05f45",
        "order": 3,
        "width": 7,
        "height": 4,
        "passthru": false,
        "decouple": "false",
        "topic": "override",
        "style": "",
        "onvalue": "1",
        "onvalueType": "num",
        "onicon": "",
        "oncolor": "",
        "offvalue": "0",
        "offvalueType": "num",
        "officon": "",
        "offcolor": "",
        "x": 100,
        "y": 420,
        "wires": [
            [
                "d321a497.1a8d88",
                "bab5ef72.33a34"
            ]
        ]
    },
    {
        "id": "249010e9.b2078",
        "type": "ui_text",
        "z": "c855e9c5.011388",
        "group": "82ffe014.05f45",
        "order": 6,
        "width": 7,
        "height": 4,
        "name": "Status",
        "label": "Status",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "x": 390,
        "y": 420,
        "wires": []
    },
    {
        "id": "96ec9075.82fdf",
        "type": "change",
        "z": "c855e9c5.011388",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$number(payload)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1780,
        "y": 420,
        "wires": [
            [
                "aa82cc44.de1bc"
            ]
        ]
    },
    {
        "id": "aa82cc44.de1bc",
        "type": "function",
        "z": "c855e9c5.011388",
        "name": "",
        "func": "global.set(\"flow2\",msg.payload);",
        "outputs": 1,
        "noerr": 0,
        "x": 1870,
        "y": 480,
        "wires": [
            []
        ]
    },
    {
        "id": "66a7b37f.1dbe3c",
        "type": "mqtt out",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "valve1",
        "qos": "2",
        "retain": "true",
        "broker": "5e8739b4.e25bd8",
        "x": 800,
        "y": 520,
        "wires": []
    },
    {
        "id": "6f556440.9993ac",
        "type": "mqtt out",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "pump",
        "qos": "2",
        "retain": "true",
        "broker": "5e8739b4.e25bd8",
        "x": 810,
        "y": 600,
        "wires": []
    },
    {
        "id": "53308e00.f4e86",
        "type": "mqtt out",
        "z": "c855e9c5.011388",
        "name": "",
        "topic": "valve2",
        "qos": "2",
        "retain": "true",
        "broker": "5e8739b4.e25bd8",
        "x": 810,
        "y": 700,
        "wires": []
    },
    {
        "id": "d321a497.1a8d88",
        "type": "function",
        "z": "c855e9c5.011388",
        "name": "",
        "func": "if (msg.payload==1) {\n    msg.payload=\"Override\";\n} if(msg.payload===0) {\n    msg.payload=\"Automatic\";\n}\n\n   return(msg);",
        "outputs": 1,
        "noerr": 0,
        "x": 250,
        "y": 420,
        "wires": [
            [
                "249010e9.b2078"
            ]
        ]
    },
    {
        "id": "b7b6d358.f3295",
        "type": "function",
        "z": "c855e9c5.011388",
        "name": "pump auto",
        "func": "var f1=global.get(\"level2\");\nvar ov=global.get(\"override\");\nif(ov==1)\n{\n}\nelse\n{\n    if(f1<3)\n    {\n        msg.payload=1;\n    }\n    else\n    {\n        msg.payload=0;\n    }\n\n    return(msg);\n}\n",
        "outputs": 1,
        "noerr": 0,
        "x": 350,
        "y": 560,
        "wires": [
            [
                "478bd80d.d86d98",
                "dfb491d5.b4d48"
            ]
        ]
    },
    {
        "id": "876a0ee9.4524e",
        "type": "change",
        "z": "c855e9c5.011388",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$number(payload)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1260,
        "y": 300,
        "wires": [
            [
                "cda63c53.03412"
            ]
        ]
    },
    {
        "id": "cda63c53.03412",
        "type": "function",
        "z": "c855e9c5.011388",
        "name": "",
        "func": "global.set(\"level2\",msg.payload);",
        "outputs": 1,
        "noerr": 0,
        "x": 1350,
        "y": 360,
        "wires": [
            []
        ]
    },
    {
        "id": "5aa82413.e6a61c",
        "type": "change",
        "z": "c855e9c5.011388",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$number(payload)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 860,
        "y": 320,
        "wires": [
            [
                "e1439452.e3d798"
            ]
        ]
    },
    {
        "id": "e1439452.e3d798",
        "type": "function",
        "z": "c855e9c5.011388",
        "name": "",
        "func": "global.set(\"flow1\",msg.payload);",
        "outputs": 1,
        "noerr": 0,
        "x": 950,
        "y": 380,
        "wires": [
            []
        ]
    },
    {
        "id": "fa621d17.e7174",
        "type": "change",
        "z": "c855e9c5.011388",
        "name": "",
        "rules": [
...

This file has been truncated, please download it to see its full contents.

Credits

Pratik_Roy98

Pratik_Roy98

6 projects • 25 followers
Embedded Software Developer at Texas Instruments.

Comments