From 86a3d19b5966bd5dea695a8755c8d3d568b2f1ec Mon Sep 17 00:00:00 2001 From: Bolukan Date: Thu, 1 Oct 2020 07:22:50 +0200 Subject: [PATCH 1/2] Update to V1.3.0 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 31f89a9..eaa2385 100644 --- a/library.json +++ b/library.json @@ -12,7 +12,7 @@ "type": "git", "url": "https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot" }, - "version": "1.2.0", + "version": "1.3.0", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 78aca94..fc18f2e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=UniversalTelegramBot -version=1.2.0 +version=1.3.0 author=Brian Lough maintainer=Brian Lough sentence=Arduino Telegram Bot library for multiple different architectures. From b21db4fd8502e87df4e3782a491aa972a9bac640 Mon Sep 17 00:00:00 2001 From: Bolukan Date: Thu, 1 Oct 2020 07:51:32 +0200 Subject: [PATCH 2/2] Styling --- .../UpdateInlineKeyboard.ino | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/examples/ESP32/CustomKeyboard/UpdateInlineKeyboard/UpdateInlineKeyboard.ino b/examples/ESP32/CustomKeyboard/UpdateInlineKeyboard/UpdateInlineKeyboard.ino index 80ba5ca..73efb33 100644 --- a/examples/ESP32/CustomKeyboard/UpdateInlineKeyboard/UpdateInlineKeyboard.ino +++ b/examples/ESP32/CustomKeyboard/UpdateInlineKeyboard/UpdateInlineKeyboard.ino @@ -11,21 +11,20 @@ #include #include -// Initialize Wifi connection to the router -const char *ssid = "mySSID"; -const char *password = "myPASSWORD"; +// Wifi network station credentials +#define WIFI_SSID "YOUR_SSID" +#define WIFI_PASSWORD "YOUR_PASSWORD" +// Telegram BOT Token (Get from Botfather) +#define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -// Initialize Telegram BOT -#define BOTtoken "xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxx" // your Bot Token (Get from Botfather) -WiFiClientSecure client; -UniversalTelegramBot bot(BOTtoken, client); +// LED parameters +const int ledPin = 2; // Internal LED on DevKit ESP32-WROOM (GPIO2) +const unsigned long BOT_MTBS = 1000; // mean time between scan messages -int Bot_mtbs = 1000; //mean time between scan messages -long Bot_lasttime; //last time messages' scan has been done +WiFiClientSecure secured_client; +UniversalTelegramBot bot(BOT_TOKEN, secured_client); +unsigned long bot_lasttime; // last time messages' scan has been done int last_message_id = 0; - -// LED parameters -const int ledPin = 2; // Internal LED on DevKit ESP32-WROOM (GPIO2) int ledState = LOW; void handleNewMessages(int numNewMessages) @@ -134,35 +133,39 @@ void handleNewMessages(int numNewMessages) void setup() { Serial.begin(115200); + Serial.println(); - // Attempt to connect to Wifi network: - Serial.print("Connecting Wifi: "); - Serial.println(ssid); - - // Set WiFi to station mode and disconnect from an AP if it was Previously - // connected - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - + // attempt to connect to Wifi network: + Serial.print("Connecting to Wifi SSID "); + Serial.print(WIFI_SSID); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } - - Serial.println(""); - Serial.println("WiFi connected"); - Serial.print("IP address: "); + Serial.print("\nWiFi connected. IP address: "); Serial.println(WiFi.localIP()); + Serial.print("Retrieving time: "); + configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP + time_t now = time(nullptr); + while (now < 24 * 3600) + { + Serial.print("."); + delay(100); + now = time(nullptr); + } + Serial.println(now); + pinMode(ledPin, OUTPUT); // initialize ledPin as an output. digitalWrite(ledPin, ledState); // initialize pin as low (LED Off) } void loop() { - // run this in loop to poll new messages - if (millis() > Bot_lasttime + Bot_mtbs) + if (millis() - bot_lasttime > BOT_MTBS) { int numNewMessages = bot.getUpdates(bot.last_message_received + 1); @@ -173,6 +176,6 @@ void loop() numNewMessages = bot.getUpdates(bot.last_message_received + 1); } - Bot_lasttime = millis(); + bot_lasttime = millis(); } } \ No newline at end of file