Iotedge: Publish and subscribe with Azure IoT Edge Not Working

Created on 22 Dec 2020  Â·  3Comments  Â·  Source: Azure/iotedge

Hi
i am experimenting with Azure IoT Edge MQTT broker to publish and subscribe
from below link : https://docs.microsoft.com/en-us/azure/iot-edge/how-to-publish-subscribe?view=iotedge-2020-11#pre-requisites

i am able to connect to broker but i am not seeing published messages in subscriber end

Egde Runtime Version :
iotedge 1.2.0~rc1

Edgehub and EdgeAgent :

CONTAINER ID        IMAGE                                            COMMAND                   CREATED             STATUS              PORTS                                                                                          NAMES
801cb4bf7c5b        mcr.microsoft.com/azureiotedge-hub:1.2.0-rc1     "/bin/sh -c 'echo \"$…"   13 hours ago        Up 38 minutes       0.0.0.0:443->443/tcp, 0.0.0.0:1883->1883/tcp, 0.0.0.0:5671->5671/tcp, 0.0.0.0:8883->8883/tcp   edgeHub
22f439fa0e4c        mcr.microsoft.com/azureiotedge-agent:1.2.0-rc1   "/bin/sh -c 'exec /a…"    3 days ago          Up 38 minutes                                                                                                      edgeAgent

Deployment json

{
  "$schema-template": "2.0.0",
  "modulesContent": {
    "$edgeAgent": {
      "properties.desired": {
        "schemaVersion": "1.0",
        "runtime": {
          "type": "docker",
          "settings": {
            "minDockerVersion": "v1.25",
            "loggingOptions": "",
            "registryCredentials": {}
          }
        },
        "systemModules": {
          "edgeAgent": {
            "type": "docker",
            "settings": {
              "image": "mcr.microsoft.com/azureiotedge-agent:1.2.0-rc1",
              "createOptions": {}
            }
          },
          "edgeHub": {
            "type": "docker",
            "status": "running",
            "env": {
              "experimentalFeatures__enabled": {
                  "value": "true"
              },
              "experimentalFeatures__mqttBrokerEnabled": {
                  "value": "true"
              }
           },
            "restartPolicy": "always",
            "settings": {
              "image": "mcr.microsoft.com/azureiotedge-hub:1.2.0-rc1",
              "createOptions": {
                "HostConfig": {
                  "PortBindings": {
                    "5671/tcp": [
                      {
                        "HostPort": "5671"
                      }
                    ],
                    "8883/tcp": [
                      {
                        "HostPort": "8883"
                      }
                    ],
                    "443/tcp": [
                      {
                        "HostPort": "443"
                      }
                    ],
                    "1883/tcp": [
                      {
                        "HostPort": "1883"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "modules": {
          "TemperatureSensorModule": {
            "version": "1.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULES.TemperatureSensorModule}",
              "createOptions": {}
            }
          }
        }
      }
    }, 
      "$edgeHub":{
         "properties.desired":{
            "schemaVersion":"1.2",
            "routes":{
              "Route1":"FROM /messages/* INTO $upstream"
           },
           "storeAndForwardConfiguration":{
              "timeToLiveSecs":7200
           },
            "mqttBroker":{
              "authorizations":[
                {
                   "identities": [
                      "{{iot:identity}}"
                   ],
                   "allow":[
                      {
                         "operations":[
                            "mqtt:connect"
                         ]
                      }
                   ]
                },
                {
                   "identities": [
                      "<iothub>.azure-devices.net/sub_client"
                   ],
                   "allow":[
                      {
                         "operations":[
                            "mqtt:subscribe"
                         ],
                         "resources":[
                            "test_topic"
                         ]
                      }
                   ]
                },
                {
                   "identities": [
                      "<iothub>.azure-devices.net/pub_client"
                   ],
                   "allow":[
                      {
                         "operations":[
                            "mqtt:publish"
                         ],
                         "resources":[
                            "test_topic"
                         ]
                      }
                   ]
                }
             ]
            }
         }
      }
  }
}
mqtt customer-reported iotedge question

All 3 comments

Hi @lakshmisivareddy, thanks for you interest in Azure IoT Edge MQTT broker. I took a look at your deployment file and I have a few suggestions:

  • please use the latest version of edgehub and edgeagent images - 1.2.0-rc2
  • It is not clear whether you've redacted the iothub name for privacy, but please make sure that you actually use real iothub name instead of <iothub>.azure-devices.net in authorization policy.
                   "identities": [
                      "<iothub>.azure-devices.net/sub_client"
                   ],

If you still experience the issue, please share the edgehub logs at the time of the issue. Also, it would be great if you can share the logs from clients that you use to publish/subscribe. If you use mosquitto clients, please run them with -d parameter to get the trace.

Hi @vadim-kovalyov
Thanks for the Response.
it is working with Edgehub: 1.2.0-rc2

Hi @vadim-kovalyov
i tried setting up mqtt broker in edgehub and able to test it with SAS token
but when i was trying with x509 certificate i am getting Error
can u please help us understand why ssl handshakes falling with edgeMqtt Broker

Error Message

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)

edge runtime version

iotedge runtime : iotedge 1.2.0~rc1

edgeHub and edgeAgent version:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8487c368cf5 mcr.microsoft.com/azureiotedge-hub:1.2.0-rc2 "/bin/sh -c 'echo \"$…" 3 hours ago Up About an hour 0.0.0.0:443->443/tcp, 0.0.0.0:1883->1883/tcp, 0.0.0.0:5671->5671/tcp, 0.0.0.0:8883->8883/tcp edgeHub
305ff643a56a mcr.microsoft.com/azureiotedge-agent:1.2.0-rc2 "/bin/sh -c 'exec /a…" 3 hours ago Up About an hour edgeAgent

please find the code :

from paho.mqtt import client as mqtt
import ssl

path_to_root_cert = "/home/challal/Downloads/cacert.pem" # Baltimore CyberTrust Root

path_to_root_cert = "/home/challal/Downloads/certs/azure-iot-test-only.root.ca.cert.pem"

device_id = "pub_cert"

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,clean_session=True,userdata=None,protocol=mqtt.MQTTv311,transport="tcp")

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

client.username_pw_set(username="WE-SB-DEV-SC-iothub02.azure-devices.net/pub_cert/?api-version=2018-06-30", password=None)

cert_file = "/home/challal/Downloads/pub_cert/new-device.cert.pem"
key_file = "/home/challal/Downloads/pub_cert/new-device.key.pem"
client.tls_set(ca_certs=path_to_root_cert, certfile=cert_file, keyfile=key_file,
cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)

client.connect("WE-SB-DEV-SC-iothub02.azure-devices.net", 8883,60)

client.publish("devices/pub_cert/messages/events/", "{id=123}", qos=1)

client.connect("localhost", 8883,60)
client.publish("test_topic", "{id=123}", qos=1)
client.loop_forever()

Was this page helpful?
0 / 5 - 0 ratings