Here's a notional example of what I mean:
Code: Select all
>>> simpleCode="def j(x): return x**2"
>>> simpleCode
'def j(x): return x**2'
>>> exec(simpleCode)
>>> j(5)
25
>>>
Code: Select all
>>> simpleCode="def j(x): return x**2"
>>> simpleCode
'def j(x): return x**2'
>>> exec(simpleCode)
>>> j(5)
25
>>>
Which code on target do you want to update?WhiteHare wrote:Then the target executes the string, which updates the code on the target.
Are you a C/C++ programmer?
Updating the firmware of micropython cannot be done while running micropython.WhiteHare wrote:Well, for microcontrollers, that's the language that I've been using.
On ESP32 boards it is an easy process and it is implemented in my MicroPython port.
Code: Select all
from microbit import *
import radio
print ("Starting...");
radio.on()
txCode = "def j(x): return x**2"
codeReceived = False
while (not codeReceived):
radio.send(txCode)
sleep(1000)
newCode = radio.receive()
if (newCode != None) :
print(newCode)
exec(newCode)
codeReceived = True
Code: Select all
Starting...
def j(x): return x**2
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit v1.0.0 with nRF51822
Type "help()" for more information.
>>> j(4)
16
>>>