channel.basic_publish(exchange='', routing_key='down_queue', body=body)


if __name__ == "__main__":
    connection = pika.BlockingConnection(
        pika.ConnectionParameters(
            host='localhost'))  #connection using localhost
    channel = connection.channel()
    mqtt_aws = None
    name_client = "temperature_humidity"
    host = "abb1xpjvw6x95-ats.iot.us-east-1.amazonaws.com"
    rootCAPath = "./certificates2/AmazonRootCA1.pem"
    privateKeyPath = "./certificates2/f2de2b0af7-private.pem.key"
    certificatePath = "./certificates2/f2de2b0af7-certificate.pem.crt"
    data_check = "temphumid"
    mqtt_aws = aws(name_client)
    up_topic = 'mqtt_upstream'
    down_topic = 'mqtt_downstream'
    mqtt_aws.configureEndpoint(host, 8883)
    mqtt_aws.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
    mqtt_aws.connect()
    calcthread = []  #threads for executing code parallely
    thread_ui = threading.Thread(target=System_UI)
    calcthread.append(thread_ui)
    thread_ui.start()
    coapthread = threading.Thread(target=Coap_server)
    calcthread.append(coapthread)
    coapthread.daemon = True
    coapthread.start()  #coap thread
    mqtt_thread = threading.Thread(target=func_mqtt)
    calcthread.append(mqtt_thread)
        ):  #show plot only in data collected points collected is more than 10
            self.label_4.setText(
                _translate("TemperatureQT", "Error: Data not sufficient"))
            return
        i = range(0, len(self.all_temp))
        pt1.plot(i, self.all_temp)  #plot temp data
        pt2.plot(i, self.all_humidity)  #plot humidity data
        pt1.show()  #show temperature graph
        pt2.show()  #show humidity graph


if __name__ == "__main__":
    mqtt_aws_client = None
    client_name = 'sensor_rpi'
    host = 'a1qcmx85kdext1.iot.us-east-2.amazonaws.com'
    rootCAPath = './certificates/root-CA.crt'
    key_private = './certificates/ri-mma.private.key'
    certificatePath = './certificates/rpi-mma.cert.pem'
    topic = 'aws_eidproject3'
    mqtt_aws_client = aws(client_name)
    mqtt_aws_client.configureEndpoint(host, 8883)
    mqtt_aws_client.configureCredentials(rootCAPath, key_private,
                                         certificatePath)
    mqtt_aws_client.connect()
    app = QtWidgets.QApplication(sys.argv)
    TemperatureQT = QtWidgets.QMainWindow()
    ui = Ui_TemperatureQT()
    ui.setupUi(TemperatureQT)
    TemperatureQT.show()
    sys.exit(app.exec_())