timestamp in and out messages
This commit is contained in:
8
hcpy
8
hcpy
@@ -9,6 +9,7 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
# Monkey patch for sslpsk in pip using the old _sslobj
|
# Monkey patch for sslpsk in pip using the old _sslobj
|
||||||
@@ -19,6 +20,8 @@ def _sslobj(sock):
|
|||||||
return sock._sslobj
|
return sock._sslobj
|
||||||
sslpsk.sslpsk._sslobj = _sslobj
|
sslpsk.sslpsk._sslobj = _sslobj
|
||||||
|
|
||||||
|
def now():
|
||||||
|
return datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
host = '10.1.0.133'
|
host = '10.1.0.133'
|
||||||
@@ -39,10 +42,10 @@ ssl_sock = sslpsk.wrap_socket(
|
|||||||
|
|
||||||
ws = None
|
ws = None
|
||||||
def tx(msg):
|
def tx(msg):
|
||||||
|
print(now(), "TX:", msg)
|
||||||
buf = json.dumps(msg, separators=(',', ':') )
|
buf = json.dumps(msg, separators=(',', ':') )
|
||||||
# swap " for '
|
# swap " for '
|
||||||
buf = re.sub("'", '"', buf)
|
buf = re.sub("'", '"', buf)
|
||||||
print("TX:", buf)
|
|
||||||
ws.send(buf)
|
ws.send(buf)
|
||||||
|
|
||||||
def send_initial_messages():
|
def send_initial_messages():
|
||||||
@@ -81,7 +84,8 @@ def send_initial_messages():
|
|||||||
def handle_message(buf):
|
def handle_message(buf):
|
||||||
global session_id, msg_id
|
global session_id, msg_id
|
||||||
msg = json.loads(buf)
|
msg = json.loads(buf)
|
||||||
print("RX:", msg)
|
print(now(), "RX:", msg)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
# first message from the device establishes the session etc
|
# first message from the device establishes the session etc
|
||||||
# {'sID': 926468163, 'msgID': 3785595876, 'resource': '/ei/initialValues', 'version': 2, 'action': 'POST', 'data': [{'edMsgID': 2569124008}]}
|
# {'sID': 926468163, 'msgID': 3785595876, 'resource': '/ei/initialValues', 'version': 2, 'action': 'POST', 'data': [{'edMsgID': 2569124008}]}
|
||||||
|
|||||||
Reference in New Issue
Block a user