Tuesday 6 April 2021

Own IOT website and Hardware Using Node MCU (cyber thinks)

NODE MCU code -- website link Cyberthinks

google drive link cyberthinks website files

#include <ESP8266WiFi.h>

#include <ArduinoJson.h>


const char* ssid     = "#Hacker";

const char* password = "M.A.K.E.R.B.O.T.";

const char* host = "cyberthinks.000webhostapp.com"; //replace it with your webhost url

String url;

int count = 0;



void setup() {

  Serial.begin(115200);

  delay(100);

  pinMode(D0, OUTPUT);

  digitalWrite(D1, 0);


  Serial.println();

  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.println("WiFi connected");

  Serial.println("IP address: ");

  Serial.println(WiFi.localIP());

  Serial.print("Netmask: ");

  Serial.println(WiFi.subnetMask());

  Serial.print("Gateway: ");

  Serial.println(WiFi.gatewayIP());

  digitalWrite(D1, 1);

  delay(500);

  digitalWrite(D1, 0);

  delay(500);

}


void loop() {


  Serial.print("connecting to ");

  Serial.println(host);


  WiFiClient client;

  const int httpPort = 80;

  if (!client.connect(host, httpPort)) {

    Serial.println("connection failed");

    return;

  }


  Serial.print("Requesting URL: ");

  Serial.println(url);



  url = "/api/readcommand.php";

  count = count + 1;

  Serial.println("Here1");



  client.print(String("GET ") + url + " HTTP/1.1\r\n" +

               "Host: " + host + "\r\n" +

               "Connection: close\r\n\r\n");


  //Serial.println(String("GET ") + url + " HTTP/1.1\r\n" +

               //  "Host: " + host + "\r\n" +

               //  "Connection: close\r\n\r\n");


  delay(500);

  String section = "header";

  while (client.available()) {

    String line = client.readStringUntil('krkg');


    Serial.println("********************");

    Serial.println(line);

    Serial.println("......................");


    if (section == "header") { // headers..


      if (line == "\n") { // skips the empty space at the beginning

        section = "json";

      }

    }

    

    else if (section == "json") { // print the good stuff

      section = "ignore";

      String result = line.substring(1);


      // Parse JSON

      int size = result.length() + 1;

      char json[size];

      result.toCharArray(json, size);

      StaticJsonBuffer<200> jsonBuffer;

      JsonObject& json_parsed = jsonBuffer.parseObject(json);

      

      if (!json_parsed.success())

      {

        Serial.println("parseObject() failed");

        return;

      }

      

      String led = json_parsed["data"][0];


      Serial.print("mydata:");

      Serial.println(led);


      if (led == "500") {

        digitalWrite(D0, 1);

        delay(100);

        Serial.println("D1 is On..!");

      }

      else if (led == "600") {

        digitalWrite(D0, 0);

        delay(100);

        Serial.println("D1 is Off..!");

      }


    }

  }

  Serial.println();

  Serial.println("closing connection");

  delay(3000);

}


Sunday 4 April 2021

Electricity theft detection system Using Arduino nano and Sim 800l

 



Arduino Code

#include "ACS712.h"

ACS712 sensor1(ACS712_30A, A0);  /// current sensor attached to A0 of arduino nano
ACS712 sensor2(ACS712_30A, A1); /// current sensor attached to 1 of arduino nano

#include <LiquidCrystal.h>  ////////lcd screen
#include <SoftwareSerial.h>  /////Sim 800l communication

SoftwareSerial sim(11, 12); //tx,rx

String number = "9080154392";  //message number

String alert = "ALERT ! Theft Identified";  ///alert message

int i = 0;   

int senttime = 0;
int currenttime = 0;

float I1 = 0.00;
float I2 = 0.00;

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


void setup()
{
  pinMode(13, OUTPUT);

  Serial.begin(9600); //baud rate of serial communication between computer and arduino
  
  lcd.begin(16, 2);
  sim.begin(115200); //baud rate of serial communication between arduino and sim 800l

  lcd.clear();
  
  lcd.setCursor(0, 0);

  lcd.print("  POWER  THEFT  ");
  lcd.setCursor(0, 1);
  lcd.print(" IDENTIFICATION ");

  delay(2000);

  lcd.clear();
  lcd.setCursor(0, 0);

  lcd.print("STARTING  DEVICE");
  delay(250);
  lcd.setCursor(0, 1);
  lcd.print("   in    secs   ");

  Serial.println("Starting Device wait 20 secs");

  for (i = 20; i > 0; i--)
  {
    lcd.setCursor(6, 1);
    lcd.print("  ");
    lcd.setCursor(6, 1);
    lcd.print(i);
    delay(1000);
  }

  ////////////////////////////////////////GSM Initialization/////////////////////////////////////////////

  sim.println("AT");
  delay(200);
  sim.println("AT");
  delay(200);

  if (sim.find("OK"))
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("   GSM module   ");
    lcd.setCursor(0, 1);
    lcd.print("     ready!     ");

    Serial.println("GSM  Module Ready");

    delay(1000);
  }

  else
  {
    while (1)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("     !ERROR!    ");
      lcd.setCursor(0, 1);
      lcd.print("check GSM module");

      Serial.println("GSM Module error check wires or restart device to fix");

      delay(1000);
    }
  }

  /////////////////////////////////////////////Sensor calibrartion/////////////////////////////////////////////////

  Serial.println("Calibrating... Ensure that no current flows through the sensor at this moment");
  sensor1.calibrate();
  sensor2.calibrate();
  Serial.println("Done!");
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("   Calibrating  ");
  lcd.setCursor(0, 1);
  lcd.print("     sensors    ");
  delay(2000);
}


void loop()
{
  get_sensor_data();

  if ((I1 - I2) > 0.16)
  {
    delay(1000);
    get_sensor_data();
    theftanalysis();
    
    delay(1000);
    get_sensor_data();

    if ((I1 - I2) > 0.16)
    {
      get_sensor_data();
      theftscreen();  ///////////theft confirm

      currenttime = millis();

      Serial.print("current time : ");
      Serial.println(currenttime);

      Serial.print("sent time : ");
      Serial.println(senttime);

      if ((currenttime - senttime) > 20000)
      {
        send_alert();  ////mesge sending
      }

      digitalWrite(13, HIGH);
    }
  }

  else if ((I1 - I2) < 0.10)
  {
    get_sensor_data();
    normal();
    digitalWrite(13, LOW);
  }
}

/////////////////////////////////sensor Function///////////////////////////////////////////

void normal()
{

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Dist meter     A");
  lcd.setCursor(11, 0);
  lcd.print("    ");
  lcd.setCursor(11, 0);
  lcd.print(I1);

  lcd.setCursor(0, 1);
  lcd.print("Home meter     A");
  lcd.setCursor(11, 1);
  lcd.print("    ");
  lcd.setCursor(11, 1);
  lcd.print(I2);

  Serial.println("Normal");
  Serial.print("Distribution Meter: ");
  Serial.print(I1);
  Serial.println("A");

  Serial.print("Home Meter: ");
  Serial.print(I2);
  Serial.println("A");


  delay(1000);
}

////////////////////////////////gsm functions//////////////////////////////////////////////

void send_alert()
{

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Sending  Message");
  lcd.setCursor(3, 1);
  lcd.print(number);


  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(100);
  sim.println("AT+CMGS=\"" + number + "\"\r");   //specifys the number to send message
  delay(100);
  String SMS = String(alert);
  sim.println(SMS);
  delay(100);
  sim.println((char)26);        //exits from sms mode

  delay(1000);
  senttime = millis();
}

//////////////////////////////////////Theft Screen///////////////////////////////////////

void theftscreen()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("  Alert! Theft  ");

  lcd.setCursor(0, 1);
  lcd.print("D:    A");
  lcd.setCursor(2, 1);
  lcd.print("    ");
  lcd.setCursor(2, 1);
  lcd.print(I1);

  lcd.setCursor(9, 1);
  lcd.print("H:    A");
  lcd.setCursor(11, 1);
  lcd.print("    ");
  lcd.setCursor(11, 1);
  lcd.print(I2);

  Serial.println("ALERT! Theft");
  Serial.print("Distribution Meter: ");
  Serial.print(I1);
  Serial.println("A");

  Serial.print("Home Meter: ");
  Serial.print(I2);
  Serial.println("A");
}

/////////////////////////////////Theft Analyse///////////////////////////////////////////////


void theftanalysis()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Analysing  Theft");

  lcd.setCursor(0, 1);
  lcd.print("D:    A");
  lcd.setCursor(2, 1);
  lcd.print("    ");
  lcd.setCursor(2, 1);
  lcd.print(I1);

  lcd.setCursor(9, 1);
  lcd.print("H:    A");
  lcd.setCursor(11, 1);
  lcd.print("    ");
  lcd.setCursor(11, 1);
  lcd.print(I2);


  Serial.println(" Analysing Theft");
  Serial.print("Distribution Meter: ");
  Serial.print(I1);
  Serial.println("A");

  Serial.print("Home Meter: ");
  Serial.print(I2);
  Serial.println("A");
}

///////////////////////////////////////////get sensor data////////////////////////

void get_sensor_data()
{
  I1 = sensor1.getCurrentAC();
  I2 = sensor2.getCurrentAC();
}


Own IOT website and Hardware Using Node MCU (cyber thinks)

NODE MCU code -- website link  Cyberthinks google drive link  cyberthinks website files #include <ESP8266WiFi.h> #include <ArduinoJ...