-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8837fa
commit 25c0c29
Showing
9 changed files
with
350 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************* | ||
* An example of bot that echos back any messages received, | ||
* including ones from channels | ||
* | ||
* written by Brian Lough | ||
*******************************************************************/ | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <UniversalTelegramBot.h> | ||
|
||
// Initialize Wifi connection to the router | ||
char ssid[] = "XXXXXX"; // your network SSID (name) | ||
char password[] = "YYYYYY"; // your network key | ||
|
||
// Initialize Telegram BOT | ||
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather) | ||
|
||
WiFiClientSecure client; | ||
UniversalTelegramBot bot(BOTtoken, client); | ||
|
||
int Bot_mtbs = 1000; //mean time between scan messages | ||
long Bot_lasttime; //last time messages' scan has been done | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// Set WiFi to station mode and disconnect from an AP if it was Previously | ||
// connected | ||
WiFi.mode(WIFI_STA); | ||
WiFi.disconnect(); | ||
delay(100); | ||
|
||
// Attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
if (millis() > Bot_lasttime + Bot_mtbs) { | ||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
|
||
while(numNewMessages) { | ||
Serial.println("got response"); | ||
for (int i=0; i<numNewMessages; i++) { | ||
if(bot.messages[i].type == "channel_post") { | ||
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].chat_title + " " + bot.messages[i].text, ""); | ||
} else { | ||
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, ""); | ||
} | ||
} | ||
|
||
numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
} | ||
|
||
Bot_lasttime = millis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/******************************************************************* | ||
* An example of recieving location Data | ||
* | ||
* | ||
* By Brian Lough | ||
*******************************************************************/ | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <UniversalTelegramBot.h> | ||
|
||
// Initialize Wifi connection to the router | ||
char ssid[] = "SSID"; // your network SSID (name) | ||
char password[] = "password"; // your network key | ||
|
||
// Initialize Telegram BOT | ||
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather) | ||
|
||
WiFiClientSecure client; | ||
UniversalTelegramBot bot(BOTtoken, client); | ||
|
||
int Bot_mtbs = 1000; //mean time between scan messages | ||
long Bot_lasttime; //last time messages' scan has been done | ||
|
||
void handleNewMessages(int numNewMessages) { | ||
|
||
for (int i = 0; i < numNewMessages; i++) { | ||
|
||
String chat_id = String(bot.messages[i].chat_id); | ||
String text = bot.messages[i].text; | ||
|
||
String from_name = bot.messages[i].from_name; | ||
if (from_name == "") from_name = "Guest"; | ||
|
||
if (bot.messages[i].longitude != 0 || bot.messages[i].latitude != 0) { | ||
Serial.print("Long: "); | ||
Serial.println(String(bot.messages[i].longitude, 6)); | ||
Serial.print("Lat: "); | ||
Serial.println(String(bot.messages[i].latitude, 6)); | ||
|
||
String message = "Long: " + String(bot.messages[i].longitude, 6) + "\n"; | ||
message += "Lat: " + String(bot.messages[i].latitude, 6) + "\n"; | ||
bot.sendMessage(chat_id, message, "Markdown"); | ||
} else if (text == "/start") { | ||
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n"; | ||
welcome += "Share a location or a live location and the bot will respond with the co-ords\n"; | ||
|
||
bot.sendMessage(chat_id, welcome, "Markdown"); | ||
} | ||
} | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// Set WiFi to station mode and disconnect from an AP if it was Previously connected | ||
WiFi.mode(WIFI_STA); | ||
WiFi.disconnect(); | ||
delay(100); | ||
|
||
// attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
if (millis() > Bot_lasttime + Bot_mtbs) { | ||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
|
||
while (numNewMessages) { | ||
Serial.println("got response"); | ||
handleNewMessages(numNewMessages); | ||
numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
} | ||
|
||
Bot_lasttime = millis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************* | ||
* An example of setting a long poll, this will mean the request | ||
* for new messages will wait the specified amount of time before | ||
* returning with no messages | ||
* | ||
* This should reduce amount of data used by the bot | ||
* | ||
* written by Brian Lough | ||
*******************************************************************/ | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <UniversalTelegramBot.h> | ||
|
||
// Initialize Wifi connection to the router | ||
char ssid[] = "XXXXXX"; // your network SSID (name) | ||
char password[] = "YYYYYY"; // your network key | ||
|
||
// Initialize Telegram BOT | ||
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather) | ||
|
||
WiFiClientSecure client; | ||
UniversalTelegramBot bot(BOTtoken, client); | ||
|
||
int Bot_mtbs = 1000; //mean time between scan messages | ||
long Bot_lasttime; //last time messages' scan has been done | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// Set WiFi to station mode and disconnect from an AP if it was Previously | ||
// connected | ||
WiFi.mode(WIFI_STA); | ||
WiFi.disconnect(); | ||
delay(100); | ||
|
||
// Attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
bot.longPoll = 60; | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
if (millis() > Bot_lasttime + Bot_mtbs) { | ||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
|
||
while(numNewMessages) { | ||
Serial.println("got response"); | ||
for (int i=0; i<numNewMessages; i++) { | ||
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, ""); | ||
} | ||
numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
} | ||
Serial.println("I will happen much less often with a long poll"); | ||
Bot_lasttime = millis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.