Skip to content

Commit

Permalink
Sending messages to IoT Hub
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Hiermann committed Dec 7, 2021
1 parent c21e6e6 commit 3a29317
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import json
import os
from datetime import datetime
from azure.iot.device import Message
from azure.iot.device.aio import IoTHubDeviceClient

PATH = "/home/pi/station/"
URL = open(PATH + '.url', 'r').readline().strip()
# Used to connect the device to the IOT Hub
CONNECTION_STRING = open(PATH + '.conKey', 'r').readline().strip()
# Create instance of the device client
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)

LED_PIN_GR = 7
LED_PIN_YE = 12
Expand Down Expand Up @@ -58,6 +62,11 @@ def get_temperature_humidity():

def send_data(data):
try:
# TODO: Make request to Azure IOT
message = Message(data)
client.send_message(message)

# API request
r = requests.post(
url=URL + 'measurement',
data=data
Expand Down

0 comments on commit 3a29317

Please sign in to comment.