Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created September 17, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/e31b7b3257f647d6556a90c4eebda128 to your computer and use it in GitHub Desktop.
Save elbruno/e31b7b3257f647d6556a90c4eebda128 to your computer and use it in GitHub Desktop.
AzureIoTCSendCustomTelemetry.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)
gCounter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment