If long press, then I need to restart the device in setup mode, otherwise I start it in run mode.
The boot.py initialises the interrupt and during startup reads a json file, if the mode in the json config is set to run then it will execute the run library otherwise it will execute the setup library.
All of this works fine if I manually edit the .json variable, the problem is I cannot write to the .json file during the button press interrupt routine.
Any suggestions on an alternative method of selecting run / setup modes during boot with the ability to trigger the system to reboot and run the correct mode or how I can write the mode to the json file
Code: Select all
rmode = 'run'
startms = 0
def pincb(pin):
global rmode, run, startms
if(pin()==0 and startms==0):
startms = ticks_ms()
while ticks_diff(ticks_ms(),startms) < 200: pass
while pin() == 0: pass
if(ticks_diff(ticks_ms(),startms)>1050): rmode = 'setup'
startms = 0
jsonWrite('mode':rmode) ## << can't do this !
machine.reset()
def pininit():
but = Pin(13, Pin.IN, Pin.PULL_UP)
but.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=pincb)
data = jsonRead()
if(data['mode']=='run'): mqtts()
else: webs()