Created
December 5, 2014 08:58
-
-
Save tomconte/19982fb73890ef5b210d 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/python | |
import sys | |
import commands | |
import re | |
import uuid | |
import serial | |
from proton import * | |
# Device ID | |
id = uuid.getnode() | |
# Topic address | |
address = "amqps://owner:key@arduino.servicebus.windows.net/esplora" | |
# Open serial port | |
ser = serial.Serial('/dev/ttyACM0', 9600) | |
# Create Proton objects | |
messenger = Messenger() | |
while True: | |
# Read values from Arduino in the form K1:V1_K2:V2_... | |
temp = ser.readline().rstrip('\r\n') | |
print temp | |
# Create AMQP message | |
message = Message() | |
# Initialize properties | |
message.properties = dict() | |
message.properties[symbol("did")] = symbol(id) | |
# Map string to list, symbolize, create dict and merge | |
pairs=map(lambda x:x.split(':'), temp.split('_')) | |
symbols = map(lambda x:(symbol(x[0]),int(x[1])), pairs) | |
message.properties.update(dict(symbols)) | |
message.address = address | |
messenger.put(message) | |
messenger.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment