Created
March 8, 2016 03:50
-
-
Save lily-mara/23d127292f1c824b7e21 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 | |
from serial import Serial | |
import sys | |
import requests | |
def main(): | |
serial_port = find_port() | |
while True: | |
s = serial_port.read().split(',') | |
requests.post('https://foo.com?var1={}&var2={}'.format(s[0], s[1])) | |
def find_port(): | |
locations = [ | |
'/dev/ttyACM0', '/dev/ttyACM1','/dev/ttyACM2', | |
'/dev/ttyACM3','/dev/ttyACM4', | |
'/dev/ttyACM5','/dev/ttyUSB0','/dev/ttyUSB1','/dev/ttyUSB2','/dev/ttyUSB3', | |
'/dev/ttyUSB4', '/dev/ttyUSB5', '/dev/ttyUSB6', '/dev/ttyUSB7', | |
'/dev/ttyUSB8', '/dev/ttyUSB9', '/dev/ttyUSB10','/dev/ttyS0', | |
'/dev/ttyS1', '/dev/ttyS2', 'com2', 'com3', 'com4', 'com5', 'com6', | |
'com7', 'com8', 'com9', 'com10', 'com11', 'com12', 'com13', 'com14', | |
'com15', 'com16', 'com17', 'com18', 'com19', 'com20', 'com21', 'com1', | |
'end' | |
] | |
for device in locations: | |
try: | |
serial_port = Serial(device) | |
return serial_port | |
except: | |
if device == 'end': | |
print('Unable to find Serial Port.') | |
sys.exit(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment