diff --git a/iot/api-client/codelabs/lightsensor.py b/iot/api-client/codelabs/lightsensor.py index 481dcfe138eb..4115c8ea4679 100644 --- a/iot/api-client/codelabs/lightsensor.py +++ b/iot/api-client/codelabs/lightsensor.py @@ -84,7 +84,7 @@ def detect_light(device_id, sock): lux = "{:.3f}".format(LightSensor.lux) sys.stdout.write( - '\r>> ' + bcolors.CGREEN + bcolors.CBLINK + 'Lux: {}'.format(lux) + + '\r>> ' + bcolors.CGREEN + bcolors.CBOLD + 'Lux: {}'.format(lux) + bcolors.ENDC + ' <<') sys.stdout.flush() @@ -95,9 +95,14 @@ def detect_light(device_id, sock): def print_sensor_state(): - print( - '\nSensor is {}, reporting lux every {} seconds.'.format( - LightSensor.power, LightSensor.interval)) + if LightSensor.power == 'on': + print( + '\nSensor is {}, reporting lux every {} seconds.'.format( + LightSensor.power, LightSensor.interval)) + else: + print( + '\nSensor is {}. Send a configuration update to turn on'.format( + LightSensor.power)) def process_message(message): @@ -172,11 +177,13 @@ def main(): sys.exit(1) else: # Received data from the socket, so process the message. - message = json.loads(data.decode("utf-8")) - if not message: - print('invalid json: {}'.format(data.decode("utf-8"))) - continue - process_message(message) + decode = data.decode("utf-8") + if decode != '': + message = json.loads(decode) + if not message: + print('invalid json: {}'.format(data.decode("utf-8"))) + continue + process_message(message) finally: print('Closing socket') sock.close() diff --git a/iot/api-client/codelabs/thermostat.py b/iot/api-client/codelabs/thermostat.py index 165b941fc828..39d7e6263c4e 100644 --- a/iot/api-client/codelabs/thermostat.py +++ b/iot/api-client/codelabs/thermostat.py @@ -77,7 +77,7 @@ def main(): humidity = "{:.3f}".format(h) temperature = "{:.3f}".format(temperature_f) sys.stdout.write( - '\r >>' + bcolors.CGREEN + bcolors.CBOLD + + '\r>> ' + bcolors.CGREEN + bcolors.CBOLD + 'Temp: {} F, Hum: {}%'.format(temperature, humidity) + bcolors.ENDC + ' <<') sys.stdout.flush()