mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
in log script, print sender as well as addressee
This commit is contained in:
parent
608b4010a0
commit
774a05f8dc
1 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import argparse, re
|
||||
import argparse, re, struct
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
g_topics = [
|
||||
|
@ -18,7 +18,8 @@ def on_connect(client, userdata, flags, rc):
|
|||
def on_message(client, obj, msg):
|
||||
match = sDevIDPat.match(msg.topic)
|
||||
if match:
|
||||
print('on_message(): for: {}, len: {}'.format(match.group(1), len(msg.payload)))
|
||||
(sender, gameID) = getSender(msg.payload)
|
||||
print('on_message(): from {} to {}, len: {}'.format(sender, match.group(1), len(msg.payload)))
|
||||
|
||||
def on_publish(client, obj, mid):
|
||||
print("mid: " + str(mid))
|
||||
|
@ -29,6 +30,16 @@ def on_subscribe(client, obj, mid, granted_qos):
|
|||
def on_log(client, obj, level, string):
|
||||
print(string)
|
||||
|
||||
def getSender(payload):
|
||||
result = None
|
||||
got = struct.unpack_from('>bqI', payload)
|
||||
if 0 == got[0] or 1 == got[0]:
|
||||
devID = '{:016X}'.format(got[1])
|
||||
gameID = 1 == got[0] and got[2] or 0
|
||||
result = (devID, gameID)
|
||||
# print('getSender() => {}'.format(result))
|
||||
return result
|
||||
|
||||
def makeClient():
|
||||
mqttc = mqtt.Client()
|
||||
# Assign event callbacks
|
||||
|
|
Loading…
Add table
Reference in a new issue