diff --git a/esphomeyaml/__main__.py b/esphomeyaml/__main__.py index 1462cdf29e..36c5414b58 100644 --- a/esphomeyaml/__main__.py +++ b/esphomeyaml/__main__.py @@ -102,12 +102,15 @@ def run_miniterm(config, port, escape=False): with serial.Serial(port, baudrate=baud_rate) as ser: while True: - line = ser.readline() + line = ser.readline().replace('\r', '').replace('\n', '') time = datetime.now().time().strftime('[%H:%M:%S]') - message = time + line.decode('unicode-escape').replace('\r', '').replace('\n', '') + message = time + line if escape: - message = message.replace('\033', '\\033').encode('ascii', 'replace') - print(message) + message = message.replace('\033', '\\033') + try: + print(message) + except UnicodeEncodeError: + print(message.encode('ascii', 'backslashreplace')) def write_cpp(config): diff --git a/esphomeyaml/mqtt.py b/esphomeyaml/mqtt.py index 4e4b75a17d..3497e600a1 100644 --- a/esphomeyaml/mqtt.py +++ b/esphomeyaml/mqtt.py @@ -57,10 +57,13 @@ def show_logs(config, topic=None, username=None, password=None, client_id=None, def on_message(client, userdata, msg): time = datetime.now().time().strftime(u'[%H:%M:%S]') - message = msg.payload.decode('utf-8') + message = time + msg.payload if escape: message = message.replace('\033', '\\033') - print(time + message) + try: + print(message) + except UnicodeEncodeError: + print(message.encode('ascii', 'backslashreplace')) return initialize(config, [topic], on_message, username, password, client_id)