-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTempData2EH.py
25 lines (23 loc) · 1.22 KB
/
TempData2EH.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# GrovePi + Grove Temperature Sensor
import time
import grovepi
from azure.servicebus import ServiceBusService
key_name ='RootManageSharedAccessKey' # SharedAccessKeyName from Azure Portal
key_value='' # SharedAccessKey from Azure Portal
sbs = ServiceBusService('asatestsn', shared_access_key_name=key_name, shared_access_key_value=key_value)
sbs.create_event_hub('hubcreationfromlinux')
# Connect the Grove Temperature Sensor to analog port D4
sensor_port = 4
deviceId = "device-1"
#Declare direction to the pin.
#grovepi.pinMode (Temp_sensor,"INPUT")
while True:
try:
[temp,hum] = grovepi.dht(sensor_port,0)
CurrentTime = str(time.localtime(time.time()).tm_hour) + ":" + str(time.localtime(time.time()).tm_min) + ":"+ str(time.localtime(time.time()).tm_sec)
print "Temperature : ", temp , "Humidity : ", hum, "RecordTime : ", CurrentTime
sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + str(temp) +'", "Humidity":"' + str(hum) +'", "RecordTime":"' + str(CurrentTime) +'"}')
# sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + temperature +'"}')
time.sleep(1.0)
except IOError:
print "Error"