Skip to content

Commit 606424f

Browse files
committed
Small changes in news examples.
1 parent 0716d9e commit 606424f

File tree

4 files changed

+40
-45
lines changed

4 files changed

+40
-45
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ env:
1515
- SCRIPT=platformioSingle EXAMPLE_NAME=FlashledBot EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
1616
- SCRIPT=platformioSingle EXAMPLE_NAME=UsingWiFiManager EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
1717
- SCRIPT=platformioSingle EXAMPLE_NAME=BulkMessages EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
18-
- SCRIPT=platformioSingle EXAMPLE_NAME=ImageFromSD EXAMPLE_FOLDER=/SendPhoto/ EXAMPLE_NAME=ImageFromSD BOARDTYPE=ESP8266 BOARD=d1_mini
19-
- SCRIPT=platformioSingle EXAMPLE_NAME=ImageFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
20-
- SCRIPT=platformioSingle EXAMPLE_NAME=ImageFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
18+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSD EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
19+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
20+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromFileID EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
2121

2222

2323
install:

examples/ESP8266/SendPhoto/ImageFromFileId/ImageFromFileId.ino renamed to examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ void handleNewMessages(int numNewMessages) {
4141

4242
if (text == "/start") {
4343
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
44-
welcome += "This is Send Photo From File Id example.\n\n";
44+
welcome += "This is Send Photo From File ID example.\n\n";
4545
welcome += "/get_test_photo : getting test photo\n";
46-
//welcome += "You will receive photo from " + test_photo_url + "\n";
4746

4847
bot.sendMessage(chat_id, welcome, "");
4948
}

examples/ESP8266/SendPhoto/ImageFromSD/ImageFromSD.ino renamed to examples/ESP8266/SendPhoto/PhotoFromSD/PhotoFromSD.ino

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@
44
* written by Giacarlo Bacchio (Gianbacchio on Github) *
55
* adapted by Brian Lough *
66
*******************************************************************/
7-
87
#include <ESP8266WiFi.h>
98
#include <WiFiClientSecure.h>
109
#include <UniversalTelegramBot.h>
1110
#include <ArduinoJson.h>
12-
1311
#include <SPI.h>
1412
#include <SD.h>
1513

16-
bool isMoreDataAvailable();
17-
byte getNextByte();
18-
1914
// Initialize Wifi connection to the router
20-
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxx"; // your network SSID (name)
21-
char password[] = "yyyyyyyy"; // your network key
22-
23-
File myFile;
15+
char ssid[] = "XXXXXX"; // your network SSID (name)
16+
char password[] = "YYYYYY"; // your network key
2417

2518
// Initialize Telegram BOT
2619
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
@@ -31,83 +24,87 @@ UniversalTelegramBot bot(BOTtoken, client);
3124
int Bot_mtbs = 1000; //mean time between scan messages
3225
long Bot_lasttime; //last time messages' scan has been done
3326

27+
File myFile;
28+
bool isMoreDataAvailable();
29+
byte getNextByte();
3430

3531
void setup() {
36-
3732
Serial.begin(115200);
3833

39-
Serial.print("Initializing SD card...");
34+
Serial.print("Initializing SD card....");
4035

4136
if (!SD.begin(D0)) {
42-
Serial.println("initialization failed!");
37+
Serial.println("failed!");
4338
return;
4439
}
45-
Serial.println("initialization done.");
4640

41+
Serial.println("done.");
4742

48-
// Set WiFi to station mode and disconnect from an AP if it was Previously
49-
// connected
43+
// Set WiFi to station mode and disconnect from an AP if it was Previously connected
5044
WiFi.mode(WIFI_STA);
5145
WiFi.disconnect();
5246
delay(100);
5347

54-
// Attempt to connect to Wifi network:
48+
// attempt to connect to Wifi network:
5549
Serial.print("Connecting Wifi: ");
5650
Serial.println(ssid);
5751
WiFi.begin(ssid, password);
52+
5853
while (WiFi.status() != WL_CONNECTED) {
5954
Serial.print(".");
6055
delay(500);
6156
}
57+
6258
Serial.println("");
6359
Serial.println("WiFi connected");
64-
Serial.println("IP address: ");
65-
IPAddress ip = WiFi.localIP();
66-
Serial.println(ip);
67-
68-
69-
}
70-
71-
bool isMoreDataAvailable(){
72-
return myFile.available();
73-
}
74-
75-
byte getNextByte(){
76-
return myFile.read();
60+
Serial.print("IP address: ");
61+
Serial.println(WiFi.localIP());
7762
}
7863

7964
void loop() {
80-
8165
if (millis() > Bot_lasttime + Bot_mtbs) {
8266
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
67+
8368
while(numNewMessages) {
8469
Serial.println("got response");
8570

86-
8771
String chat_id = bot.messages[0].chat_id;
72+
String file_name = "box.jpg";
73+
74+
myFile = SD.open(file_name);
8875

89-
myFile = SD.open("box.jpg");
9076
if (myFile) {
91-
Serial.println("box.jpg:");
77+
Serial.print(file_name);
78+
Serial.print("....");
9279

9380
//Content type for PNG image/png
9481
bool sent = bot.sendPhotoByBinary(chat_id, "image/jpeg", myFile.size(),
9582
isMoreDataAvailable,
9683
getNextByte);
9784

98-
if(sent){
99-
Serial.println("Succesfully sent photo");
85+
if (sent) {
86+
Serial.println("was successfully sent");
10087
} else {
101-
Serial.println("Error sending photo");
88+
Serial.println("was not sent");
10289
}
10390

10491
myFile.close();
105-
} else {
106-
// if the file didn't open, print an error:
107-
Serial.println("error opening photo.jpg");
92+
} else {
93+
// if the file didn't open, print an error:
94+
Serial.println("error opening photo");
10895
}
96+
10997
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
11098
}
99+
111100
Bot_lasttime = millis();
112101
}
113102
}
103+
104+
bool isMoreDataAvailable(){
105+
return myFile.available();
106+
}
107+
108+
byte getNextByte(){
109+
return myFile.read();
110+
}

examples/ESP8266/SendPhoto/ImageFromURL/ImageFromURL.ino renamed to examples/ESP8266/SendPhoto/PhotoFromURL/PhotoFromURL.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ void handleNewMessages(int numNewMessages) {
4242
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
4343
welcome += "This is Send Image From URL example.\n\n";
4444
welcome += "/get_test_photo : getting test photo\n";
45-
//welcome += "You will receive photo from " + test_photo_url + "\n";
4645

4746
bot.sendMessage(chat_id, welcome, "");
4847
}

0 commit comments

Comments
 (0)