#include <ETH.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <WiFiUdp.h>



#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>

// Replace with your network credentials
const char* ssid = "iPhone";
const char* password = "12345678";

// Initialize Telegram BOT
#define BOTtoken "1302903030:AAECPBuLpik9gW7ZpoRTs2V6r4JcpPA_c-8"  // your Bot Token (Get from Botfather)

// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "1270771384"

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

const int Vsensor = 34; // PIR Motion Sensor
int sensorValue = 0;
bool powerdowen = false;

void setup() {
  Serial.begin(115200);
  delay(1000);
   
//   Attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while  (WiFi.status() == WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  bot.sendMessage(CHAT_ID, "Bot started up", "");
}
void loop() {
  // Reading potentiometer value
 sensorValue = analogRead(34);
  Serial.println(sensorValue);
  delay(500);
  if(sensorValue == 0){
    bot.sendMessage(CHAT_ID, "powerdowen", "");
    Serial.println("powerdown");
  
  }
}
