Ymodem ESP32 1.0.0
Loading...
Searching...
No Matches
TransmitExample.cpp
Go to the documentation of this file.
1
15#include "YmodemCore.h"
16#include <Arduino.h>
17#include <HardwareSerial.h>
18#include <SPIFFS.h>
19
20#define CONFIG_SPIFFS_SIZE (2 * 1024 * 1024)
21#define MAX_FILE_SIZE (CONFIG_SPIFFS_SIZE - 0x2000)
36void setup()
37{
38
39 Serial.begin(115200);
40 while (!Serial) {
41 ; // wait for serial port to connect. Needed for native USB port only
42 }
43
44 if (!SPIFFS.begin(true)) {
45 Serial.println("Error mounting SPIFFS");
46 return;
47 }
48
49 // Configure the Ymodem activity LED pin
50 pinMode(YMODEM_LED_ACT, OUTPUT);
51 digitalWrite(YMODEM_LED_ACT, YMODEM_LED_ACT_ON ^ 1);
52
53 // configure serial communication for Ymodem transfer
54 Serial1.begin(115200, SERIAL_8N1, 16, 17); // RX, TX pins
55 if (!Serial1) {
56 Serial.println("Error initialazing Serial port");
57 return;
58 }
59
60 // setup finish message
61 log_d("Setup completed, ready ro send data");
62}
63
75void loop()
76{
77 // Open file saved in SPIFFS to transmit
78 File ffd = SPIFFS.open("/firmware-1.bin", FILE_READ);
79 if (!ffd) {
80 log_e("Error reading file form SPIFFS");
81 return;
82 }
83
84 // Transmit the file to the receiver
85 int result = ymodem.transmit((char*)"firmware-1.bin", ffd.size(), ffd);
86 ffd.close();
87
88 if (result == 0) {
89 log_i("Send successfully done");
90 }
91 else {
92 log_e("Error sending file. Error code %d\n", result);
93 }
94 delay(10);
95}
void setup()
Initial system configuration.
Ymodem ymodem
void loop()
Main loop function that handles the transmission of a firmware file using Ymodem protocol.
Ymodem core functions.
#define YMODEM_LED_ACT_ON
Definition YmodemDef.h:24
#define YMODEM_LED_ACT
Definition YmodemDef.h:23
Ymodem class.
Definition YmodemCore.h:30
int transmit(char *sendFileName, unsigned int sizeFile, fs::File &ffd)
Transmits a file using the Ymodem protocol.