Skip to content
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

Use this to send a file update from device A to B #103

Open
RosiersRobin opened this issue Dec 6, 2022 · 2 comments
Open

Use this to send a file update from device A to B #103

RosiersRobin opened this issue Dec 6, 2022 · 2 comments

Comments

@RosiersRobin
Copy link

RosiersRobin commented Dec 6, 2022

Hi,

I've tried to use this package to update an second ESP32, atached to the UART1 (Serial1).

So my use-case is the following:

  • 2 ESP's, connected to eachother via UART1.
  • 1 has internet using a LAN-chip and thus connected via wire. The other one is not Wi-Fi capable, so I can't update using wifi, since the device can change location any time.

I want to download the firmware for te second, non internet connected eps32, onto the ethernet connected one. This works as intended.

After that download, I want to send/stream the downloaded file to the other ESP, that does not have internet and after the file got streamed, flash it to the ESP.

What I currently have:

Sender

File readFile = LittleFS.open("/newFirmware.bin");

uint8_t buf[1025] = {};
size_t _len = 256;

serialTransferClient.begin(Serial1);

serialTransferClient.sendDatum("newFirmware.bin"); // Send filename

uint16_t fileSize = readFile.size();

uint16_t numPackets = fileSize / (MAX_PACKET_SIZE - 2); // Reserve two bytes for current file index

// Add an extra transmission if needed
if (fileSize % MAX_PACKET_SIZE) {
       numPackets++;
}

// Send all data within the file across multiple packets
for (uint16_t i = 0; i < numPackets; i++) {

    int len = readFile.read(buf, _len);

    uint16_t fileIndex = i * MAX_PACKET_SIZE; // Determine the current file index
    uint8_t dataLen = MAX_PACKET_SIZE - 2;

    // Determine data length for the last packet if file length is not an exact multiple of MAX_PACKET_SIZE-2
    if ((fileIndex + (MAX_PACKET_SIZE - 2)) > fileSize) {
        dataLen = fileSize - fileIndex;
    }

    uint8_t sendSize = serialTransferClient.txObj(fileIndex); // Stuff the current file index
    sendSize = serialTransferClient.txObj(buf[fileIndex], sendSize, dataLen); // Stuff the current file data

    serialTransferClient.sendData(sendSize, 1); // Send the current file index and data
    delay(100);
}

Receiver:

serialTransferClient.begin(Serial1);

while (serialTransferClient.available() && !finished) {
    if (serialTransferClient.available()) {
        if (!serialTransferClient.currentPacketID()) {
            serialTransferClient.rxObj("newFirmware.bin");
        } else if (serialTransferClient.currentPacketID() == 1) {
            for (uint8_t i = 2; i < serialTransferClient.bytesRead; i++) {
                // Serial.print((char)serialTransferClient.packet.rxBuff[i]);
                Update.write(serialTransferClient.packet.rxBuff[i], l); // this does not work either...
            }
        }
    }

    lastTime = millis();
}

Any help would be really appriciated!

@cyberdevnet
Copy link

@RosiersRobin did you manage to update one esp32 from another? It's exactly what I'm trying to do...not too much info over the internet

@RosiersRobin
Copy link
Author

@cyberdevnet I did, however not by using this package, but by transferring 64bytes each chunk. So I don't have to do specific calculations and buffering. There is room for optimizing this, but I haven't had the time yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants