Created
April 8, 2020 12:55
-
-
Save viewpointsa/64a1512c0b684c8e0cb9ffc4f9e38fc9 to your computer and use it in GitHub Desktop.
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
import paho.mqtt.client as mqtt | |
import sys | |
import json | |
from random import random | |
import ssl | |
import os | |
# This is the Publisher | |
data = json.dumps({ | |
'temperature' : random() * 20.0, | |
'wind': random() * 10, | |
'wind_direction' : [ "South", "North", "East", "West" ][int(random()*4)] | |
}) | |
here = os.path.dirname(__file__) | |
ca_certs = os.path.join(here, "iot-hub-ca.pem") | |
certfile = os.path.join(here, "device1-crt.pem") | |
keyfile = os.path.join(here, "device1-key.pem") | |
client_id = "<GUID_DEVICEID>" | |
client = mqtt.Client(client_id=client_id) | |
client.enable_logger() | |
client.tls_set(ca_certs=ca_certs, certfile=certfile, keyfile=keyfile, cert_reqs=ssl.CERT_REQUIRED, | |
tls_version=ssl.PROTOCOL_TLS) | |
client.connect("iot.fr-par.scw.cloud",8883,60) | |
client.publish("topic/test", data ) | |
client.disconnect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment