8000 OTA firmware update · Issue #5 · pycom/pycom-micropython-sigfox · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

OTA firmware update #5

Closed
jmarcelino opened this issue Apr 5, 2017 · 16 comments
Closed

OTA firmware update #5

jmarcelino opened this issue Apr 5, 2017 · 16 comments

Comments

@jmarcelino
Copy link
jmarcelino commented Apr 5, 2017

I was trying out the over-the-air (OTA) firmware update functionality and after a small tweak was surprised I could actually:

  1. Build a new image
  2. Upload the newly built appimg.bin to /flash/sys/appimg.bin using FTP
  3. New OTA image was picked up and everything worked on reboot!

The only change I made was setting

#define IMG_SIZE (1536 * 1024)

in pycom-micropython-sigfox/esp32/bootloader/bootloader.h

(the 1536K is the actual size of the image, the old value 1024 overwrote the running code on SPI and cause very bad results)

I understand the size of the images and maybe the bootloader may not be fixed in stone yet but maybe this could work within minor versions?

@Mungio
Copy link
Mungio commented Apr 5, 2017

I'm sorry for the lack of experience, but which tool of this repository I must use to create the appimg.bin?

Thx.

@jmarcelino
Copy link
Author

@Mungio
You need to setup the build environment first, see the "The ESP32 version" section in this repo's https://github.com/pycom/pycom-micropython-sigfox README up to the "To build and flash" instructions

Then follow the README in the esp32 folder https://github.com/pycom/pycom-micropython-sigfox/tree/master/esp32

The appimg.bin will be in the build/ folder.

You will need to flash a version with the change above first via the usual GND-G23 method before the FTP will work!

If you need help with these steps it's best to post in the forum. Many other members building custom images already.

@Mungio
Copy link
Mungio commented May 11, 2017

Hi, unfortunately this change doesn't work.

  1. I built a new image with the bootloader edited;
  2. I flashed this custom image using make BOARD=WIPY flash and everything work.
  3. I create a new image and copy the appimg.bin file in /flash/sys/ using Filezilla.
  4. I reset the WiPy
  5. The firmware and the app do not change

In other words OTA does not work

@nevercast
Copy link

Did you flash this custom image manually first, and then try OTA @Mungio ? You need to make the bootloader change and flash normally first.

@danicampora
Copy link

This is now fixed with: dd8a992

It required @jmarcelino tweak plus a few other fixes inside bootloader.c and updater.c

@Mungio and @jmarcelino could you please try again and report back? :-)

@robert-hh
Copy link
Contributor

It seems to work, even if it failed on the first attempt. the only confusing thing is that on uploading the file ftp only once reported 226, which is OK, but most of the time 426, which is an error code. Nevertheless, the new code seems to be active. At least the embedded updated python scripts changed.

@danicampora
Copy link

@robert-hh which FTP client are you using? 426 is transfer aborted (might be a timeout).

@robert-hh
Copy link
Contributor
robert-hh commented Jul 22, 2017

Both Linux command line ftp and Mozilla fireftp
Same with FileZilla

@robert-hh
Copy link
Contributor
robert-hh commented Jul 22, 2017

@danicampora It seems to fail after all data has been transferred and the checksum is being verified. I did not hook up wireshark yet to see, if the error is reported by the device.
Update: Checked it with Wireshark: it's the Lopy sending 426.

@Mungio
Copy link
Mungio commented Jul 27, 2017

Using FileZilla everything works, but if I try to use a script, it fails. I think that the problem is that the "fs" area is large only 508K.

@robert-hh
Copy link
Contributor

@Mungio The OTA itself works, even I just get most of the time an error response from the ftp transfer after the file is tranferred. Using a script on your PC should not make a difference, as long as you transfer the image via the ftp protocol to /flash/sys/appimg.bin. The file is then NOT stored in the file system of the XxPy board.

@Mungio
Copy link
Mungio commented Jul 27, 2017

@robert-hh This is my code to download the file appimg.bin :

import socket
import gc
import uos
import machine
from network import WLAN
import utime
import sys

wlan = WLAN(mode=WLAN.STA)
wlan.connect('*******', auth=(WLAN.WPA2,"*********"))
while not wlan.isconnected():
    machine.idle()

def getPort(req):
    req = req.split('(')
    print(req)
    req = req[1].split(')')
    print(req)
    req = req[0].split(',')
    port = (int(req[4]) << 8) + int(req[5]) 
    return port

uos.chdir("sys")
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(socket.getaddrinfo("wpage.unina.it", 21)[0][-1])
s.sendall(b'USER *************\r\n')
req = str(s.recv(8192))
print(req)
s.sendall(b'PASS ************\r\n"')
req = str(s.recv(8192))
print(req)
s.sendall(b'PASV\r\n')
req = str(s.recv(8192))
print(req)
s.sendall(b'TYPE I\r\n')
req = str(s.recv(8192),'utf-8')
print(req)
port = getPort(req)
p = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
p.connect(socket.getaddrinfo("************", port)[0][-1])
print("Connected!")
f = open("appimg.bin",'wb')
f.close()
s.sendall(b'RETR appimg.bin\r\n')
req = str(s.recv(8192))
print(req)
print("Start transfer")

i=0
while 1:
    try:
        req = p.recv(8192)
        i = i + len(req)
        #print(req)
    except:
        print("Error Recv")
    else:
        #print(req)
        if not req or req == b"\r\n" or req == None:
            break
        q = open("appimg.bin","a")
    try:    
        q.write(req)
        #print("write done!")
        q.close()
    except:
        print("Error Write")
        q.close()
        break
    gc.collect()
utime.sleep(0.1)
print("DONE!")
print(str(i))

But it fails when transfers about 500K.

@jmarcelino
Copy link
Author
jmarcelino commented Jul 27, 2017

@Mungio
I don't know of any way to fetch the file from MicroPython, you have to FTP from another machine to the Pycom board and PUT the file from there. It's the Pycom FTP server - not the filesystem - that handles the appimg "magic".

@robert-hh
Copy link
Contributor

@jmarcelino SInce OTA update is now implemented, the issue could be closed.

@jmarcelino
Copy link
Author

Thanks Robert and Merry Christmas :-)

@robert-hh
Copy link
Contributor

Any you, Merry Christmas, Jose.

iwahdan88 pushed a commit that referenced this issue Dec 7, 2018
* Update Jenkinsfile, update version for first 1.20.0 RC

New device name on MacMini
New version 1.20.0.rc0

* Updated Jenkinsfile, application.mk

Build IDF libraries in esp-idf/examples/wifi/scan
Copy libraries from esp-idf/examples/wifi/scan during MPY build

* Update Jenkinsfile

Set IDF path before building libraries
Reduce MPY build to 2 parallel tasks
Use -C <dir> parameter with make

* Update Jenkinsfile

Build both Base and Pybytes revision
Build IDF libs in it's own task, same with git-tag

* Update Jenkinsfile

Set PATH for python3 executable
Fix missing space for VARIANT

* Update Jenkinsfile

Build BASE variant only for now
Fix parallel build for variants

* Updated Makefile, Jenkinsfile, makepkg.sh

Allow specifying BUILD_DIR in Makefile rather than using VARIANT specific build directory
Use BUILD_DIR in Jenkinsfile to build different variants
Pass BUILD_DIR to makepkg.sh as optional parameter

* Updated gitignore, application.mk

Pass build directory to makepkg.sh script

* Update Jenkinsfile

Fix missing forward slashes

* Update Jenkinsfile

Build both BASE and PYBYTES

* Update makepkg.sh

Fix build directory check

* Update makepkg.sh

Disable debug output
X-Ryl669 pushed a commit to X-Ryl669/pycom-micropython-sigfox that referenced this issue May 12, 2023
* Update Jenkinsfile, update version for first 1.20.0 RC

New device name on MacMini
New version 1.20.0.rc0

* Updated Jenkinsfile, application.mk

Build IDF libraries in esp-idf/examples/wifi/scan
Copy libraries from esp-idf/examples/wifi/scan during MPY build

* Update Jenkinsfile

Set IDF path before building libraries
Reduce MPY build to 2 parallel tasks
Use -C <dir> parameter with make

* Update Jenkinsfile

Build both Base and Pybytes revision
Build IDF libs in it's own task, same with git-tag

* Update Jenkinsfile

Set PATH for python3 executable
Fix missing space for VARIANT

* Update Jenkinsfile

Build BASE variant only for now
Fix parallel build for variants

* Updated Makefile, Jenkinsfile, makepkg.sh

Allow specifying BUILD_DIR in Makefile rather than using VARIANT specific build directory
Use BUILD_DIR in Jenkinsfile to build different variants
Pass BUILD_DIR to makepkg.sh as optional parameter

* Updated gitignore, application.mk

Pass build directory to makepkg.sh script

* Update Jenkinsfile

Fix missing forward slashes

* Update Jenkinsfile

Build both BASE and PYBYTES

* Update makepkg.sh

Fix build directory check

* Update makepkg.sh

Disable debug output
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
0