Skip to content

Commit 751fe70

Browse files
committed
Adding ESP32 send Message From Event
1 parent 0cf304a commit 751fe70

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************
2+
A telegram bot that sends you a message when ESP
3+
starts up
4+
5+
Parts:
6+
ESP32 D1 Mini stlye Dev board* - http://s.click.aliexpress.com/e/C6ds4my
7+
(or any ESP32 board)
8+
9+
= Affilate
10+
11+
If you find what I do useful and would like to support me,
12+
please consider becoming a sponsor on Github
13+
https://github.com/sponsors/witnessmenow/
14+
15+
16+
Written by Brian Lough
17+
YouTube: https://www.youtube.com/brianlough
18+
Tindie: https://www.tindie.com/stores/brianlough/
19+
Twitter: https://twitter.com/witnessmenow
20+
*******************************************************************/
21+
22+
// ----------------------------
23+
// Standard ESP32 Libraries
24+
// ----------------------------
25+
26+
#include <WiFi.h>
27+
#include <WiFiClientSecure.h>
28+
29+
// ----------------------------
30+
// Additional Libraries - each one of these will need to be installed.
31+
// ----------------------------
32+
33+
#include <UniversalTelegramBot.h>
34+
35+
#include <ArduinoJson.h>
36+
// Library used for parsing Json from the API responses
37+
38+
// Search for "Arduino Json" in the Arduino Library manager
39+
// https://github.com/bblanchon/ArduinoJson
40+
41+
// Initialize Wifi connection to the router
42+
char ssid[] = "XXXXXX"; // your network SSID (name)
43+
char password[] = "YYYYYY"; // your network key
44+
45+
// Use @myidbot to find out the chat ID of an individual or a group
46+
// Also note that you need to click "start" on a bot before it can
47+
// message you
48+
#define CHAT_ID "175753388"
49+
50+
// Initialize Telegram BOT
51+
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
52+
53+
WiFiClientSecure client;
54+
UniversalTelegramBot bot(BOTtoken, client);
55+
56+
void setup() {
57+
Serial.begin(115200);
58+
59+
// Attempt to connect to Wifi network:
60+
Serial.print("Connecting Wifi: ");
61+
Serial.println(ssid);
62+
63+
// Set WiFi to station mode and disconnect from an AP if it was Previously
64+
// connected
65+
WiFi.mode(WIFI_STA);
66+
WiFi.begin(ssid, password);
67+
68+
while (WiFi.status() != WL_CONNECTED) {
69+
Serial.print(".");
70+
delay(500);
71+
}
72+
73+
Serial.println("");
74+
Serial.println("WiFi connected");
75+
Serial.print("IP address: ");
76+
Serial.println(WiFi.localIP());
77+
78+
bot.sendMessage(CHAT_ID, "Bot started up", "");
79+
}
80+
81+
void loop() {
82+
83+
}

0 commit comments

Comments
 (0)