witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.09k stars 302 forks source link

my bot.sendPhotoByBinary Not Working similar to #68 #287

Open aarondvail opened 2 years ago

aarondvail commented 2 years ago

Serial.println("was successfully sent"); is called but nothing is sent to telegram.

I've put my telegram code within a function (see below)

void sendTelegramPhoto(String file_name){

String path = "/" + file_name +""; myFile = SD_MMC.open(path); telegramBot.sendMessage(CHAT_ID, "Starting send of photo", ""); if (myFile) { Serial.print(file_name); Serial.print("....");

//Content type for PNG image/png
String sent = telegramBot.sendPhotoByBinary(CHAT_ID, "image/jpeg", myFile.size(), isMoreDataAvailable, getNextByte, nullptr, nullptr);

if (sent)
{
  Serial.println("was successfully sent");
}
else
{
  Serial.println("was not sent");
}

myFile.close();

} else { // if the file didn't open, print an error: Serial.println("error opening photo"); } telegramBot.sendMessage(CHAT_ID, "Ending send of photo", "");

}

Serial Monitor results : 00:03:53.050 -> 2022-06-10-000348-Cam05.jpg....was successfully sent

Telegram Results : Bot, [6/10/2022 12:03 AM] Starting send of photo

 Bot, [6/10/2022 12:04 AM]
 Ending send of photo

68 eluded to using the 1.2 version, I can only find 1.3 and 1.1, and 1.1 wouldn't compile. It's getting late and I'm open to suggestions.

aarondvail commented 2 years ago

I think I may have identified my problem.... some where else I saw someone was sending a 64 by 64 px image (or something like that... my buffer (and the saved file) is 1600 by 1200 px... a lot bigger...

So what I'm trying to figure out now to prove this hypothesis is correct is to scale the buffer into a lot smaller image file, but not resize the buffer, as I still want the 1600 by 1200 image...

Here's my savePhoto function

`String savePhoto() { String getAll; String getBody; String fullFilename = timeToFilename(1); String fullFilename_thumb = timeToFilename(2); Serial.println(fullFilename);

// Get picture into buffer camera_fb_t * fb = NULL; fb = esp_camera_fb_get(); if(!fb) { Serial.println("Camera capture failed"); delay(15000); ESP.restart(); // try again maybe //return; } // make the file // initialize EEPROM with predefined size //EEPROM.begin(EEPROM_SIZE); //pictureNumber = EEPROM.read(0) + 1;

// Path where new picture will be saved in SD Card

fs::FS &fs = SD_MMC;

String path = "/" + fullFilename +""; Serial.printf("Picture file name: %s\n", path.c_str()); File file = fs.open(path.c_str(), FILE_WRITE); if(!file){ Serial.println("Failed to open file in writing mode"); } else { file.write(fb->buf, fb->len); // payload (image), payload length Serial.printf("Saved file to path: %s\n", path.c_str()); // EEPROM.write(0, pictureNumber); // EEPROM.commit(); } file.close();

String path_thumb = "/" + fullFilename_thumb +""; Serial.printf("Picture file name: %s\n", path_thumb.c_str()); File file_thumb = fs.open(path_thumb.c_str(), FILE_WRITE); if(!file_thumb){ Serial.println("Failed to open file in writing mode"); } else { file_thumb.write(fb->buf, fb->len); // payload (image), payload length Serial.printf("Saved file to path: %s\n", path_thumb.c_str()); // EEPROM.write(0, pictureNumber); // EEPROM.commit(); } file_thumb.close(); esp_camera_fb_return(fb); //makeThumbnail(fullFilename); sendTelegramPhoto(fullFilename_thumb);

// Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4 //pinMode(4, OUTPUT); BAD CODE, KILLS SD CARD //digitalWrite(4, LOW); BAD CODE, KILLS SD CARD //rtc_gpio_hold_en(GPIO_NUM_4); BAD CODE, KILLS SD CARD } `

but.... I'm stuck again