index out of range errors :: Devices unresponsive
I was porting uPyEcho to latest MicroPython (June 2020-- 1.12_2 ) to run on the TinPICO.
As part of that, I had to change all the references to clock.gmtime() to clock.datetime() when composing the date_str. as gmtime() is not available on my MP port.
After this format_timetuple_and_zone was hitting index out of range errors and my devices were intermittently discoverable AND always unresponsive after they did work (On and Off).
I tracked that down to changing the timetuple[6] in the day of the week section to [timetuple[4].
This is the corrected function which worked for me.
def format_timetuple_and_zone(timetuple, zone):
return "%s, %02d %s %04d %02d:%02d:%02d %s" % (
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][timetuple[4]],
timetuple[2],
[
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
][timetuple[1] - 1],
timetuple[0],
timetuple[3],
timetuple[4],
timetuple[5],
zone,
)
I don't know why this happened. I'm not sure if the time.gmtime() on your ports of MicroPython just has different looking tuples, if the timetuple changed in MicroPython or if this was always a bug. But for me on 1.12 on the TinyPICO this works.
I thought I'd share in case others hit this this as well.
Thanks!
Thank you, I will check that and keep you informed.