Created
January 31, 2017 17:29
-
-
Save k3an3/524cdfc704f9da46aff28f177431df51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import errno | |
import socket | |
import sys | |
from time import sleep | |
PORT = 48899 | |
AUTH = 'HF-A11ASSISTHREAD'.encode() | |
OK = "+ok".encode() | |
target = sys.argv[1] | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.bind(('', PORT)) | |
s.setblocking(0) | |
def quit(): | |
print() | |
sys.exit() | |
while True: | |
try: | |
msg = "AT+" + input('-> ') | |
except KeyboardInterrupt: | |
quit() | |
except EOFError: | |
quit() | |
s.sendto(AUTH, (target, PORT)) | |
s.sendto(OK, (target, PORT)) | |
sleep(.4) | |
s.sendto((msg + '\n').encode(), (target, PORT)) | |
sleep(.4) | |
data = "" | |
while True: | |
try: | |
data += s.recv(1024).decode() | |
except socket.error as e: | |
if e.errno == errno.EWOULDBLOCK: | |
break | |
print(str(e)) | |
print('\n'.join(data.replace('\r', '').split('\n')[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment