Skip to content

Commit 92fa5f4

Browse files
committed
Update 101 examples
1 parent ee395f4 commit 92fa5f4

File tree

7 files changed

+168
-158
lines changed

7 files changed

+168
-158
lines changed

examples/UntestedSinceUpgrade/101/CustomKeyboard/CustomKeyboard.ino renamed to examples/Untested/101/CustomKeyboard/CustomKeyboard.ino

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,61 @@
88
#include <WiFiSSLClient.h>
99
#include <WiFi101.h>
1010
#include <UniversalTelegramBot.h>
11+
#include <SPI.h>
1112

12-
13-
// Initialize Wifi connection to the router
14-
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxx"; // your network SSID (name)
15-
char password[] = "yyyyyyyy"; // your network key
16-
17-
13+
// Wifi network station credentials
14+
#define WIFI_SSID "YOUR_SSID"
15+
#define WIFI_PASSWORD "YOUR_PASSWORD"
16+
// Telegram BOT Token (Get from Botfather)
17+
#define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
1818

1919
const int ledPin = 13;
20-
21-
// Initialize Telegram BOT
22-
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
20+
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
2321

2422
WiFiSSLClient client;
25-
UniversalTelegramBot bot(BOTtoken, client);
26-
27-
int Bot_mtbs = 1000; //mean time between scan messages
28-
long Bot_lasttime; //last time messages' scan has been done
23+
UniversalTelegramBot bot(BOT_TOKEN, client);
24+
unsigned long bot_lasttime; // last time messages' scan has been done
2925
int ledStatus = 0;
3026

31-
void handleNewMessages(int numNewMessages) {
27+
void handleNewMessages(int numNewMessages)
28+
{
3229
Serial.println("handleNewMessages");
3330
Serial.println(String(numNewMessages));
34-
for(int i=0; i<numNewMessages; i++) {
35-
String chat_id = String(bot.messages[i].chat_id);
31+
for (int i = 0; i < numNewMessages; i++)
32+
{
33+
String chat_id = bot.messages[i].chat_id;
3634
String text = bot.messages[i].text;
37-
if (text == "/ledon") {
38-
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
35+
if (text == "/ledon")
36+
{
37+
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
3938
ledStatus = 1;
4039
bot.sendMessage(chat_id, "Led is ON", "");
4140
}
42-
if (text == "/ledoff") {
41+
if (text == "/ledoff")
42+
{
4343
ledStatus = 0;
44-
digitalWrite(ledPin, LOW); // turn the LED off (LOW is the voltage level)
44+
digitalWrite(ledPin, LOW); // turn the LED off (LOW is the voltage level)
4545
bot.sendMessage(chat_id, "Led is OFF", "");
4646
}
47-
if (text == "/status") {
48-
if(ledStatus){
47+
if (text == "/status")
48+
{
49+
if (ledStatus)
50+
{
4951
bot.sendMessage(chat_id, "Led is ON", "");
50-
} else {
52+
}
53+
else
54+
{
5155
bot.sendMessage(chat_id, "Led is OFF", "");
5256
}
5357
}
54-
if (text == "/options") {
58+
if (text == "/options")
59+
{
5560
String keyboardJson = "[[\"/ledon\", \"/ledoff\"],[\"/status\"]]";
5661
bot.sendMessageWithReplyKeyboard(chat_id, "Choose from one of the following options", "", keyboardJson, true);
5762
}
5863

59-
if (text == "/start") {
64+
if (text == "/start")
65+
{
6066
String welcome = "Welcome from FlashLedBot, your personal Bot on Arduino 101\n";
6167
welcome = welcome + "/ledon : to switch the Led ON \n";
6268
welcome = welcome + "/ledoff : to switch the Led OFF \n";
@@ -67,41 +73,40 @@ void handleNewMessages(int numNewMessages) {
6773
}
6874
}
6975

70-
71-
void setup() {
76+
void setup()
77+
{
7278
Serial.begin(115200);
79+
Serial.println();
7380

74-
delay(100);
7581
// attempt to connect to Wifi network:
76-
Serial.print("Connecting Wifi: ");
77-
Serial.println(ssid);
78-
while (WiFi.begin(ssid, password) != WL_CONNECTED) {
82+
Serial.print("Connecting to Wifi SSID ");
83+
Serial.print(WIFI_SSID);
84+
while (WiFi.begin(WIFI_SSID, WIFI_PASSWORD) != WL_CONNECTED)
85+
{
7986
Serial.print(".");
8087
delay(500);
8188
}
82-
Serial.println("");
83-
Serial.println("WiFi connected");
84-
Serial.println("IP address: ");
85-
IPAddress ip = WiFi.localIP();
86-
Serial.println(ip);
89+
Serial.print("\nWiFi connected. IP address: ");
90+
Serial.println(WiFi.localIP());
8791

8892
pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
8993
delay(10);
9094
digitalWrite(ledPin, HIGH); // initialize pin as off
91-
9295
}
9396

94-
95-
96-
void loop() {
97-
98-
if (millis() > Bot_lasttime + Bot_mtbs) {
97+
void loop()
98+
{
99+
if (millis() - bot_lasttime > BOT_MTBS)
100+
{
99101
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
100-
while(numNewMessages) {
102+
103+
while (numNewMessages)
104+
{
101105
Serial.println("got response");
102106
handleNewMessages(numNewMessages);
103107
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
104108
}
105-
Bot_lasttime = millis();
109+
110+
bot_lasttime = millis();
106111
}
107112
}
File renamed without changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*******************************************************************
2+
* An example of bot that echos back any messages received *
3+
* using A101TelegramBot. *
4+
* *
5+
* written by Giacarlo Bacchio (Gianbacchio on Github) *
6+
* adapted by Brian Lough *
7+
*******************************************************************/
8+
9+
#include <WiFiSSLClient.h>
10+
#include <WiFi101.h>
11+
#include <UniversalTelegramBot.h>
12+
#include <SPI.h>
13+
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"
19+
20+
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
21+
22+
WiFiSSLClient client;
23+
UniversalTelegramBot bot(BOT_TOKEN, client);
24+
unsigned long bot_lasttime; // last time messages' scan has been done
25+
26+
void handleNewMessages(int numNewMessages)
27+
{
28+
for (int i = 0; i < numNewMessages; i++)
29+
{
30+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
31+
}
32+
}
33+
34+
void setup()
35+
{
36+
Serial.begin(115200);
37+
Serial.println();
38+
39+
// attempt to connect to Wifi network:
40+
Serial.print("Connecting to Wifi SSID ");
41+
Serial.print(WIFI_SSID);
42+
while (WiFi.begin(WIFI_SSID, WIFI_PASSWORD) != WL_CONNECTED)
43+
{
44+
Serial.print(".");
45+
delay(500);
46+
}
47+
Serial.print("\nWiFi connected. IP address: ");
48+
Serial.println(WiFi.localIP());
49+
}
50+
51+
void loop()
52+
{
53+
if (millis() - bot_lasttime > BOT_MTBS)
54+
{
55+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
56+
57+
while (numNewMessages)
58+
{
59+
Serial.println("got response");
60+
handleNewMessages(numNewMessages);
61+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
62+
}
63+
64+
bot_lasttime = millis();
65+
}
66+
}
File renamed without changes.

examples/UntestedSinceUpgrade/101/FlashledBot/FlashledBot.ino renamed to examples/Untested/101/FlashledBot/FlashledBot.ino

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,61 @@
66
* adapted by Brian Lough *
77
*******************************************************************/
88

9-
#include <WiFiSSLClient.h>
10-
#include <WiFi101.h>
11-
#include <UniversalTelegramBot.h>
9+
#include <WiFiSSLClient.h>
10+
#include <WiFi101.h>
11+
#include <UniversalTelegramBot.h>
12+
#include <SPI.h>
1213

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"
1319

14-
// Initialize Wifi connection to the router
15-
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxx"; // your network SSID (name)
16-
char password[] = "yyyyyyyy"; // your network key
17-
18-
19-
20-
const int ledPin = 13;
21-
22-
// Initialize Telegram BOT
23-
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
20+
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
2421

2522
WiFiSSLClient client;
26-
UniversalTelegramBot bot(BOTtoken, client);
23+
UniversalTelegramBot bot(BOT_TOKEN, client);
24+
unsigned long bot_lasttime; // last time messages' scan has been done
2725

28-
int Bot_mtbs = 1000; //mean time between scan messages
29-
long Bot_lasttime; //last time messages' scan has been done
26+
const int ledPin = 13;
3027
bool Start = false;
3128
int ledStatus = 0;
3229

33-
void handleNewMessages(int numNewMessages) {
34-
Serial.println("handleNewMessages");
35-
Serial.println(String(numNewMessages));
36-
for(int i=0; i<numNewMessages; i++) {
37-
String chat_id = String(bot.messages[i].chat_id);
30+
void handleNewMessages(int numNewMessages)
31+
{
32+
for (int i = 0; i < numNewMessages; i++)
33+
{
34+
String chat_id = bot.messages[i].chat_id;
3835
String text = bot.messages[i].text;
39-
if (text == "/ledon") {
40-
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
36+
if (text == "/ledon")
37+
{
38+
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
4139
ledStatus = 1;
4240
bot.sendMessage(chat_id, "Led is ON", "");
4341
}
44-
if (text == "/ledoff") {
42+
if (text == "/ledoff")
43+
{
4544
ledStatus = 0;
46-
digitalWrite(ledPin, LOW); // turn the LED off (LOW is the voltage level)
45+
digitalWrite(ledPin, LOW); // turn the LED off (LOW is the voltage level)
4746
bot.sendMessage(chat_id, "Led is OFF", "");
4847
}
49-
if (text == "/status") {
50-
if(ledStatus){
48+
if (text == "/status")
49+
{
50+
if (ledStatus)
51+
{
5152
bot.sendMessage(chat_id, "Led is ON", "");
52-
} else {
53+
}
54+
else
55+
{
5356
bot.sendMessage(chat_id, "Led is OFF", "");
5457
}
5558
}
56-
if (text == "/start") {
59+
if (text == "/start")
60+
{
5761
String from_name = bot.messages[i].from_name;
58-
if (from_name == "") from_name = "Anonymous";
62+
if (from_name == "")
63+
from_name = "Anonymous";
5964

6065
String welcome = "Welcome, " + from_name + ", from FlashLedBot, your personal Bot on Arduino 101\n";
6166
welcome = welcome + "/ledon : to switch the Led ON \n";
@@ -66,40 +71,40 @@ void handleNewMessages(int numNewMessages) {
6671
}
6772
}
6873

69-
70-
void setup() {
74+
void setup()
75+
{
7176
Serial.begin(115200);
72-
73-
delay(100);
77+
Serial.println();
7478

7579
// attempt to connect to Wifi network:
76-
Serial.print("Connecting Wifi: ");
77-
Serial.println(ssid);
78-
while (WiFi.begin(ssid, password) != WL_CONNECTED) {
80+
Serial.print("Connecting to Wifi SSID ");
81+
Serial.print(WIFI_SSID);
82+
while (WiFi.begin(WIFI_SSID, WIFI_PASSWORD) != WL_CONNECTED)
83+
{
7984
Serial.print(".");
8085
delay(500);
8186
}
82-
Serial.println("");
83-
Serial.println("WiFi connected");
84-
Serial.println("IP address: ");
85-
IPAddress ip = WiFi.localIP();
86-
Serial.println(ip);
87+
Serial.print("\nWiFi connected. IP address: ");
88+
Serial.println(WiFi.localIP());
8789

8890
pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
8991
delay(10);
9092
digitalWrite(ledPin, LOW); //initialize pin as off
91-
9293
}
9394

94-
void loop() {
95-
96-
if (millis() > Bot_lasttime + Bot_mtbs) {
95+
void loop()
96+
{
97+
if (millis() - bot_lasttime > BOT_MTBS)
98+
{
9799
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
98-
while(numNewMessages) {
100+
101+
while (numNewMessages)
102+
{
99103
Serial.println("got response");
100104
handleNewMessages(numNewMessages);
101105
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
102106
}
103-
Bot_lasttime = millis();
107+
108+
bot_lasttime = millis();
104109
}
105110
}
File renamed without changes.

0 commit comments

Comments
 (0)