Created
October 4, 2015 00:09
-
-
Save KentaroAOKI/ace0d3c4a5192d4b32cc to your computer and use it in GitHub Desktop.
Send the sensor data of Raspberry PI to the Azure Event Hub using SORACOM.
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
#coding: utf-8 | |
from azure.servicebus import ServiceBusService | |
import urllib3 | |
import datetime | |
#azure service bus | |
key_name = 'SendRule' # SharedAccessKeyName from Azure portal | |
key_value = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # SharedAccessKey from Azure portal | |
service_namespace = 'xxxxx-ns' | |
sbs = ServiceBusService(service_namespace, | |
shared_access_key_name=key_name, | |
shared_access_key_value=key_value) | |
#values | |
http = urllib3.PoolManager() | |
r = http.request('GET', 'http://beam.soracom.io:8888/') | |
devid = r.data.split("=")[1].strip() | |
dtime = datetime.datetime.today().strftime("%F %H:%M:%S %z").strip() | |
#from sensors | |
temp = "27.4" | |
pres = "1000.1" | |
hum = "68.0" | |
hilux = "100.0" | |
lowlux = "10.0" | |
#json fot event hub | |
json = '{ "Date":"' + dtime + '", "DeviceId":"' + devid + '", "Temp":"' + temp + '", "Pressure":"' + pres + '","Hum":"' + hum + '", "HiLux":"' + hilux + '","LowLux":"' + lowlux + '" }' | |
sbs.send_event('sora', json) | |
print json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment