Created
December 22, 2020 20:02
-
-
Save danielsiwiec/7e53002d504b5eb8d7e06830a4ea7d01 to your computer and use it in GitHub Desktop.
MQTT connection
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
from umqtt.simple import MQTTClient | |
import json | |
client_id = 'esp8266' | |
mqtt_topic = 'tempReading/bedroom' | |
mqtt_port = 8883 | |
mqtt_host = 'a2XXXXXXXX.iot.us-west-2.amazonaws.com' | |
private_key = open("/private_key.der").read() | |
certificate = open("/cert.der").read() | |
mqtt_client = MQTTClient( | |
client_id=client_id, | |
server=mqtt_host, | |
port=mqtt_port, | |
keepalive=10000, | |
ssl=True, | |
ssl_params={ | |
'cert': certificate, | |
'key': private_key} | |
) | |
mqtt_client.connect() | |
mqtt_client.publish(mqtt_topic, json.dumps({'temp': 62.5})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment