-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jpg photo Serial transmit (again!!!) doesn't work #116
Comments
Here is the receiver: ` about serial2 for CYD: witnessmenow/ESP32-Cheap-Yellow-Display#75 the RGB led pins are used for RS485 connexion: */ // parameters // =========================== // wifi // TFT display //#include <LovyanGFX.hpp> byte chosenTextFont = 0; // 0 or 2 or 4 int16_t dw = 320; // sd card part // pinup // file transfer #define BAUD_RATE 200000 char imageBuffer[5000]; // void setup() { // console // RS485 // TFT display TL_DATUM = 0 = Top left L_BASELINE = 9 = Left character baseline (Line the 'A' character would sit on) tft.setSwapBytes(true); TJpgDec.setJpgScale(1); // The jpeg image can be scaled by a factor of 1, 2, 4, or 8 dw = tft.width(); // start sd card: must be placed AFTER tft and ts setup } // end of setup // void loop() { if(myTransfer.available()) { if((tempo > (memoTempo + 1000)) && (loopCount > 0)) {
// save to sdcard // read picture from sdcard
*/ //============================================================================================ // bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) { if( y >= tft.height()) return 0; // Stop further decoding as image is running off bottom of screen // void ListDir(fs::FS &fs, const char *dirname, uint8_t levels) { File root = fs.open(dirname); File file = root.openNextFile(); void ReadFile(fs::FS &fs, const char *path) { File file = fs.open(path); Serial.print(F("Read from file: ")); void WriteFile(fs::FS &fs, const char *path, const char *message) { File file = fs.open(path, FILE_WRITE); void AppendFile(fs::FS &fs, const char *path, const char *message) { File file = fs.open(path, FILE_APPEND); void RenameFile(fs::FS &fs, const char * path1, const char * path2) { void DeleteFile(fs::FS &fs, const char * path) { void CopyFile(fs::FS &fs1, const char * path1, fs::FS &fs2, const char * path2) { size_t n; ` |
I cannot receive a viewable jpg photo. However if I rename the pic.jpg as pic.txt it looks like a jpg file. I guess here is the problem |
Hi, many thanks for this library and your contribution. There was several threads about transmitting a picture,... I'm trying to get it working with the last library version.
The project is building a camera door bell.
The camera is a ESP32-CAM, the receiver is a Cheap Yellow Display ESP32.
Here is the code for the sender:
`
/*
ESP32-CAM takes photos to save on SPIFFS, and with serial transfert / RS485 wire transfer
From an idea of: http://electroniqueamateur.blogspot.com/2020/07/esp32-cam-gestion-distance-de-la-carte.html
https://gist.github.com/ypelletier/e47f4df32745fbdd7bc6799a42979ba3
RS485 exemple: https://microcontrollerslab.com/rs485-serial-communication-esp32-esp8266-tutorial/
about file transfer: https://github.com/PowerBroker2/SerialTransfer/tree/master
discussion: https://forum.arduino.cc/t/transfer-pictures-from-esp32-cam-to-esp32-via-serial/647488
!!! file transfer v3.1.3 only
IDE version 1.8.16 with Expressif Sytems (ESP32) version 2.0.3
*/
//#define SAVE2SPIFFS // to save photo to SPIFFS
// ===========================
// Enter your WiFi credentials
// ===========================
const char* ssid = "xxxxxx";
const char* password = "yyyyyy";
// wifi
//-------
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
WebServer server(80);
// SDCard
//---------
#include <SPIFFS.h>
#include <FS.h>
// to keep data
//-------------
#include <Preferences.h> // https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/
Preferences pref;
// camera
//----------------
#include "esp_camera.h"
#include "Arduino.h"
#include "soc/soc.h" // Disable brownour problems
#include "soc/rtc_cntl_reg.h" // Disable brownour problems
// file transfer
//----------------
#include "SerialTransfer.h" // https://github.com/PowerBroker2/SerialTransfer/tree/master
SerialTransfer myTransfer;
HardwareSerial Comm(1);
// RS485
//----------------
// note: 2nd Serial with Tx = 15, Rx = 14 to MAX485 Rx & Tx pins
#define REpin 15 // MAX485 RE/DE pins 2 & 3
#define TXpin 14 // MAX485 RO pin 4
#define RXpin 13 // MAX485 DI pin 1
#define RS485Transmit HIGH
#define RS485Receive LOW
#define BAUD_RATE 200000 //962100
#define flashPin 4 // white flash led
#define ledPin 33 // red led
int fileNumber = 0; // jpeg file name index number
//
// SETUP
//_____________________________________________________________________________________________
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
// Console
Serial.begin(115200); // Define and start serial monitor
delay(1000);
Serial.println(F("starting..."));
// RS485 Serial communication
Comm.begin(BAUD_RATE, SERIAL_8N1, RXpin, TXpin); // Define and start Comm serial port
myTransfer.begin(Comm);
pinMode(REpin, OUTPUT);
digitalWrite(REpin, LOW);
// camera setup - AI Thinker - ESP32-CAM pins definition
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = 5;
config.pin_d1 = 18;
config.pin_d2 = 19;
config.pin_d3 = 21;
config.pin_d4 = 36;
config.pin_d5 = 39;
config.pin_d6 = 34;
config.pin_d7 = 35;
config.pin_xclk = 0;
config.pin_pclk = 22;
config.pin_vsync = 25;
config.pin_href = 23;
config.pin_sscb_sda = 26;
config.pin_sscb_scl = 27;
config.pin_pwdn = 32;
config.pin_reset = -1;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG; // YUV422|GRAYSCALE|RGB565|JPEG
config.frame_size = FRAMESIZE_QVGA;
/* UXGA(1600x1200)
SXGA(1280x1024)
XGA(1024x768)
SVGA(800x600)
VGA(640x480)
CIF(400x296)
QVGA(320x240)
HQVGA(240x176)
QQVGA(160x120)
*/
config.jpeg_quality = 12; // 10-63 ; plus bas = meilleure qualité
config.fb_count = 1; // nombre de frame buffers
esp_err_t err = esp_camera_init(&config);
if(err != ESP_OK) {
Serial.printf("Camera error 0x%x", err);
return;
}
sensor_t * s = esp_camera_sensor_get();
// wifi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED) delay(500);
Serial.print(F("IP address: ")); Serial.println(WiFi.localIP());
// web server
server.on("/delete", HTTP_GET, handleDelete);
server.on("/clic", HTTP_GET, handleSave);
server.onNotFound(handleNotFound);
server.begin();
Serial.println(F("Web server started."));
// SPIFFS init
//if(SPIFFS.format()) Serial.println(F("SPIFFS erased successfully."));
if(SPIFFS.begin(true)) Serial.println(F("SPIFFS OK"));
else Serial.println(F("SPIFFS error!"));
// get photo index number
pref.begin("parameters", false);
fileNumber = pref.getUInt("num", 0);
} // end of setup
//
// LOOP
//_____________________________________________________________________________________________
void loop() {
server.handleClient();
}
//============================================================================================
// list of functions
//============================================================================================
//
// html Save - Take a photo and save it to SDCard
//____________________________________________________________________________________________
void handleSave(void) {
camera_fb_t * fb = NULL; // frame buffer
fb = esp_camera_fb_get(); // prise de la photo
if(!fb) {
Serial.println("Failed to take a photo.");
return;
}
uint16_t fbSize = fb->len; // keep size of fb
uint8_t *fbFile = fb->buf; // keep picture frame in file
// save photo to SPIFFS
#ifdef SAVE2SPIFFS
char fileName[20] = ""; // picture file name .jpg
sprintf(fileName, "/%d.jpg", fileNumber++); // file name creation
pref.putUInt("num", fileNumber); // keep the file index number
if(SPIFFS.exists(fileName)) SPIFFS.remove(fileName);
File file = SPIFFS.open(fileName, FILE_WRITE);
if(!file) Serial.println("SPIFFS error!");
else {
//file.write(fb->buf, fb->len);
file.write(fbFile, fbSize);
Serial.printf("Photo saved: %s", fileName);
Serial.print(F(" size= ")); Serial.println(fbSize);
}
file.close();
#endif
// photo file serial transfer
// 1- transfer mode & send fbSize
digitalWrite(REpin, RS485Transmit); // RS485 transmit mode
myTransfer.sendDatum(fbSize); // Send fbSize
// 2- define number of packets to transmit
uint8_t dataLen = MAX_PACKET_SIZE -2; // Reserve two bytes for current file index
uint16_t numPackets = fbSize / dataLen; // the number of packets
if(fbSize % MAX_PACKET_SIZE) numPackets++; // Add an extra transmission if needed
// 3- send all data within the file across multiple packets
for(uint16_t i=0; i<numPackets; i++) { // Send all data within the file across multiple packets
uint16_t fileIndex = i * MAX_PACKET_SIZE; // Determine the current file index
// 4- send packets
uint8_t sendSize = myTransfer.txObj(fileIndex); // Stuff the current file index
sendSize = myTransfer.txObj(fbFile[fileIndex], sendSize, dataLen); // Stuff the current file data
myTransfer.sendData(sendSize, 1); // Send the current file index and data
} // end of for
esp_camera_fb_return(fb);
digitalWrite(REpin, RS485Receive); // RS485 stop transmit mode
// web message
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/html", "");
WiFiClient client = server.client();
server.sendContent("
Une nouvelle photo a été prise.
");server.sendContent("
Retour à la liste des fichiers
");} // end of handleSave()
//
// LoadFromSPIFFS() - operations on sdcard
//____________________________________________________________________________________________
bool LoadFromSPIFFS(String path) {
String dataType = "text/plain";
if(path == "/") PrintDirectory();
else {
if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
else if(path.endsWith(".htm")) dataType = "text/html";
else if(path.endsWith(".css")) dataType = "text/css";
else if(path.endsWith(".js")) dataType = "application/javascript";
else if(path.endsWith(".png")) dataType = "image/png";
else if(path.endsWith(".gif")) dataType = "image/gif";
else if(path.endsWith(".jpg")) dataType = "image/jpeg";
else if(path.endsWith(".ico")) dataType = "image/x-icon";
else if(path.endsWith(".xml")) dataType = "text/xml";
else if(path.endsWith(".pdf")) dataType = "application/pdf";
else if(path.endsWith(".zip")) dataType = "application/zip";
}
return true;
} // end of LoadFromSPIFFS()
//
// PrintDirectory()
//____________________________________________________________________________________________
void PrintDirectory() {
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/html", "");
WiFiClient client = server.client();
server.sendContent("
Prise de photo
");server.sendContent("
");
server.sendContent("
Contenu de la carte SD
");File dir = SPIFFS.open("/");
File entry = dir.openNextFile();
while(entry) {
Serial.print(F("\tFILE: ")); Serial.print(entry.name());
Serial.print(F("\tSIZE: ")); Serial.println(entry.size());
String output = " ";
output += entry.name();
// add a delete button
output += " <a href = /delete?url=";
output += entry.name();
output += "> [Supprimer]
";
server.sendContent(output);
entry = dir.openNextFile();
}
dir.close();
} // end of PrintDirectory()
//
// html Delete
//____________________________________________________________________________________________
void handleDelete() {
if(server.args() == 0) {
returnFail("Mauvais arguments?");
return;
}
String path = "/" + server.arg(0);
Serial.print(F("deleting: ")); Serial.println(path);
//SPIFFS.remove((char *)path.c_str());
SPIFFS.remove(path);
// delete confirmation
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/html", "");
WiFiClient client = server.client();
server.sendContent("
Le fichier a été supprimé
");server.sendContent("
Retour à la liste des fichiers
");} // end of handleDelete()
//
// html display
//____________________________________________________________________________________________
void handleNotFound() {
if(LoadFromSPIFFS(server.uri())) return;
String message = "Action imprevue\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for(uint8_t i = 0; i < server.args(); i++) {
message += " NAME:" + server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
Serial.print(message);
} // end of handleNotFound()
void returnOK() {
server.send(200, "text/plain", "");
}
void returnFail(String msg) {
server.send(500, "text/plain", msg + "\r\n");
}
`
The text was updated successfully, but these errors were encountered: