Ymodem ESP32 1.0.0
Loading...
Searching...
No Matches
ReceiveExample.cpp File Reference

Example code to receive a file using Ymodem protocol. More...

#include "YmodemCore.h"
#include <Arduino.h>
#include <HardwareSerial.h>
#include <SPIFFS.h>
#include <Update.h>
+ Include dependency graph for ReceiveExample.cpp:

Go to the source code of this file.

Macros

#define CONFIG_SPIFFS_SIZE   (2 * 1024 * 1024)
 
#define MAX_FILE_SIZE   (CONFIG_SPIFFS_SIZE - 0x2000)
 
#define FIRMWARE_UPDATE
 

Functions

void setup ()
 Setup function to initialize Serial, SPIFFS, and UART for YModem file reception.
 
void loop ()
 Main loop function for receiving and updating firmware via YModem protocol.
 

Variables

Ymodem ymodem
 

Detailed Description

Example code to receive a file using Ymodem protocol.

Version
0.1
Date
2025-01-24

This code is an example of how to use the Ymodem library to receive a file using the Ymodem protocol. The file is received through the Serial1 port and saved to the SPIFFS filesystem.

Definition in file ReceiveExample.cpp.

Macro Definition Documentation

◆ CONFIG_SPIFFS_SIZE

#define CONFIG_SPIFFS_SIZE   (2 * 1024 * 1024)

SPIFFS size in bytes

Definition at line 19 of file ReceiveExample.cpp.

◆ FIRMWARE_UPDATE

#define FIRMWARE_UPDATE

Uncomment this line to enable firmware update

Definition at line 21 of file ReceiveExample.cpp.

◆ MAX_FILE_SIZE

#define MAX_FILE_SIZE   (CONFIG_SPIFFS_SIZE - 0x2000)

Maximum file size

Definition at line 20 of file ReceiveExample.cpp.

Function Documentation

◆ loop()

void loop ( )

Main loop function for receiving and updating firmware via YModem protocol.

This function performs the following steps:

  1. Calculates the maximum file size that can be received based on the available space in SPIFFS.
  2. Opens a file in SPIFFS to store the received firmware.
  3. Initiates the YModem file reception and stores the received data in the opened file.
  4. If the file reception is successful, it proceeds to perform an OTA update with the received binary.
  5. If the OTA update is successful, it restarts the ESP32.
  6. Handles various error conditions such as file opening failures, transfer errors, and OTA update errors.
Note
The function uses the SPIFFS filesystem and the Update library for OTA updates.
The function assumes that the YModem library is properly initialized and configured.

Definition at line 79 of file ReceiveExample.cpp.

◆ setup()

void setup ( )

Setup function to initialize Serial, SPIFFS, and UART for YModem file reception.

This function performs the following tasks:

  • Initializes the Serial interface for debugging with a baud rate of 115200.
  • Waits until the Serial interface is ready.
  • Initializes the SPIFFS (SPI Flash File System) and checks for successful mounting.
  • Configures the YModem activity LED pin and sets its initial state.
  • Initializes the UART (Serial1) interface with a baud rate of 115200 and specified RX/TX pins.
  • Logs a setup complete message indicating readiness to receive files.

Definition at line 36 of file ReceiveExample.cpp.

Variable Documentation

◆ ymodem

Ymodem ymodem

Ymodem instance

Definition at line 23 of file ReceiveExample.cpp.