Skip to content

Commit

Permalink
Merge pull request #205 from Bolukan/master
Browse files Browse the repository at this point in the history
Update to V1.3.0
  • Loading branch information
witnessmenow authored Nov 8, 2020
2 parents 7b56463 + b21db4f commit 5c01f75
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

// 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)
Expand Down Expand Up @@ -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);

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

Bot_lasttime = millis();
bot_lasttime = millis();
}
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=UniversalTelegramBot
version=1.2.0
version=1.3.0
author=Brian Lough
maintainer=Brian Lough <[email protected]>
sentence=Arduino Telegram Bot library for multiple different architectures.
Expand Down

0 comments on commit 5c01f75

Please sign in to comment.