Skip to content

Commit 915b054

Browse files
authored
ArduinoJson6 support + Send photo from serial
ArduinoJson6 support Sending photo from camera serial port (no SD card needed) is now supported
1 parent 198dfe7 commit 915b054

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ String UniversalTelegramBot::sendPostToTelegram(String command, JsonObject paylo
9494
String body = "";
9595
String headers = "";
9696
long now;
97-
bool responseReceived;
97+
bool responseReceived = false;
9898

9999
// Connect with api.telegram.org if not already connected
100100
if (!client->connected()) {
@@ -130,9 +130,8 @@ String UniversalTelegramBot::sendPostToTelegram(String command, JsonObject paylo
130130
client->println(out);
131131

132132
int ch_count = 0;
133-
char c;
133+
//char c;
134134
now = millis();
135-
responseReceived = false;
136135
bool finishedHeaders = false;
137136
bool currentLineIsBlank = true;
138137
while (millis() - now < waitForResponse) {
@@ -178,13 +177,17 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram(
178177
String command, String binaryProperyName, String fileName,
179178
String contentType, String chat_id, int fileSize,
180179
MoreDataAvailable moreDataAvailableCallback,
181-
GetNextByte getNextByteCallback, GetNextBuffer getNextBufferCallback,
180+
GetNextByte getNextByteCallback,
181+
GetNextBuffer getNextBufferCallback,
182182
GetNextBufferLen getNextBufferLenCallback) {
183183

184184
String body = "";
185185
String headers = "";
186186
long now;
187-
bool responseReceived;
187+
bool responseReceived = false;
188+
bool finishedHeaders = false;
189+
bool currentLineIsBlank = true;
190+
188191
String boundry = F("------------------------b8f610217e83e29b");
189192

190193
// Connect with api.telegram.org if not already connected
@@ -278,12 +281,11 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram(
278281
if (_debug)
279282
Serial.print("End request: " + end_request);
280283

281-
int count = 0;
284+
//int count = 0;
282285
int ch_count = 0;
283-
char c;
286+
//char c;
284287
now = millis();
285-
bool finishedHeaders = false;
286-
bool currentLineIsBlank = true;
288+
287289
while (millis() - now < waitForResponse) {
288290
while (client->available()) {
289291
char c = client->read();
@@ -532,7 +534,7 @@ bool UniversalTelegramBot::sendSimpleMessage(String chat_id, String text,
532534

533535
bool sent = false;
534536
if (_debug)
535-
Serial.println(F("SEND Simple Message"));
537+
Serial.println(F("sendSimpleMessage: SEND Simple Message"));
536538
long sttime = millis();
537539

538540
if (text != "") {
@@ -654,7 +656,7 @@ bool UniversalTelegramBot::sendPostMessage(JsonObject payload) {
654656

655657
bool sent = false;
656658
if (_debug){
657-
Serial.print(F("SEND Post Message: "));
659+
Serial.print(F("sendPostMessage: SEND Post Message: "));
658660
serializeJson(payload, Serial);
659661
Serial.println();
660662
}
@@ -682,7 +684,7 @@ String UniversalTelegramBot::sendPostPhoto(JsonObject payload) {
682684
bool sent = false;
683685
String response = "";
684686
if (_debug)
685-
Serial.println(F("SEND Post Photo"));
687+
Serial.println(F("sendPostPhoto: SEND Post Photo"));
686688
long sttime = millis();
687689

688690
if (payload.containsKey("photo")) {
@@ -708,7 +710,7 @@ String UniversalTelegramBot::sendPhotoByBinary(
708710
GetNextByte getNextByteCallback, GetNextBuffer getNextBufferCallback, GetNextBufferLen getNextBufferLenCallback) {
709711

710712
if (_debug)
711-
Serial.println("SEND Photo");
713+
Serial.println(F("sendPhotoByBinary: SEND Photo"));
712714

713715
String response = sendMultipartFormDataToTelegram("sendPhoto", "photo", "img.jpg",
714716
contentType, chat_id, fileSize,

src/UniversalTelegramBot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class UniversalTelegramBot {
109109
String userName;
110110
int longPoll = 0;
111111
bool _debug = false;
112-
int waitForResponse = 1500;
112+
int waitForResponse = 3000;
113113

114114
private:
115115
// JsonObject * parseUpdates(String response);

0 commit comments

Comments
 (0)