Errno 32管道破裂的Azure IOT边缘

问题描述 投票:0回答:1

我一直收到管道破裂的错误,并且不确定IOT边缘的故障。它将在没有收到任何信息之前发出8-9个发布。 我将IOT边缘容器托管在与其连接的同一设备上。这会引起问题吗?

错误消息

log: Sending PUBLISH (d0, q0, r0, m1), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m2), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m3), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m4), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m5), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m6), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m7), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: Sending PUBLISH (d0, q0, r0, m8), 'b'devices/vehicleRPM/messages/events/'', ... (1 bytes)
log: failed to receive on socket: [Errno 32] Broken pipe

这是我的联系方式

        self.device_id = device_id

        self.client = mqtt.Client(client_id=device_id, protocol=mqtt.MQTTv311,  clean_session=False)
        self.client.on_log = on_log
        self.client.tls_set(ca_certs="/home/pi/RTT/Pi/kerts/certs/azure-iot-test-only.root.ca.cert.pem", cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1, ciphers=None)
        self.client.tls_insecure_set(False)        # self.client.tls_set(cert_reqs=ssl.CERT_NONE)
        self.username = "{}.azure-devices.net/{}/api-version=2018-06-30".format(self.iot_hub_name, self.device_id)
        self.client.username_pw_set(username=self.username, password=self.sas_token)

        # Connect to the Azure IoT Hub
        self.client.on_connect = on_connect
        self.client.connect("raspberrypi", port=8883)

        # Subscribing on the topic ,
        self.client.on_message = on_message
        self.client.on_subscribe = on_subscribe
        self.client.subscribe("devices/{device_id}/messages/devicebound/#".format(device_id=device_id))
        self.client.subscribe("$iothub/twin/PATCH/properties/desired/#")
        self.client.subscribe("$iothub/methods/POST/#")

    def _SendMessage(self, payload):
        self.client.publish("devices/{device_id}/messages/events/".format(device_id=self.device_id), payload=payload, qos=0, retain=False)

这是我在物联网边缘连接时看到的。

Mar 01 21:26:42 raspberrypi iotedged[1034]: 2020-03-01T21:26:42Z [INFO] - [mgmt] - - - [2020-03-01 21:26:42.908760673 UTC] "GET /modules?api-version=2019-01-30 HTTP/1.1" 200 OK 1043 "-" "-" auth_id(-)
Mar 01 21:26:47 raspberrypi iotedged[1034]: 2020-03-01T21:26:47Z [INFO] - [mgmt] - - - [2020-03-01 21:26:47.934428600 UTC] "GET /modules?api-version=2019-01-30 HTTP/1.1" 200 OK 1043 "-" "-" auth_id(-)

Mar 01 21:26:48 raspberrypi iotedged[1034]: 2020-03-01T21:26:48Z [INFO] - [work] - - - [2020-03-01 21:26:48.543634841 UTC] "POST /modules/%24edgeHub/genid/{number}/sign?api-version=2019-01-30 HTTP/1.1" 200 OK 57 "-" "-" auth_id(-)
Mar 01 21:26:49 raspberrypi iotedged[1034]: 2020-03-01T21:26:49Z [INFO] - [work] - - - [2020-03-01 21:26:49.011628265 UTC] "POST /modules/%24edgeHub/genid/{same number}/encrypt?api-version=2019-01-30 HTTP/1.1" 200 OK 569 "-" "-" auth_id(-)

Mar 01 21:26:52 raspberrypi iotedged[1034]: 2020-03-01T21:26:52Z [INFO] - [mgmt] - - - [2020-03-01 21:26:52.953183647 UTC] "GET /modules?api-version=2019-01-30 HTTP/1.1" 200 OK 1043 "-" "-" auth_id(-)
Mar 01 21:26:57 raspberrypi iotedged[1034]: 2020-03-01T21:26:57Z [INFO] - [mgmt] - - - [2020-03-01 21:26:57.983174061 UTC] "GET /modules?api-version=2019-01-30 HTTP/1.1" 200 OK 1043 "-" "-" auth_id(-)
Mar 01 21:27:03 raspberrypi iotedged[1034]: 2020-03-01T21:27:03Z [INFO] - [mgmt] - - - [2020-03-01 21:27:03.013862166 UTC] "GET /modules?api-version=2019-01-30 HTTP/1.1" 200 OK 1043 "-" "-" auth_id(-)
Mar 01 21:27:08 raspberrypi iotedged[1034]: 2020-03-01T21:27:08Z [INFO] - [mgmt] - - - [2020-03-01 21:27:08.041568988 UTC] "GET /modules?api-version=2019-01-30 HTTP/1.1" 200 OK 1043 "-" "-" auth_id(-)
azure-iot-hub paho azure-iot-edge
1个回答
0
投票

http://busbyland.com/connect-mqtt-client-to-azure-iot-edge/中的代码有效!我不确定与我的有什么不同,但是现在完全像这样实现就可以了!

from paho.mqtt import client as mqtt
import ssl

import time

path_to_root_cert = '[path to root CA cert]' # e.g. './azure-iot-test-only.root.ca.cert.pem'
device_id = "[iot device id]" # e.g. "myIoTDevice"
sas_token = "[generated SAS token]" # e.g. SharedAccessSignature sr=exampleIotHub.azure-devices.net%2Fdevices%2FmyIoTDevice&sig=8%2Fo6sdsFE%2BplYLQJrxIo5Usx1iVV0gnySaVhkh7aNOk%3D&se=1563635795"
iot_hub_name = "[iothub short name]" #e.g. exampleIoTHub

#EDGE - the FQDN of the device.. for example: myedgedevice.local
edge_device_name = "[edge device name]"

def on_connect(client, userdata, flags, rc):
print ("Device connected with result code: " + str(rc))
def on_disconnect(client, userdata, rc):
print ("Device disconnected with result code: " + str(rc))
def on_publish(client, userdata, mid):
print ("Device sent message")

client = mqtt.Client(client_id=device_id, protocol=mqtt.MQTTv311)

client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_publish = on_publish

#EDGE - we need to add the + "/api-version=2016-11-14" (api version) to the end of the username. Technically, you can do this if you are
# talking directly to IoTHub as well, but it's optional. Edge seems to require it.
client.username_pw_set(username=iot_hub_name+".azure-devices.net/" + device_id + "/api-version=2016-11-14", password=sas_token)

client.tls_set(ca_certs=path_to_root_cert, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1, ciphers=None)
client.tls_insecure_set(False)

# start paho's background processing

client.loop_start()

#EDGE - although we are still authenticating to IoTHub with the IoTHub based SAS token, we are actually connecting
# to IoT Edge device's MQTT endpoint

client.connect(edge_device_name, port=8883)

i=0

while(True):

payload = "{"message_id": %d}" % (i)

client.publish("devices/" + device_id + "/messages/events/", payload, qos=1)

time.sleep(5)

i=i+1
© www.soinside.com 2019 - 2024. All rights reserved.