Use micropython to do dead simple "over-the-air" code updates

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
pythoncoder
Posts: 4365
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Use micropython to do dead simple "over-the-air" code updates

Post by pythoncoder » Thu Nov 01, 2018 11:32 am

That is very odd. I've today run the following under CPython. I've also run it under MicroPython on the following ports: Unix, Pyboard and ESP8266. All without issue.

Code: Select all

radioBuffer = bytearray(256)
mv = memoryview(radioBuffer)

def copyStringToRadioBuffer(s):
    l = len(s)
    mv[: l] = s.encode('utf8')[: l]
    mv[l] = 0

copyStringToRadioBuffer('The quick brown fox\n')
print(radioBuffer)
If it fails on your platform it could be a build-time option otherwise it's a port specific bug. I'm not well-up on the build options but if it were a space-saving optimisation I'd have expected to see it on the ESP8266.

Has anyone else any thoughts on this?
Peter Hinch

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: Use micropython to do dead simple "over-the-air" code updates

Post by WhiteHare » Thu Nov 01, 2018 5:26 pm

OK, until that gets sorted, I reverted to the prior copyStringToRadioBuffer definition for the current files posted on GitHub. That way anyone downloading the files should have something that works.

I also made a few upgrades:
1. Rather than running open loop and transmitting each packet 3 times, the receiver node now transmits an acknowledgement to the transmitter to let the transmitter know that the receiver received a valid packet and for the transmitter to please the next packet.
2. Upgraded from 1mbps to 2mbps over the air datarate.
3. Enabled data-whitening.
4. Now using a longer preamble on transmitted packets.

https://github.com/rabbithat/NRF52840_M ... TA_Updates

User avatar
pythoncoder
Posts: 4365
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Use micropython to do dead simple "over-the-air" code updates

Post by pythoncoder » Fri Nov 02, 2018 8:19 am

WhiteHare wrote:
Thu Nov 01, 2018 5:26 pm
OK, until that gets sorted, I reverted to the prior copyStringToRadioBuffer definition for the current files posted on GitHub...
Fair enough.

I've posted this message to establish why this orthodox bit of Python is failing, and to determine which Nordic targets are affected.

As an optimisation it's pretty small beer, but we should know why it's failing.
Peter Hinch

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: Use micropython to do dead simple "over-the-air" code updates

Post by WhiteHare » Sat Nov 03, 2018 1:04 am

Thanks! Now that we've solved that, I added your code back into the official github release: https://github.com/rabbithat/NRF52840_M ... TA_Updates

User avatar
pythoncoder
Posts: 4365
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Use micropython to do dead simple "over-the-air" code updates

Post by pythoncoder » Sat Nov 03, 2018 11:14 am

Alas we proved that my solution requires users to create a special build. Your code avoids this so is arguably more usable, at least until the official build gets better ;)
Peter Hinch

Post Reply