Skip to content

Instantly share code, notes, and snippets.

@sushilshah
Created March 28, 2016 11:29
Show Gist options
  • Save sushilshah/99065455c82c342da1c0 to your computer and use it in GitHub Desktop.
Save sushilshah/99065455c82c342da1c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import paho.mqtt.client as paho
import os
import socket
import ssl
from time import sleep
from random import uniform
connflag = False
def on_connect(client, userdata, flags, rc):
global connflag
connflag = True
print("Connection returned result: " + str(rc))
mqttc = paho.Client()
mqttc.on_connect = on_connect
awshost = "ABCDEFGH.iot.ap-northeast-1.amazonaws.com"
awsport = 8883
caPath = "D:\personal_docs\iot\keys\CA_certificate_aws_iot"
certPath = "D:\personal_docs\iot\keys\cert.pem"
keyPath = "D:\personal_docs\iot\keys\myHomePiPrivateKey.pem"
mqttc.tls_set(caPath, certfile=certPath, keyfile=keyPath, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
mqttc.connect(awshost, awsport, keepalive=60)
mqttc.loop_start()
while 1==1:
sleep(2)
message = "{'Hello' : 'world foo'} "
#mqttc.publish("$aws/things/rpi/shadow/update", message, qos=1)
mqttc.publish("my/topic", message, qos=1)
print ('publish my topic')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment