forked from yorkhackspace/SpacehackClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimalclient.py
More file actions
32 lines (24 loc) · 797 Bytes
/
minimalclient.py
File metadata and controls
32 lines (24 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Console game client - proof of concept demo
#York Hackspace - Bob November 2013
#This runs on a Beaglebone Black
#This is a minimal version with all the hardware interaction taken out.
import mosquitto
import commands
#Who am I?
ipaddress = commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
#MQTT client
client = mosquitto.Mosquitto("Game-" + ipaddress) #client ID
server = "192.168.1.30" #fixed IP address of server
#MQTT message arrived
def on_message(mosq, obj, msg):
print(msg.topic + " - " + str(msg.payload))
#Setup MQTT
client.on_message = on_message
client.connect(server)
client.subscribe("control1")
client.subscribe("control2")
client.subscribe("instruction")
client.subscribe("digit1")
client.subscribe("digit2")
#Set MQTT listening
client.loop_forever()