You are on page 1of 2

#include <ESP8266WiFi.

h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <UrlEncode.h>

float analog_value1 = 0.0;

const char* ssid = "Galaxy M028d2c";


const char* password = "ovjf5620";
String phoneNumber = "+94773822512";
String apiKey = "3351873";

void sendMessage(String message){

String url = "http://api.callmebot.com/whatsapp.php?phone=" + phoneNumber +


"&apikey=" + apiKey + "&text=" + urlEncode(message);

WiFiClient client;
HTTPClient http;
http.begin(client, url);

// Specify content-type header


http.addHeader("Content-Type", "application/x-www-form-urlencoded");
Serial.println("");
Serial.print("NodeMcu connected to wifi...");
Serial.println(ssid);
int httpResponseCode = http.POST(url);
if (httpResponseCode == 200){
Serial.print("Message sent successfully");
}
else{
Serial.println("Error sending the message");
Serial.print("HTTP response code: ");
Serial.println(httpResponseCode);
}

// Free resources
http.end();
}

void setup() {

Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());

// Send Message to WhatsAPP


sendMessage("Hello from ESP8266!");
}

void loop() {
analog_value1 = analogRead(A0);
if (analog_value1 <= 10){
sendMessage("Line 1 MNR ON By Supervisor");}

if (analog_value1 >= 500){


sendMessage("Line 1 MNR Off and Check By Supervisor");}

You might also like