mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-10-27 05:56:11 +03:00 
			
		
		
		
	Fix espota completion success/fail check (#7204)
The OTA script was not reporting the actual reported upload status from the ESP8266, and instead always printed "Result: OK" no matter what happened. Now check for ERROR or OK in final message (and ensure the message is not accidentally merged with the final byte count) and report properly. Fixes #7162
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							1af4ea661f
						
					
				
				
					commit
					9632e868d5
				
			| @@ -328,9 +328,13 @@ void ArduinoOTAClass::_runUpdate() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (Update.end()) { |   if (Update.end()) { | ||||||
|     client.print("OK"); |     // Ensure last count packet has been sent out and not combined with the final OK | ||||||
|     client.stop(); |     client.flush(); | ||||||
|     delay(1000); |     delay(1000); | ||||||
|  |     client.print("OK"); | ||||||
|  |     client.flush(); | ||||||
|  |     delay(1000); | ||||||
|  |     client.stop(); | ||||||
| #ifdef OTA_DEBUG | #ifdef OTA_DEBUG | ||||||
|     OTA_DEBUG.printf("Update Success\n"); |     OTA_DEBUG.printf("Update Success\n"); | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -132,7 +132,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm | |||||||
|         sys.stderr.write('FAIL\n') |         sys.stderr.write('FAIL\n') | ||||||
|         logging.error('%s', data) |         logging.error('%s', data) | ||||||
|         sock2.close() |         sock2.close() | ||||||
|         sys.exit(1); |         sys.exit(1) | ||||||
|         return 1 |         return 1 | ||||||
|       sys.stderr.write('OK\n') |       sys.stderr.write('OK\n') | ||||||
|     else: |     else: | ||||||
| @@ -172,7 +172,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm | |||||||
|         connection.sendall(chunk) |         connection.sendall(chunk) | ||||||
|         if connection.recv(32).decode().find('O') >= 0: |         if connection.recv(32).decode().find('O') >= 0: | ||||||
|           # connection will receive only digits or 'OK' |           # connection will receive only digits or 'OK' | ||||||
|           received_ok = True; |           received_ok = True | ||||||
|       except: |       except: | ||||||
|         sys.stderr.write('\n') |         sys.stderr.write('\n') | ||||||
|         logging.error('Error Uploading') |         logging.error('Error Uploading') | ||||||
| @@ -188,19 +188,25 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm | |||||||
|     # the connection before receiving the 'O' of 'OK' |     # the connection before receiving the 'O' of 'OK' | ||||||
|     try: |     try: | ||||||
|       connection.settimeout(60) |       connection.settimeout(60) | ||||||
|       while not received_ok: |       received_ok = False | ||||||
|         if connection.recv(32).decode().find('O') >= 0: |       received_error = False | ||||||
|           # connection will receive only digits or 'OK' |       while not (received_ok or received_error): | ||||||
|           received_ok = True; |         reply = connection.recv(64).decode() | ||||||
|       logging.info('Result: OK') |         # Look for either the "E" in ERROR or the "O" in OK response | ||||||
|  |         # Check for "E" first, since both strings contain "O" | ||||||
|  |         if reply.find('E') >= 0: | ||||||
|  |           sys.stderr.write('\n') | ||||||
|  |           logging.error('%s', reply) | ||||||
|  |           received_error = True | ||||||
|  |         elif reply.find('O') >= 0: | ||||||
|  |           logging.info('Result: OK') | ||||||
|  |           received_ok = True | ||||||
|       connection.close() |       connection.close() | ||||||
|       f.close() |       f.close() | ||||||
|       sock.close() |       sock.close() | ||||||
|       if (data != "OK"): |       if received_ok: | ||||||
|         sys.stderr.write('\n') |         return 0 | ||||||
|         logging.error('%s', data) |       return 1 | ||||||
|         return 1; |  | ||||||
|       return 0 |  | ||||||
|     except: |     except: | ||||||
|       logging.error('No Result!') |       logging.error('No Result!') | ||||||
|       connection.close() |       connection.close() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user