Skip to content

Commit 5c01f75

Browse files
authored
Merge pull request #205 from Bolukan/master
Update to V1.3.0
2 parents 7b56463 + b21db4f commit 5c01f75

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

examples/ESP32/CustomKeyboard/UpdateInlineKeyboard/UpdateInlineKeyboard.ino

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@
1111
#include <WiFiClientSecure.h>
1212
#include <UniversalTelegramBot.h>
1313

14-
// Initialize Wifi connection to the router
15-
const char *ssid = "mySSID";
16-
const char *password = "myPASSWORD";
14+
// Wifi network station credentials
15+
#define WIFI_SSID "YOUR_SSID"
16+
#define WIFI_PASSWORD "YOUR_PASSWORD"
17+
// Telegram BOT Token (Get from Botfather)
18+
#define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
1719

18-
// Initialize Telegram BOT
19-
#define BOTtoken "xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxx" // your Bot Token (Get from Botfather)
20-
WiFiClientSecure client;
21-
UniversalTelegramBot bot(BOTtoken, client);
20+
// LED parameters
21+
const int ledPin = 2; // Internal LED on DevKit ESP32-WROOM (GPIO2)
22+
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
2223

23-
int Bot_mtbs = 1000; //mean time between scan messages
24-
long Bot_lasttime; //last time messages' scan has been done
24+
WiFiClientSecure secured_client;
25+
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
26+
unsigned long bot_lasttime; // last time messages' scan has been done
2527
int last_message_id = 0;
26-
27-
// LED parameters
28-
const int ledPin = 2; // Internal LED on DevKit ESP32-WROOM (GPIO2)
2928
int ledState = LOW;
3029

3130
void handleNewMessages(int numNewMessages)
@@ -134,35 +133,39 @@ void handleNewMessages(int numNewMessages)
134133
void setup()
135134
{
136135
Serial.begin(115200);
136+
Serial.println();
137137

138-
// Attempt to connect to Wifi network:
139-
Serial.print("Connecting Wifi: ");
140-
Serial.println(ssid);
141-
142-
// Set WiFi to station mode and disconnect from an AP if it was Previously
143-
// connected
144-
WiFi.mode(WIFI_STA);
145-
WiFi.begin(ssid, password);
146-
138+
// attempt to connect to Wifi network:
139+
Serial.print("Connecting to Wifi SSID ");
140+
Serial.print(WIFI_SSID);
141+
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
142+
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
147143
while (WiFi.status() != WL_CONNECTED)
148144
{
149145
Serial.print(".");
150146
delay(500);
151147
}
152-
153-
Serial.println("");
154-
Serial.println("WiFi connected");
155-
Serial.print("IP address: ");
148+
Serial.print("\nWiFi connected. IP address: ");
156149
Serial.println(WiFi.localIP());
157150

151+
Serial.print("Retrieving time: ");
152+
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
153+
time_t now = time(nullptr);
154+
while (now < 24 * 3600)
155+
{
156+
Serial.print(".");
157+
delay(100);
158+
now = time(nullptr);
159+
}
160+
Serial.println(now);
161+
158162
pinMode(ledPin, OUTPUT); // initialize ledPin as an output.
159163
digitalWrite(ledPin, ledState); // initialize pin as low (LED Off)
160164
}
161165

162166
void loop()
163167
{
164-
// run this in loop to poll new messages
165-
if (millis() > Bot_lasttime + Bot_mtbs)
168+
if (millis() - bot_lasttime > BOT_MTBS)
166169
{
167170
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
168171

@@ -173,6 +176,6 @@ void loop()
173176
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
174177
}
175178

176-
Bot_lasttime = millis();
179+
bot_lasttime = millis();
177180
}
178181
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"type": "git",
1313
"url": "https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot"
1414
},
15-
"version": "1.2.0",
15+
"version": "1.3.0",
1616
"license": "MIT",
1717
"frameworks": "arduino",
1818
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=UniversalTelegramBot
2-
version=1.2.0
2+
version=1.3.0
33
author=Brian Lough
44
maintainer=Brian Lough <brian.d.lough@gmail.com>
55
sentence=Arduino Telegram Bot library for multiple different architectures.

0 commit comments

Comments
 (0)