Beispiel #1
0

########################################

#======================================
# AWS IoT SDK - MQTT Client connection
#======================================
myAWSIoTMQTTClient = AWSIoTMQTTClient(thingName)
myAWSIoTMQTTClient.configureEndpoint(awsEndpoint, awsPortNumber)
myAWSIoTMQTTClient.configureCredentials(awsRootCAPath, awsIoTPrivateKeyPath,
                                        awsIoTCertificatePath)
myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)

# Last will payload for disconnection
lastWillPayload = '{"recordType":"Device","deviceStatus":"Disconnected"}'
myAWSIoTMQTTClient.configureLastWill(awsTopicPrefix + thingName,
                                     lastWillPayload, 0)

# Connect

myAWSIoTMQTTClient.connect()
updateDeviceStatus("Connected")
dateTimeObj = datetime.now()
print("Device is connected at " + str(datetime.now()))

previous_status = 2

# Listen to door sensor and publish

while True:
    if (previous_status != GPIO.input(pinNumber)):
        if (GPIO.input(pinNumber) == 1):
Beispiel #2
0
import json
import time

#Setup our MQTT client and security certificates
#Make sure your certificate names match what you downloaded from AWS IoT

#Function to encode a payload into JSON
def json_encode(string):
        return json.dumps(string)

#Creating last will message and encoding
lastWill = "Help I have disconnected"
lastWill = json_encode(lastWill)

mqttc = AWSIoTMQTTClient("1234")

#Make sure you use the correct region!
mqttc.configureEndpoint("data.iot.us-west-2.amazonaws.com",8883)
mqttc.configureCredentials("./rootCA.pem","./ratchet/ratchet.private.key","./ratchet/ratchet.cert.pem")
mqttc.configureLastWill("lwt", lastWill, 1)


mqttc.connect()
print("Connected")
print("Press Control + C to Crash")

# Loop forever
while True:
        pass

Beispiel #3
0
    print("--------------\n\n")


# configure the MQTT client
pycomAwsMQTTClient = AWSIoTMQTTClient(config.CLIENT_ID)
pycomAwsMQTTClient.configureEndpoint(config.AWS_HOST, config.AWS_PORT)
pycomAwsMQTTClient.configureCredentials(config.AWS_ROOT_CA,
                                        config.AWS_PRIVATE_KEY,
                                        config.AWS_CLIENT_CERT)

pycomAwsMQTTClient.configureOfflinePublishQueueing(config.OFFLINE_QUEUE_SIZE)
pycomAwsMQTTClient.configureDrainingFrequency(config.DRAINING_FREQ)
pycomAwsMQTTClient.configureConnectDisconnectTimeout(
    config.CONN_DISCONN_TIMEOUT)
pycomAwsMQTTClient.configureMQTTOperationTimeout(config.MQTT_OPER_TIMEOUT)
pycomAwsMQTTClient.configureLastWill(config.LAST_WILL_TOPIC,
                                     config.LAST_WILL_MSG, 1)

#Connect to MQTT Host
if pycomAwsMQTTClient.connect():
    print('AWS connection succeeded')

# Subscribe to topic
pycomAwsMQTTClient.subscribe(config.TOPIC, 1, customCallback)
time.sleep(2)

# configure pysense
py = Pysense()
si = SI7006A20(py)

# Send message to host
loopCount = 0
Beispiel #4
0
    else:
        stopThread = False
        x = threading.Thread(target=thread_function, args=(int(time.time()), ))
        x.start()


myAWSIoTMQTTClient = AWSIoTMQTTClient(thingName, cleanSession=False)
myAWSIoTMQTTClient.configureEndpoint(
    "a1f18ishzwlosz-ats.iot.ap-southeast-2.amazonaws.com", 8883)

myAWSIoTMQTTClient.configureCredentials("./AmazonRootCA1.pem",
                                        "./90b9981671-private.pem.key",
                                        "./90b9981671-certificate.pem.crt")
myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)
lastWillPayload = '{"errorType":"Device","deviceID":"' + thingName + '"}'
myAWSIoTMQTTClient.configureLastWill("LNH_ALARM", lastWillPayload, 0)

myAWSIoTMQTTClient.connect()

previous_status = 2
while True:
    print(GPIO.input(pinNumber))
    if (previous_status != GPIO.input(pinNumber)):
        if (GPIO.input(pinNumber) == 1):
            print("I am sending message door is open")
            updateDoorStatus("OPEN")
        else:
            print("I am sending message door is closed")
            updateDoorStatus("CLOSE")
        previous_status = GPIO.input(pinNumber)