Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AzureIoTCSendCustomTelemetryAndEvent.py
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license.
# Based on
# https://raw.githubusercontent.com/Azure/iot-central-firmware/master/RaspberryPi/app.py
...
while iotc.isConnected():
iotc.doNext() # do the async work needed to be done for MQTT
if gCanSend == True:
if gCounter % 20 == 0:
gCounter = 0
print("Sending telemetry..")
telemetryJson = "{\"temp\": " + str(randint(20, 45)) + ", \
\"accelerometerX\": " + str(randint(2, 15)) + ", \
\"accelerometerY\": " + str(randint(3, 9)) + ", \
\"accelerometerZ\": " + str(randint(3, 9)) + ", \
\"t1\": " + str(float(random.random()*100)) + "}"
print(telemetryJson)
iotc.sendTelemetry(telemetryJson)
if gCounter % 60 == 0:
print("Sending event ..")
eventJson = "{\"event1\": \"data " + str(float(random.random()*100)) + "\"}"
print(eventJson)
iotc.sendEvent(eventJson)
gCounter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.