11#!/usr/bin/env python
22
33"""
4- The WiPy firmware update script. Transmits the specified firmware file over FTP
5- and then resets the WiPy.
4+ The WiPy firmware update script. Transmits the specified firmware file
5+ over FTP, and then resets the WiPy and optionally verifies that software
6+ was correctly updated.
67
78Usage:
89
@@ -62,7 +63,7 @@ def reset_board(args):
6263
6364 if b'Password:' in tn .read_until (b"Password:" , timeout = 5 ):
6465 # needed because of internal implementation details of the WiPy's telnet server
65- time .sleep (1 )
66+ time .sleep (0.2 )
6667 tn .write (bytes (args .password , 'ascii' ) + b"\r \n " )
6768
6869 if b'Type "help()" for more information.' in tn .read_until (b'Type "help()" for more information.' , timeout = 5 ):
@@ -92,7 +93,6 @@ def reset_board(args):
9293
9394
9495def verify_update (args ):
95-
9696 success = False
9797 firmware_tag = ''
9898
@@ -105,8 +105,8 @@ def find_tag (tag):
105105 print ("Error: verification failed, the git tag doesn't match" )
106106
107107 try :
108- # Specify a longer time out value because the board has just been reset
109- # and the wireless connection might not be fully established yet
108+ # Specify a longer time out value here because the board has just been
109+ # reset and the wireless connection might not be fully established yet
110110 tn = Telnet (args .ip , timeout = 15 )
111111 print ("Connected via telnet again, lets check the git tag" )
112112
@@ -140,7 +140,7 @@ def main():
140140 cmd_parser .add_argument ('-u' , '--user' , default = 'micro' , help = 'the username' )
141141 cmd_parser .add_argument ('-p' , '--password' , default = 'python' , help = 'the login password' )
142142 cmd_parser .add_argument ('--ip' , default = '192.168.1.1' , help = 'the ip address of the WiPy' )
143- cmd_parser .add_argument ('--verify' , action = 'store_true' , help = 'verify that the update succeded ' )
143+ cmd_parser .add_argument ('--verify' , action = 'store_true' , help = 'verify that the update succeeded ' )
144144 cmd_parser .add_argument ('-t' , '--tag' , default = None , help = 'git tag of the firmware image' )
145145 args = cmd_parser .parse_args ()
146146
@@ -155,8 +155,8 @@ def main():
155155 print ('Waiting for the WiFi connection to come up again...' )
156156 # this time is to allow the system's wireless network card to connect to the
157157 # WiPy again. Sometimes it might only take a couple of seconds, but let's
158- # leave 10s to be on the safe side
159- time .sleep (10 )
158+ # leave 15s to be on the safe side
159+ time .sleep (15 )
160160 if verify_update (args ):
161161 result = 0
162162 else :
0 commit comments