Created
September 17, 2019 17:09
-
-
Save elbruno/e31b7b3257f647d6556a90c4eebda128 to your computer and use it in GitHub Desktop.
AzureIoTCSendCustomTelemetry.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) | |
gCounter += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment