Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CTBot.h"
- #include "DHT.h"
- #define dht11_PIN D4
- DHT dht(dht11_PIN, DHT11);
- CTBot myBot;
- float temp_Value;
- float hum_Value;
- String ssid = "network"; // REPLACE mySSID WITH YOUR WIFI SSID
- String pass = "123456789"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
- String token = "5316933044:AAFP4Huo7KpzrlPaDV-o3BuZUKaBlBIR16U";
- //"5303605044:AAGU8H0XDaYFlxNSlqWiULycmVNfFXP6aMw"; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
- uint8_t led1 = D1;
- uint8_t led2 = D2; // the onboard ESP8266 LED.
- // If you have a NodeMCU you can use the BUILTIN_LED pin
- // (replace 2 with BUILTIN_LED)
- void setup() {
- // initialize the Serial
- Serial.begin(115200);
- Serial.println("Starting TelegramBot...");
- // connect the ESP8266 to the desired access point
- myBot.wifiConnect(ssid, pass);
- // set the telegram bot token
- myBot.setTelegramToken(token);
- // check if all things are ok
- if (myBot.testConnection())
- Serial.println("\ntestConnection OK");
- else
- Serial.println("\ntestConnection NOK");
- }
- void loop() {
- // a variable to store telegram message data
- TBMessage msg;
- temp_Value = checkTemp();
- hum_Value = checkHum();
- // if there is an incoming message...
- if (myBot.getNewMessage(msg)) {
- if (msg.text.equalsIgnoreCase("temp")||msg.text.equalsIgnoreCase("Temp")) { // if the received message is "LIGHT ON"...
- float value_1 = checkTemp();
- float value_2 = checkHum();
- String reply1;
- String reply2;
- reply1 = (String)"Temprature reading is : " + String(value_1);
- reply2 = (String)"Humidity reading is : " + String(value_2);
- myBot.sendMessage(msg.sender.id, "Temprature reading is : " + String(value_1));
- myBot.sendMessage(msg.sender.id, "Humidity reading is : " + String(value_2));
- }
- //else { // otherwise...
- // generate the message for the sender
- //String reply;
- //reply = (String)"Welcome " + msg.sender.username + (String)". Try LIGHT ON or LIGHT OFF.";
- //myBot.sendMessage(msg.sender.id, reply); // and send it
- //}
- }
- if (temp_Value>30){
- myBot.sendMessage(msg.sender.id, "HIGH Tempreture detected !!!");
- }
- // wait 500 milliseconds
- delay(500);
- }//end of LOOP
- float checkTemp() {
- float value1 = dht.readTemperature();
- //Serial.print("temprature value: ");
- //Serial.println(value1);
- return value1;
- }
- float checkHum() {
- float value2 = dht.readHumidity();
- //Serial.print("humidity value: ");
- //Serial.println(value2);
- return value2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement