SHARE
TWEET

Untitled

a guest Aug 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rom AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
  2. import time
  3. import json
  4.  
  5. host =  "a2c7vpgkmq05d0-ats.iot.us-west-2.amazonaws.com"
  6. clientId = "c-sdk-client-id"
  7. port = "443"
  8. rootCAPath = "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsFADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24gUm9vdCBDQSA$
  9. privateKeyPath = "2a5c7ce20d-private.pem.key"
  10. certificatePaht = "2a5c7ce20d-certificate.pem.key"
  11. topic = "Raspberry/1"
  12. message = "ABC WE'RE DONE WITH THIS"
  13.  
  14. #Custom MQTT message callback
  15. def customCallback(client, userdata, message):
  16.    print("Received a new message: ")
  17.    print(message.payload)
  18.    print("from topic: ")
  19.    print(message.topic)
  20.    print("--------------\n\n")
  21.  
  22. #initialize
  23. myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId) #clientId can be anything
  24. myAWSIoTMQTTClient.configureEndpoint(host, port) #host is your Pi’s AWS IoT Endpoint, port is 8883
  25. myAWSIoTMQTTClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
  26.  
  27. #AWSIoTMQTTClient connection configuration
  28. myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
  29. myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
  30. myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
  31. myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
  32. myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top