Created
September 17, 2019 17:13
-
-
Save elbruno/256986d2298e1e5618246ee441fc2974 to your computer and use it in GitHub Desktop.
AzureIoTCSendCustomTelemetryAndEvent.py
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
# 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