Skip to content

Instantly share code, notes, and snippets.

@danielsiwiec
Created December 22, 2020 20:02
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 danielsiwiec/7e53002d504b5eb8d7e06830a4ea7d01 to your computer and use it in GitHub Desktop.
Save danielsiwiec/7e53002d504b5eb8d7e06830a4ea7d01 to your computer and use it in GitHub Desktop.
MQTT connection
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