Project in progress
Smart Farm Application with Watering and Fertilizer System

Smart Farm Application with Watering and Fertilizer System

Real-time visibility and control of water, process farming, weather & wells - from anywhere.

  • 1,246 views
  • 3 comments
  • 16 respects

Components and supplies

Apps and online services

About this project

Control Modules for Watering and Fertilization.

COM between NodemCU, Arduino and Web Server

Sensor Messages

Message received from client

Info/Sensor/state?hum=80.30&temp=23.40&soil_humidity=25&water_level=19.74&total_mili_litres=0.26&ferti_level=18.73&total_ferti=1.27&watering_status=0&ferti_status=0

{"MessageTime":"20190611T17:55:32.1632024+00:00",

"Temperature":23.4, "Humidity":80.3, "WaterLevel":19.74, "SoilHumidity":25, "TotalMiliLitres":0.26, "FertiLevel":18.73, "TotalFerti":1.27, "FertiStatus":0, "RelayStatus":0,

"MessageType":1, "ControllerType":1, "Action":"state", "Args":[{"Key":"hum", "Value":"80.30"}, {"Key":"temp", "Value":"23.40"}, {"Key":"soil_humidity", "Value":"25"}, {"Key":"water_level", "Value":"19.74"}, {"Key":"total_mili_litres", "Value":"0.26"}, {"Key":"ferti_level", "Value":"18.73"}, {"Key":"total_ferti", "Value":"1.27"}, {"Key":"watering_status", "Value":"0"}, {"Key":"ferti_status", "Value":"0"}]}

Client Messages

Command/watering?state=true\n

Command/watering?state=false\n

Command/watering?state=true&amount=3\n

Command/fertilization?state=true\n

Command/fertilization?state=false\n

Command/fertilization?state=true&amount=4\n

Command/autoFarmer?state=true&min='+minHumidity+'&max='+maxHumidity+'\n

Instant Graphs

Instant Values

Code

Arduino PartC/C++
//TOMTOM robotics ARDUINO
//Arduino code

#include <SoftwareSerial.h>
SoftwareSerial s(5, 6);

//Rle
#define RELAY1  8
#define RELAY2  7


//DHT
#include <dht.h>
dht DHT;
#define DHT21_PIN 3     // DHT 22  (AM2302) - what pin we're connected to
float hum;  //Stores humidity value
float temp; //Stores temperature value

//Nem
byte humidity_sensor_pin = A1;
byte humidity_sensor_vcc = 4;

// Ultrasonic Water
int trig = 12;
int echo = 11;

// Ultrasonic Ferti
int trigFerti = 13;
int echoFerti = 9;

// Interrupts
int cntr = 0;
int TaskTimer1;
bool TaskFlag1;
int TaskTimer2;
bool TaskFlag2;
int TaskTimer3;
bool TaskFlag3;

//int ledPin = 13;

int relay_status = 0;

// State machine
int stateMonitor = 1;

/* Water */
long h_level_cm = 0, h_level_percent = 0, h_harcanan =0;

float h = 0;
float t = 0;
float h_level_lt = 0;

static bool isWatering = false;
static float amountWater = 0;
static float remainAmountWater = 0;
static float previousRemainAmountWater = 0;

/* Ferti */
long h_level_cm_ferti = 0, h_level_percent_ferti = 0, h_harcanan_ferti =0;

float h_ferti = 0;
float t_ferti = 0;
float h_level_lt_ferti = 0;

static bool isFerti = false;
static float amountFerti = 0;
static float remainAmountFerti = 0;
static float previousRemainAmountFerti = 0;

static bool isAutoFarm = false;
static int minHumidity = 0;
static int maxHumidity = 0;
static int soil_humidity = 0;

static bool watering_status = 0;
static bool ferti_status = 0;

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void setup() {

  s.begin(9600);
  Serial.begin(9600);


  // Timer
  // ----- configure Timer 2 to generate a compare-match interrupt every 1mS
  noInterrupts();            // disable interrupts
  TCCR2A = 0;                // clear control registers
  TCCR2B = 0;
  TCCR2B |= (1 << CS22);     // 16MHz/64=16uS

  TCNT2 = 0;                 // clear counter
  OCR2A = 63 - 1;           // 16uS*125=1mS (allow for clock propagation)
  TIMSK2 |= (1 << OCIE2A);   // enable output compare interrupt
  interrupts();              // enable interrupts

  // Rle k
  pinMode(RELAY1, OUTPUT);
  digitalWrite(RELAY1, HIGH);
  pinMode(RELAY2, OUTPUT);
  digitalWrite(RELAY2, HIGH);

  // Init the humidity sensor board
  pinMode(humidity_sensor_vcc, OUTPUT);
  digitalWrite(humidity_sensor_vcc, LOW);

  //ultrasonic water //
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);

  //ultrasonic Ferti //
  pinMode(trigFerti, OUTPUT);
  pinMode(echoFerti, INPUT);


   digitalWrite(humidity_sensor_vcc, HIGH);
//  pinMode(ledPin, OUTPUT);


}

// -------------------------------
// task scheduler (1mS interrupt)
// -------------------------------
ISR(TIMER2_COMPA_vect)
{
  
  /*
     Each timer counts the number of milliseconds since its associated task was
     last performed. Each additional task requires another timer and flag.
  */
  TaskTimer1++;
  TaskTimer2++;
  TaskTimer3++;


  // ----- task1
  if (TaskTimer1 > 10000 - 1) { // toggle LED ()
    TaskTimer1 = 0;
    TaskFlag1 = true;
  }


  // ----- task2
  if (TaskTimer2 > 500 - 1) {  // scroll message (250mS)
    TaskTimer2 = 0;
    TaskFlag2 = true;
  }

  // ----- task3
  if (TaskTimer3 > 1000 - 1) {  // bargraph (100mS)
    TaskTimer3 = 0;
    TaskFlag3 = true;
    
    if(isWatering && amountWater > 0){
      if(remainAmountWater - previousRemainAmountWater>= amountWater){
          stopWatering();
        }
    }
    
    if(isFerti && amountFerti > 0){
      if(remainAmountFerti - previousRemainAmountFerti>= amountFerti){
          stopFertilization();
        }
    }
    
    if(isAutoFarm && minHumidity > 0 && maxHumidity > 0){
      if(isWatering == false){
        if(soil_humidity <= minHumidity){
          startWatering();
        }
      }
      
      else{
        if(soil_humidity > minHumidity){
          stopWatering();
        }
      }
    }
   }

  
}

int read_humidity_sensor() {
  int value = analogRead(humidity_sensor_pin);
  value = map(value,920,480,0,100);
  return value; 
  //digitalWrite(humidity_sensor_vcc, LOW);
  
}

void startWatering() {
  digitalWrite(RELAY1, LOW);
  isWatering = true;
  watering_status = 1;
  
}

void stopWatering() {
  digitalWrite(RELAY1, HIGH);
  isWatering = false;
  amountWater = 0;
  watering_status = 0;

 

}

void startAutoFarming() {
  Serial.println("Autofarm started");
  isAutoFarm = true;

 
}

void stopAutoFarming() {
  Serial.println("Autofarm stopped");
  isAutoFarm = false;

  
}

void startFertilization() {
  digitalWrite(RELAY2, LOW);
  isFerti = true;
  ferti_status = 1;

  
}

void stopFertilization() {
  digitalWrite(RELAY2, HIGH);
  isFerti = false;
  amountFerti = 0;
  ferti_status = 0;

  
}

void loop() {

 //soil_humidity = read_humidity_sensor();
 //Serial.println(soil_humidity);
 //delay(500);
   if (TaskFlag3 == true) {
    TaskFlag3=false;
  soil_humidity = read_humidity_sensor();
   
  // Transmitting pulse for Water
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  
  // Waiting for pulse water
  t = pulseIn(echo, HIGH);
  
  
  // Calculating distance 
  h = t / 58;
  h = h - 13;  // offset correction
  h = 24.80 - h;  // water height, 0 - 50 cm
  
  // h_level_lt tankn su seviyesi
  h_level_lt = h * 0.80424772;
  
  // imdiye kadar harcanan su seviyesi
  remainAmountWater = 20 - h_level_lt; 

 // Transmitting pulse for Ferti
  digitalWrite(trigFerti, LOW);
  delayMicroseconds(2);
  digitalWrite(trigFerti, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigFerti, LOW);
  
  // Waiting for pulse water
  t_ferti = pulseIn(echoFerti, HIGH);

  // Calculating distance 
  h_ferti = t_ferti / 58;
  delayMicroseconds(10);
  h_ferti = h_ferti - 13;  // offset correction
  delayMicroseconds(10);
  h_ferti = 24.80 - h_ferti;  // water height, 0 - 50 cm
 
  
  // h_level_lt tankn su seviyesi
  h_level_lt_ferti = h_ferti * 0.80424772;
  delayMicroseconds(10);
  
  // imdiye kadar harcanan su seviyesi
  remainAmountFerti = 20 - h_level_lt_ferti;
  
   }
  
  
  if (TaskFlag2 == true) {
    TaskFlag2 = false;
    if (s.available() > 0) {

      String message_from_server = s.readStringUntil('\n');
      Serial.println(message_from_server);
       
      String cmd = getValue(message_from_server, '?', 0);
      Serial.println(cmd);

      if(cmd == "Command/watering"){
          //here you could check the servo number
          String params = getValue(message_from_server, '?', 1);
          String params2 = getValue(params, '&', 1);

          if(params2 == NULL){
            String state = getValue(params, '=', 1);
            if (state == "true"){
              amountWater = 0;
              Serial.println("Watering on");
              startWatering();
            }
            else if (state == "false"){
              Serial.println("Watering off");
              stopWatering();
            }
          }
          else{
            String stateParam = getValue(params, '&', 0);
            String state = getValue(stateParam, '=', 1);
            
            if (state == "true"){
              String amountParam = getValue(params, '&', 1);
              String amount = getValue(amountParam, '=', 1);
              amountWater = amount.toFloat();
              previousRemainAmountWater = remainAmountWater;
              
              Serial.print("Watering on for ");
              Serial.print(amount);
              Serial.println(" litres.");
              startWatering();
            }
            else if (state == "false"){
              Serial.println("Watering off");
              stopWatering();
            }
          }
      }

      else if(cmd == "Command/fertilization"){
          //here you could check the servo number
          String params = getValue(message_from_server, '?', 1);
          String params2 = getValue(params, '&', 1);

          if(params2 == NULL){
            String state = getValue(params, '=', 1);
            if (state == "true"){
              amountFerti = 0;
              Serial.println("Fertilization on");
              startFertilization();
            }
            else if (state == "false"){
              Serial.println("Fertilization off");
              stopFertilization();
            }
          }
          else{
            String stateParam = getValue(params, '&', 0);
            String state = getValue(stateParam, '=', 1);
            
            if (state == "true"){
              String amountParam = getValue(params, '&', 1);
              String amount = getValue(amountParam, '=', 1);
              amountFerti = amount.toFloat();
              previousRemainAmountFerti = remainAmountFerti;
              
              Serial.print("Fertilization on for ");
              Serial.print(amount);
              Serial.println(" litres.");
              startFertilization();
            }
            else if (state == "false"){
              Serial.println("Fertilization off");
              stopFertilization();
            }
          }
      }
        
       else if (cmd == "Command/monitoring"){
        String params = getValue(message_from_server, '?', 1);
        String state = getValue(params, '=', 1);
        Serial.println(params);
        Serial.println(state);
        if (state == "true"){
          Serial.println("Monitoring on");
          stateMonitor = 1;
          
        }
        else if (state == "false"){
          Serial.println("Monitoring off");
          stateMonitor = 2;
        }
      }
      
      else if(cmd == "Command/autoFarmer"){
          //here you could check the servo number
          String params = getValue(message_from_server, '?', 1);
          String params2 = getValue(params, '&', 1);

          if(params2 == NULL){
            String state = getValue(params, '=', 1);
            if (state == "true"){
              Serial.println("AutoFarmer on");
              //startAutoFarming();
              
            }
            else if (state == "false"){
              Serial.println("Autofarmer off");
              stopAutoFarming();
            }
          }
          else{
            String stateParam = getValue(params, '&', 0);
            String state = getValue(stateParam, '=', 1);
            
            if (state == "true"){
              String minParam = getValue(params, '&', 1);
              String minStr = getValue(minParam, '=', 1);
              String maxParam = getValue(params, '&', 2);
              String maxStr = getValue(maxParam, '=', 1);
              
              minHumidity = minStr.toInt();
              maxHumidity = maxStr.toInt();
              
              Serial.print("minHumidty = ");
              Serial.print(minHumidity);
              Serial.print(" maxHumidty = ");
              Serial.println(maxHumidity);
              startAutoFarming();
            }
            else if (state == "false"){
              Serial.println("Autofarm off");
              stopAutoFarming();
            }
          }
      }

      
  }
}
  
  switch (stateMonitor) {
    case 1:
    if (TaskFlag1 == true) {
      TaskFlag1 = false;
      DHT.read21(DHT21_PIN);
      hum = DHT.humidity;
      delay(50);
      temp = DHT.temperature;
      
      s.print("Info/Sensor/state?hum=");
      s.print(hum);
      s.print("&temp=");
      s.print(temp);
      s.print("&soil_humidity=");
      s.print(soil_humidity);
      s.print("&water_level=");
      s.print(h_level_lt);
      s.print("&total_mili_litres=");
      s.print(remainAmountWater);
      s.print("&ferti_level=");
      s.print(h_level_lt_ferti);
      s.print("&total_ferti=");
      s.print(remainAmountFerti);
      s.print("&watering_status=");
      s.print(watering_status);
      s.print("&ferti_status=");
      s.print(ferti_status);
    
      }
    
    
    break;

    case 2:
      TaskFlag1 = false;
      delay(100);
      Serial.print("Monitoring off\n");
    break;
}
}
Nodemcu PartC/C++
//TOMTOM robotics Nodemcu

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

const char* ssid = "10koliks";
const char* password =  "okanokan";
 
const uint16_t port = 1234;
const char * host = "104.41.131.109";
//const char * host = "172.20.10.4";



// Serial Communication //
SoftwareSerial s(D6,D5);
String data;

WiFiClient client;

void setup()
{

  // Serial Communication //
  s.begin(9600);
  Serial.begin(9600);


  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("...");
  }
  
  Serial.print("WiFi connected with IP: ");
  Serial.println(WiFi.localIP());
  
   if (!client.connect(host, port)) {
   
          Serial.println("Connection to host failed");
   
          delay(1000);
          
          return;
      }
      client.setTimeout(200);
      Serial.println("Connected to server successful!");
      delay(1000);
      
  }
 
void loop()
{
    // Serial Communication //
    
    if (client.available() > 0){
      String message = client.readString();
      Serial.println(message);
      s.print(message);
      delay(200);
    }
    
    if (s.available() > 0)
    {
      data = s.readString();
      Serial.println(data);

      if(client.availableForWrite() > 0){
        client.print(data);
        delay(200);
      }
      
     }
    
}
Web PageHTML
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Home Page - IOT</title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <link href="Content/Site.css" rel="stylesheet" />

    <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/18.2.8/css/dx.common.css" />

    <link rel="stylesheet dx-theme"  type="text/css" data-theme="material.teal.light" href="https://cdn3.devexpress.com/jslib/18.2.8/css/dx.light.css" />

    <link rel="stylesheet" type="text/css" href="style.css" />

    <script src="Scripts/modernizr-2.8.3.js"></script>




</head>
<body>

    <div class="container body-content">


        <div class="row">
            <div class="form col-sm-4">

                

                <div class="dx-fieldset">
                    <div class="dx-field">
                        <div class="dx-field-label">MONITORING MODE</div>
                        <div class="dx-field-value">
                            <div id="handler-monitoring"></div>
                        </div>
                    </div>
                </div>

                <div class="dx-fieldset">
                    <div class="dx-field">
                        <div class="dx-field-label">AUTO MODE</div>
                        <div class="dx-field-value">
                            <div id="handler-auto"></div>
                        </div>
                    </div>
                    <div class=""></div>
                    <div class="dx-field">
                        <div id="handler-range-slider"></div>
                    </div>
                    <div class="dx-field">
                        <div class="dx-field-label">Minimum nem</div>
                        <div class="dx-field-value">
                            <div id="start-value"></div>
                        </div>
                    </div>
                    <div class="dx-field">
                        <div class="dx-field-label">Maksimum nem</div>
                        <div class="dx-field-value">
                            <div id="end-value"></div>
                        </div>
                    </div>
                    <div class="dx-field">
                        <!--<button type="submit" id="autofarm-button" class="btn btn-success">Sula</button>-->
                        <div id="autofarm-button"></div>
                    </div>
                </div>

                <div class="dx-fieldset">
                    <div class="dx-field">
                        <div class="dx-field-label">MANUEL MODE</div>
                        <div class="dx-field-value">
                            <div id="disabled"></div>
                        </div>
                    </div>
                    <div class="dx-field">
                        <div class="dx-field-label">WATER PUMP</div>
                        <div class="dx-field-value">
                            <div id="start-water"></div>
                        </div>
                    </div>
                    <div class="dx-field">
                        <div class="dx-field-label">FERTILIZATION PUMP</div>
                        <div class="dx-field-value">
                            <div id="start-fertil"></div>
                        </div>
                    </div>
                </div>
                <div class="dx-fieldset">
                    <div class=" panel-heading">WATERING MODULE</div>
                    <div class="dx-field">
                        <div id="water-slider"></div>
                    </div>
                    <div class="dx-field">
                        <div class="dx-field-label">Watering amount:</div>
                        <div class="dx-field-value">
                            <div id="water-slider-value"></div>
                        </div>
                    </div>
                    <div class="form">
                        <div id="progress-button"></div>
                        <div id="progress"><div id="progressBarStatus"></div></div>
                    </div>
                </div>

                <div class="dx-fieldset">
                    <div class=" panel-heading">FERTIZILATION MODULE</div>
                    <div class="dx-field">
                        <div id="fertilization-slider"></div>
                    </div>
                    <div class="dx-field">
                        <div class="dx-field-label">Fertizilator amount</div>
                        <div class="dx-field-value">
                            <div id="fertilization-slider-value"></div>
                        </div>
                    </div>
                    <div class="form">
                        <div id="fertilizationButton"></div>
                        <div id="progress"><div id="fertilizationStatus"></div></div>
                    </div>
                </div>

            </div>

            <div class="col-sm-8 nopadding">
                <div class="col-sm-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            INSTANT GRAPHS
                        </div>
                        <div class="panel-body">
                            <!--<div id="humidity">0</div>-->
                            <div id="chart-allData"></div>
                        </div>
                    </div>
                </div>
                
                <div class="col-sm-2 col-half-offset">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Air<br>Temperature(C)
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="temperature">0</div>
                            <div class="gauge-element" id="temperatureGauge"></div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-2 col-half-offset">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Air<br>Humidity(%)
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="humidity">0</div>
                            <div class="gauge-element" id="humidityGauge"></div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-2 col-half-offset">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Soil<br>Humidty(%)
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="soilHumidity">0</div>
                            <div class="gauge-element" id="soilHumidityGauge"></div>
                        </div>
                    </div>
                </div>

                <div class="col-sm-2 col-half-offset">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Water<br>Tank Level(lt)
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="waterLevel">0</div>
                            <div class="gauge-element" id="waterLevelGauge"></div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-2 col-half-offset">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Fertilization Tank Level
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="fertiLevel">0</div>
                            <div class="gauge-element" id="fertiLevelGauge"></div>
                        </div>
                    </div>
                </div>
                 <div class="col-sm-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Water Counter
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="totalWater">0</div>
                            <div id="totalWaterGauge"></div>
                        </div>
                    </div>
                </div>
                 <div class="col-sm-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Fertilizator Counter
                        </div>
                        <div class="panel-body">
                            <div class="instant" id="totalFerti">0</div>
                            <div id="totalFertiGauge"></div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

        <br />


        <!--<div class="row">
            <div class="col-sm-12">
                <button id="ledOn" type="button" class="btn btn-success" disabled>
                    Sulamay Balat
                </button>
                <button id="ledOff" type="button" class="btn btn-danger" disabled>
                    Sulamay Durdur
                </button>
                <form id="form-water" class="form-inline">
                    <input type="text" id="litre" class="form-control" placeholder="lt">
                    <button type="submit" class="btn btn-success">Sula</button>
                </form>
            </div>
        </div>-->

        <br />

        <div class="row">
            
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Air Temperature(C)
                    </div>
                    <div class="panel-body">
                        <!--<div id="temperature">0</div>-->
                        <div id="chart-temperature"></div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Air Humidity(%)
                    </div>
                    <div class="panel-body">
                        <!--<div id="humidity">0</div>-->
                        <div id="chart-humidity"></div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Soil Humidity(%)
                    </div>
                    <div class="panel-body">
                        <!--<div id="soilHumidity">0</div>-->
                        <div id="chart-soilHumidity"></div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Su Tank Seviyesi(lt)
                    </div>
                    <div class="panel-body">
                        <!--<div id="waterLevel">0</div>-->
                        <div id="chart-waterLevel"></div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Total Spent Water Amount(lt)
                    </div>
                    <div class="panel-body">
                        <div id="totalMiliLitres">0</div>
                        <div id="chart-totalMiliLitres"></div>
                    </div>
                </div>
            </div>
        </div>


    </div>

    <script src="Scripts/jquery-3.3.1.min.js"></script>
    <script src="Scripts/bootstrap.js"></script>

    <script src="Scripts/jquery.signalR-2.4.0.min.js"></script>

    <script type="text/javascript" src="https://cdn3.devexpress.com/jslib/18.2.8/js/dx.all.js"></script>

    <script src="http://localhost:1235/signalr/hubs"></script>

    <script type="text/javascript">
    	var waterStepper = 0;
        var previousWateredAmount = 0;
        var wateredAmount = 0;
        var previousFertiAmount = 0;
        var fertiAmount = 0;

        $(function () {
            $('#chart-allData').dxChart({
                dataSource: [],
                commonAxisSettings: {
                    grid: {
                        visible: false
                    }
                },
                palette: "Soft Blue",
                argumentAxis: {
                    argumentType: 'datetime'
                },
                valueAxis: {
                    valueType: 'numeric'
                },
                 legend: {
                    verticalAlignment: "bottom",
                    horizontalAlignment: "center"
                },
                /*series: {
                    argumentField: 'MessageTime',
                    valueField: 'TotalMiliLitres',
                    type: 'line'
                },*/
                 series: [
                    { valueField: "Temperature", name: "Temperature",  argumentField: 'MessageTime',  type: 'line' },
                    { valueField: "SoilHumidity", name: "Soil Humidity",  argumentField: 'MessageTime',  type: 'line' },
                    { valueField: "Humidity", name: "Air Humidty",  argumentField: 'MessageTime',  type: 'line' }
                    /*
                    ,
                    { valueField: "RelayStatus", name: "Watering Status",  argumentField: 'MessageTime',  type: 'line' },
                    { valueField: "TotalMiliLitres", name: "Spent Water Amount",  argumentField: 'MessageTime',  type: 'line' }
                    */
                ],
                zoomAndPan: {
                    argumentAxis: "both"
                },
                export: {
                    enabled: true
                },
                tooltip: {
                    enabled: true,
                    customizeTooltip: function (arg) {
                        return {
                            text: arg.seriesName + ' : ' + arg.valueText
                        };
                    }
                }
                
            });

            $('#chart-temperature').dxChart({
                dataSource: [],
                commonAxisSettings: {
                    grid: {
                        visible: true
                    }
                },
                argumentAxis: {
                    argumentType: 'datetime',
                    valueMarginsEnabled: false,
                    discreteAxisDivisionMode: "crossLabels",
                    // axisDivisionFactor: 600
                    //allowDecimals: falses
                },
                valueAxis: {
                    valueType: 'numeric'
                },
                series: {
                    argumentField: 'MessageTime',
                    valueField: 'Temperature',
                    type: 'line'
                },
                zoomAndPan: {
                    argumentAxis: "both"
                },
                legend :{
                 visible: false
                },

                export: {
                    enabled: true
                },
                tooltip: {
                    enabled: true,
                    customizeTooltip: function (arg) {
                        return {
                            text: arg.valueText
                        };
                    }
                }
                
            });
            $('#chart-humidity').dxChart({
                dataSource: [],
                commonAxisSettings: {
                    grid: {
                        visible: true
                    }
                },
                argumentAxis: {
                    argumentType: 'datetime'
                },
                valueAxis: {
                    valueType: 'numeric'
                },
                series: {
                    argumentField: 'MessageTime',
                    valueField: 'Humidity',
                    type: 'line'
                },
                zoomAndPan: {
                    argumentAxis: "both"
                },
                legend:{
                    visible: false
                },
                export: {
                    enabled: true
                },
                tooltip: {
                    enabled: true,
                    customizeTooltip: function (arg) {
                        return {
                            text: '% '+arg.valueText
                        };
                    }
                }

            });
            $('#chart-waterLevel').dxChart({
                dataSource: [],
                commonAxisSettings: {
                    grid: {
                        visible: true
                    }
                },
                argumentAxis: {
                    argumentType: 'datetime'
                },
                valueAxis: {
                    valueType: 'numeric'
                },
                series: {
                    argumentField: 'MessageTime',
                    valueField: 'WaterLevel',
                    type: 'line'
                },
                zoomAndPan: {
                    argumentAxis: "both"
                },
                legend:{
                 visible: false
                },
                export: {
                    enabled: true
                },
                tooltip: {
                    enabled: true,
                    customizeTooltip: function (arg) {
                        return {
                            text: arg.valueText
                        };
                    }
                }
            });
            
            var temperatureGauge = $("#temperatureGauge").dxLinearGauge({
                title: {
                   text: "Temperature (C)",
                   font: {
                      size: 12
                   }
                },
                geometry: { orientation: "vertical" },
                scale: {
                    startValue: -20, 
                    endValue: 50,
                    tickInterval: 1
                },
                rangeContainer: {
                    backgroundColor: "none",
                    ranges: [
                        { startValue: -20, endValue: 0, color: "#679EC5" },
                        { startValue: 0, endValue: 30 },
                        { startValue: 30, endValue: 50, color: "#92000A" }
                    ]
                },
                value: -20
            }).dxLinearGauge("instance");

            var humidityGauge = $("#humidityGauge").dxLinearGauge({
                title: {
                   text: "Air Humidty (%)",
                   font: {
                      size: 12
                   }
                },
                geometry: { orientation: "vertical" },
                scale: {
                    startValue: 0, 
                    endValue: 100,
                    tickInterval: 1
                },
                rangeContainer: {
                    backgroundColor: "none",
                    ranges: [
                        { startValue: 0, endValue: 100, color: "#679EC5" }
                    ]
                },
                value: 0
            }).dxLinearGauge("instance");

            var soilHumidityGauge = $("#soilHumidityGauge").dxLinearGauge({
                title: {   
                   text: "Soil Humidity (%)",
                   font: {
                      size: 12
                   }
                },
                geometry: { orientation: "vertical" },
                scale: {
                    startValue: 0, 
                    endValue: 100,
                    tickInterval: 5,
                },
                rangeContainer: { backgroundColor: "#CACACA" },
                valueIndicator: { type: "rhombus", color: "#A4DDED" },

            }).dxLinearGauge("instance");
                

            var waterLevelGauge = $("#waterLevelGauge").dxLinearGauge({
                title: {
                   text: "Water Tank Level (lt)",
                   font: {
                      size: 12
                   }
                },
                geometry: { orientation: "vertical" },
                scale: {
                    startValue: 0, 
                    endValue: 20,
                    tickInterval: 1
                },
                rangeContainer: {
                    backgroundColor: "none",
                    ranges: [
                        { startValue: 0, endValue: 5, color: "#92000A" },
                        { startValue: 5, endValue: 20, color: "#CACACA" }
                    ]
                },
                value: 20
            }).dxLinearGauge("instance");

            var fertiLevelGauge = $("#fertiLevelGauge").dxLinearGauge({
                title: {
                   text: "Fertilization Tank Level (lt)",
                   font: {
                      size: 12
                   }
                },
                geometry: { orientation: "vertical" },
                scale: {
                    startValue: 0, 
                    endValue: 20,
                    tickInterval: 1
                },
                rangeContainer: {
                    backgroundColor: "none",
                    ranges: [
                        { startValue: 0, endValue: 5, color: "#92000A" },
                        { startValue: 5, endValue: 20, color: "#CACACA" }
                    ]
                },
                value: 20
            }).dxLinearGauge("instance");

             var totalWaterGauge = $("#totalWaterGauge").dxCircularGauge({
                scale: {
                    startValue: 0,
                    endValue: 150,
                    tickInterval: 1,
                    label: {
                        useRangeColors: true
                    }
                },
                rangeContainer: {
                    palette: "ocean",
                    ranges: [
                        { startValue: 50, endValue: 90 },
                        { startValue: 90, endValue: 130 },
                        { startValue: 130, endValue: 150 }
                    ]
                },
                title: {
                    text: "Harcanan Su Miktar",
                    font: { size: 12 }
                },
                "export": {
                    enabled: true
                },
                value: 0
            }).dxCircularGauge("instance");

            var totalFertiGauge = $("#totalFertiGauge").dxCircularGauge({
                scale: {
                    startValue: 0,
                    endValue: 50,
                    tickInterval: 10,
                    label: {
                        useRangeColors: true
                    }
                },
                rangeContainer: {
                    palette: "ocean",
                    ranges: [
                        { startValue: 50, endValue: 90 },
                        { startValue: 90, endValue: 130 },
                        { startValue: 130, endValue: 150 }
                    ]
                },
                title: {
                    text: "Harcanan Gbre Miktar",
                    font: { size: 12 }
                },
                "export": {
                    enabled: true
                },
                value: 0
            }).dxCircularGauge("instance");

            $('#chart-soilHumidity').dxChart({
                dataSource: [],
                commonAxisSettings: {
                    grid: {
                        visible: true
                    }
                },
                argumentAxis: {
                    argumentType: 'datetime'
                },
                valueAxis: {
                    valueType: 'numeric'
                },
                series: {
                    argumentField: 'MessageTime',
                    valueField: 'SoilHumidity',
                    type: 'line'
                },
                zoomAndPan: {
                    argumentAxis: "both"
                },
                legend:{
                 visible: false
                },
                export: {
                    enabled: true
                },
                tooltip: {
                    enabled: true,
                    customizeTooltip: function (arg) {
                        return {
                            text: '% '+arg.valueText
                        };
                    }
                }
            });
            $('#chart-totalMiliLitres').dxChart({
                dataSource: [],
                commonAxisSettings: {
                    grid: {
                        visible: true
                    }
                },
                argumentAxis: {
                    argumentType: 'datetime'
                },
                valueAxis: {
                    valueType: 'numeric'
                },
                series: {
                    argumentField: 'MessageTime',
                    valueField: 'TotalMiliLitres',
                    type: 'line'
                },
                zoomAndPan: {
                    argumentAxis: "both"
                },
                legend:{
                 visible: false
                },
                export: {
                    enabled: true
                },
                tooltip: {
                    enabled: true,
                    customizeTooltip: function (arg) {
                        return {
                            text: arg.valueText
                        };
                    }
                }
                
            });

             
            var waterSlider = $("#water-slider").dxSlider({
                min: 0,
                max: 20,
                value: 10,
                tooltip: {
                    enabled: true,
                    format: function (value) {
                        return value + " lt";
                    },
                    showMode: "always", 
                    position: "bottom"
                },
                onValueChanged: function(data) {
                    waterSliderValue.option("value", data.value);
                }
            }).dxSlider("instance");
            
            var waterSliderValue = $("#water-slider-value").dxNumberBox({
                value: 10,
                min: 0,
                max: 20,
                showSpinButtons: true,
                onValueChanged: function(data) {
                    waterSlider.option("value", data.value);
                }
            }).dxNumberBox("instance");


            
            var seconds = 10,
                inProgress = false,
                intervalId;

            var progressBarStatus = $("#progressBarStatus").dxProgressBar({
                min: 0,
                max: 100,
                width: "100%",
                statusFormat:  function(value) { 
                    return "Watering process: " + value * 100 + "%"; 
                },
                onComplete: function(e){
                    inProgress = false;
                    waterSlider.option("disabled", false);
                    waterSlider.option("tooltip.enabled", true);
                    waterSliderValue.option("disabled", false);

                    progressButton.option("text", "Restart progress");
                    e.element.addClass("complete");
                    progressBarStatus.option("value", 0);
                    waterSlider.option("value", 0);
                    waterSliderValue.option("value", 0);
                }
            }).dxProgressBar("instance");
            
            var progressButton = $("#progress-button").dxButton({
                text: "Start Watering",
                width: 160,
                onClick: function() {
                    $("#progressBarStatus").removeClass("complete");
                    if (inProgress) {
                        waterSlider.option("disabled", false);
                        waterSlider.option("tooltip.enabled", true);
                        waterSliderValue.option("disabled", false);

                        progressButton.option("text", "Contiue");
                        clearInterval(intervalId);
                        iotHub.server.send('Command/watering?state=false\n');
                        progressBarStatus.option("value", 0);

                    } else {
                        waterSlider.option("disabled", true);
                        waterSlider.option("tooltip.enabled", false);
                        waterSliderValue.option("disabled", true);
                        
                        previousWateredAmount = $('#totalMiliLitres').text();

                        var litre = waterSlider.option("value");
                        console.log(litre);
                        DevExpress.ui.notify( "Sistem " + litre + " litre sulama yapmaya balad");
                        iotHub.server.send('Command/watering?state=true&amount='+litre+'\n');

                        progressButton.option("text", "Stop watering");
                        setCurrentStatus();
                        intervalId = setInterval(timer, 1000);
                    }
                    inProgress = !inProgress;
                }
            }).dxButton("instance");
            
            function setCurrentStatus() {
                

                var waterAmount = waterSlider.option("value");
                
                
                var instantAmount = $('#totalMiliLitres').text();
                wateredAmount = instantAmount - previousWateredAmount;

                progressBarStatus.option("value", (wateredAmount * 100) / waterAmount);
            }
                
            function timer() {
                waterStepper = waterSlider.option("value") - wateredAmount;
                
                //var waterStepper = litre - $('#totalMiliLitres').text();
                console.log(waterStepper);
                setCurrentStatus();
                if(waterStepper === 0) {
                    //iotHub.server.send('Command/watering?state=false\n');
                    clearInterval(intervalId);
                    inProgress == false;
                    //waterStepper = 10;
                    return;

                    
                }
            }

            var fertilizationSlider = $("#fertilization-slider").dxSlider({
                min: 0,
                max: 20,
                value: 10,
                tooltip: {
                    enabled: true,
                    format: function (value) {
                        return value + " lt";
                    },
                    showMode: "always", 
                    position: "bottom"
                },
                onValueChanged: function(data) {
                    fertilizationSliderValue.option("value", data.value);
                }
            }).dxSlider("instance");
            
            var fertilizationSliderValue = $("#fertilization-slider-value").dxNumberBox({
                value: 10,
                min: 0,
                max: 20,
                showSpinButtons: true,
                onValueChanged: function(data) {
                    fertilizationSlider.option("value", data.value);
                }
            }).dxNumberBox("instance");


            
            var secondsFerti = 10,
            inProgressFerti = false,
            intervalIdFerti;

            var fertilizationStatus = $("#fertilizationStatus").dxProgressBar({
                min: 0,
                max: 100,
                width: "100%",
                statusFormat:  function(value) { 
                    return "Fertilization process: " + value * 100 + "%"; 
                },
                onComplete: function(e){
                    inProgressFerti = false;
                    fertilizationSlider.option("disabled", false);
                    fertilizationSlider.option("tooltip.enabled", true);
                    fertilizationSliderValue.option("disabled", false);

                    fertilizationButton.option("text", "Restart progress");
                    e.element.addClass("complete");
                }
            }).dxProgressBar("instance");
            
            var fertilizationButton = $("#fertilizationButton").dxButton({
                text: "Start Fertilization",
                width: 160,
                onClick: function() {
                    $("#fertilizationStatus").removeClass("complete");
                    if (inProgressFerti) {
                        fertilizationSlider.option("disabled", false);
                        fertilizationSlider.option("tooltip.enabled", true);
                        fertilizationSliderValue.option("disabled", false);

                        fertilizationButton.option("text", "Contiue Fertilization");
                        clearInterval(intervalIdFerti);
                        iotHub.server.send('Command/fertilization?state=false\n');
                        fertilizationStatus.option("value", 0);

                    } else {
                        fertilizationSlider.option("disabled", true);
                        fertilizationSlider.option("tooltip.enabled", false);
                        fertilizationSliderValue.option("disabled", true);
                        
                        previousFertiAmount = $('#totalFerti').text();

                        var litreFerti = fertilizationSlider.option("value");
                        console.log(litreFerti);
                        DevExpress.ui.notify( "Sistem " + litreFerti + " litre gbreleme yapmaya balad");
                        iotHub.server.send('Command/fertilization?state=true&amount='+litreFerti+'\n');

                        fertilizationButton.option("text", "Stop Fertilization");
                        setCurrentStatusFerti();
                        intervalIdFerti = setInterval(timerFerti, 1000);
                    }
                    inProgressFerti = !inProgressFerti;
                }
            }).dxButton("instance");
            
            function setCurrentStatusFerti() {
                

                var fertiAmount = fertilizationSlider.option("value");
                
                
                var instantFertiAmount = $('#totalFerti').text();
                fertilizedAmount = instantFertiAmount - previousFertiAmount;

                fertilizationStatus.option("value", (fertilizedAmount * 100) / fertiAmount);
            }
                
            function timerFerti() {
                var fertiStepper = fertilizationSlider.option("value") - fertilizedAmount;
                
                //var waterStepper = litre - $('#totalMiliLitres').text();
                console.log(fertiStepper);
                setCurrentStatusFerti();
                if(fertiStepper === 0) {
                    //iotHub.server.send('Command/watering?state=false\n');
                    clearInterval(intervalIdFerti);
                    //waterStepper = 10;
                    return;

                    
                }
            }


            var handlerRangeSlider = $("#handler-range-slider").dxRangeSlider({
                min: 0,
                max: 100,
                start: 10,
                end: 30,
                disabled: true,
                label: {
                    visible: true,
                    format: function(value) {
                        return value + "%";
                    },
                    position: "top"
                },
                tooltip: {
                    enabled: true,
                    format: function (value) {
                        return value + "%";
                    },
                    showMode: "onHover", 
                    position: "bottom"
                },
                onValueChanged: function(data){
                    startValue.option("value", data.start);
                    endValue.option("value", data.end);

                }
            }).dxRangeSlider("instance");
            
            var startValue = $("#start-value").dxNumberBox({
                value: 10,
                min: 0,
                max: 100,
                disabled: true,
                showSpinButtons: true,
                onValueChanged: function(data) {
                    handlerRangeSlider.option("start", data.value);
...

This file has been truncated, please download it to see its full contents.
C# application
C# listener application

Schematics

Circuit Scheme
Uploads2ftmp2f37fef9d9 96e0 44b2 9453 4c7a64b99dde2fscheme qre43mnysi

Comments

Similar projects you might like

Smart Parking System

Project in progress by Md. Khairul Alam

  • 58,182 views
  • 36 comments
  • 127 respects

RF BASED SMART HOME AUTOMATION SYSTEM

by Dennis Mwanza

  • 34,166 views
  • 5 comments
  • 51 respects

Arduino Controlled Smart Hydroponic Modular System

Project in progress by Luis Antonio Martin Nuez

  • 19,959 views
  • 4 comments
  • 98 respects

Plant Watering System

Project showcase by Niko123

  • 7,422 views
  • 2 comments
  • 17 respects

Smart Home Automation

by Team Kamakshi's Smart Team

  • 6,589 views
  • 1 comment
  • 15 respects
Add projectSign up / Login