Skip to content

Commit

Permalink
Step 6 - Send key presses through MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
tomczoink committed Mar 21, 2018
1 parent f0c10f7 commit f2b94a1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mqtt-snake/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

def on_connect(client, userdata, flags, rc):
print('Connected')

def on_disconnect(client, userdata, rc):
print('Disconnected')
client.loop_stop()

client = mqtt.Client()
client.username_pw_set('FIRST_HALF_OF_API_KEY', 'SECOND_HALF_OF_API_KEY')
client.tls_set()
Expand All @@ -25,16 +27,15 @@ def main(win):
client.disconnect()
break
elif key == 'KEY_LEFT':
win.addstr('Left clicked!')
win.addstr(str(counter))
client.publish('input', 'left', qos=0)
elif key == 'KEY_RIGHT':
win.addstr('Right clicked!')
client.publish('input', 'right', qos=0)
elif key == 'KEY_UP':
win.addstr('Up clicked!')
client.publish('input', 'up', qos=0)
elif key == 'KEY_DOWN':
win.addstr('Down clicked!')
client.publish('input', 'down', qos=0)
elif key == ' ':
win.addstr('Space clicked!')
client.publish('input', 'startstop', qos=0)
except Exception as e:
pass
curses.wrapper(main)

0 comments on commit f2b94a1

Please sign in to comment.