Skip to content

Instantly share code, notes, and snippets.

@metametaclass
Created October 30, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save metametaclass/fdcd53e4e699ed5a0a780bc74a8a5eca to your computer and use it in GitHub Desktop.
Save metametaclass/fdcd53e4e699ed5a0a780bc74a8a5eca to your computer and use it in GitHub Desktop.
import serial
import time
import sys
import socket
import datetime
s = None
sock = None
def setup():
global s
global sock
s = serial.Serial("/dev/ttyS0", 9600, timeout=1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
def loop():
b = bytearray([0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79])
#print('q');
s.write(b)
time.sleep(1)
result = s.read(9)
#print('a', type(result))
msg = datetime.datetime.now().isoformat()+","+result.encode("hex")+","+str(ord(result[2])*256+ord(result[3]))+'\n'
sock.sendto(msg, ("192.168.1.4", 0xC0C0))
sock.sendto(msg, ("192.168.1.4", 0xC0C1))
for i in result:
sys.stdout.write(hex(ord(i)))
sys.stdout.write(' ')
sys.stdout.write('\n')
sys.stdout.flush
time.sleep(14)
if __name__ == '__main__':
setup()
while True:
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment