From 283deea22c7e24553f295bcb5cb3049b0f1ef0f2 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Tue, 13 Nov 2018 21:36:20 +0100 Subject: [PATCH] add try catch for code execution --- main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 09961b0..44d7270 100755 --- a/main.py +++ b/main.py @@ -23,7 +23,10 @@ def step(): battery_voltage = sumorobot.get_battery_voltage(), ) # Execute code - exec(ast) + try: + exec(ast) + except: + pass # When robot was stopped if sumorobot.terminate: # Disable forceful termination of delays in code @@ -78,7 +81,7 @@ def ws_handler(): elif b'code' in data: data = ujson.loads(data) data['val'] = data['val'].replace(";;", "\n") - print("code:", data['val']) + #print("code:", data['val']) ast = compile(data['val'], "snippet", "exec") elif b'stop' in data: ast = "" @@ -87,6 +90,7 @@ def ws_handler(): sumorobot.terminate = True elif b'calibrate_line' in data: sumorobot.calibrate_line() + #print('calibrate') elif b'Gone' in data: print("server said 410 Gone, attempting to reconnect...") #conn = uwebsockets.connect(url) @@ -98,8 +102,8 @@ while not wlan.isconnected(): sleep_ms(100) # Connect to the websocket -url = "ws://%s/p2p/sumo-%s/browser/" % (config['sumo_server'], config['sumo_id']) -conn = uwebsockets.connect(url) +uri = "ws://%s/p2p/sumo-%s/browser/" % (config['sumo_server'], config['sumo_id']) +conn = uwebsockets.connect(uri) # Set X seconds timeout for socket reads conn.settimeout(1)