kyberpunk / openthread-mqttsn

This repository contains examples using MQTT-SN client implementation for Thread network based on OpenThread SDK.
BSD 3-Clause "New" or "Revised" License
30 stars 4 forks source link

Can not subscribe and publish #27

Open L1amaGod opened 10 months ago

L1amaGod commented 10 months ago

I have finished mqtt connection between my mqtt-sn client device and mqtt-sn gateway, everything is ok but when I tried to make my cli device publish "sensors" message, it failed. Logs are below. 60aab0b90700eaef068c18b5cae534f

L1amaGod commented 10 months ago

It seems that I didn't make my docker mosquitto connect to mqtt-sn gateway(paho) normally? image

L1amaGod commented 10 months ago

@kyberpunk Could you please help me have a look? Thank you so much!

kyberpunk commented 10 months ago

Hi @L1amaGod , I will check it today. My quick assumption is, that client didn't se to correctly connect message. What client code do you use? Is it my OpenThread fork or you have your own?

L1amaGod commented 10 months ago

Hi @kyberpunk , I use your OpenThread fork, I followed this README.md to do. The only difference is that I use nrf52840dk to act as mqttsn client instead of KW41Z. It seems that I didn't make my docker mosquitto connect to mqtt-sn gateway(paho) normally. Because when I wanted to send test message with mosquitto_pub from mosquitto Docker container, I didn't see any log about mosquitto docker on paho docker(sudo docker logs paho -f). But I can get logs about publishing from mqtt-sn client on paho when I published a message from the mqtt-sn client even it would fail.

image

kyberpunk commented 10 months ago

Gateway log output should contain CONNECT and CONACK message. Did you see connected output in client CLI (if you use cli?)? It it also possible that gateway was restarted afterwards, the it forget all connections and client must reconnect, usually after pingreq timeout. Screenshot 2024-01-09 205502

L1amaGod commented 10 months ago

Yes, it does contain CONNECT and CONACK message, the connection between mqtt-sn client and mqtt-sn gateway looks like normal. I think the problem is on the connection between docker mosquitto and mqtt-sn gateway.

9e396b34adda4debb50e528933c99ed

kyberpunk commented 10 months ago

@L1amaGod Second screenshot you sent seems to be related to restart, since PINGREQ is received after startup of the gateway. But you are right, the first case seems that upstream broker disconnected the device. However, it is not clear why. Can you please check and send also logs from mosquitto if it gives any hints? I can imagine timeouts or invalid publish message or something similar. My setup works ok.

L1amaGod commented 10 months ago

@kyberpunk Sorry to reply so late.

Logs of mosquitto show theses every time when I make mosquitto docker publishes message:

1705646763: New connection from 127.0.0.1 on port 1883.
1705646763: New client connected from 127.0.0.1 as mosq-Bmbb4MlAXcUaiPwSHw (p2, c1, k60).
1705646763: Client mosq-Bmbb4MlAXcUaiPwSHw disconnected.

2cb82482e9590ed9866bf32e076f68e

BTW, it seems that PINGREQ will appear about every 20~30 seconds. I don't know if it is normal.I tend to believe that it is heartbeat report. image

kyberpunk commented 10 months ago

I think that mosquitto log just shows the docker client which just sends publish message and disconnects immediately, that's correct behavior. Ping messages are also ok, that's for keeping the UDP "connection" alive. I'm just thinking what can we do more. Could you please send whole configuration files (as file) of mosquitto broker and paho gateway? If you could also send your binary which you flash on nRF52840, I could try to reproduce your setup.

L1amaGod commented 10 months ago

I don't know whether these are the configuration of mosquitto broker and paho gateway or not? Could you please tell me where the configuration files are? And I have uploaded my binary of nRF52840DK.ot-cli-ftd-mqtt-52840dk.zip

ubuntu@ubuntu20:/etc/docker$ sudo docker container inspect mosquitto
[
    {
        "Id": "71d31e775980d3e8e4df87b37e144cc052cad9a7ec713649f1367f9b3b5e5103",
        "Created": "2024-01-05T08:25:20.901117571Z",
        "Path": "/usr/local/sbin/mosquitto",
        "Args": [
            "-c",
            "/etc/mosquitto/mosquitto.conf"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-01-19T06:38:29.674200798Z",
            "FinishedAt": "2024-01-19T10:35:43.391508625Z"
        },
        "Image": "sha256:caec9d73d3dc7cfd90b690593efc55144538cf1c720c85fd0a45d0edbcebc2d7",
        "ResolvConfPath": "/var/lib/docker/containers/71d31e775980d3e8e4df87b37e144cc052cad9a7ec713649f1367f9b3b5e5103/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/71d31e775980d3e8e4df87b37e144cc052cad9a7ec713649f1367f9b3b5e5103/hostname",
        "HostsPath": "/var/lib/docker/containers/71d31e775980d3e8e4df87b37e144cc052cad9a7ec713649f1367f9b3b5e5103/hosts",
        "LogPath": "/var/lib/docker/containers/71d31e775980d3e8e4df87b37e144cc052cad9a7ec713649f1367f9b3b5e5103/71d31e775980d3e8e4df87b37e144cc052cad9a7ec713649f1367f9b3b5e5103-json.log",
        "Name": "/mosquitto",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "otbr_test_90",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                59,
                198
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/f702710b8b88468be7d83b9dcc5a112974bd90cb78d167b485db19eb658d8163-init/diff:/var/lib/docker/overlay2/624dfd44308ff0551b7f9a2c7e930476ce16ffa3dc72f541415382044cb8ef1e/diff:/var/lib/docker/overlay2/78a87a6005ddc853b6231cbeb560199afade0f0fe968832f8e350ad5596fda8c/diff:/var/lib/docker/overlay2/79736224597a6b976f711964601e08f1b8e1a96bcfa584618629824d115939ff/diff:/var/lib/docker/overlay2/7f76e6aac9f73a98bc1051a00279705501b9e47899bb01ee14ef93c080faf9d3/diff:/var/lib/docker/overlay2/6ada84a049658f8a19db4b4dc703e8bd884316ad2beea622c2c9aa26bf57104b/diff:/var/lib/docker/overlay2/c768a8abcc4b7ce220639f48e6dc013cb6fbbf939a370929e6d0221ad063398e/diff:/var/lib/docker/overlay2/1b75bf5edffe7620f57f9af56ca12629538c9ce92787939358f7109e617a1f9f/diff",
                "MergedDir": "/var/lib/docker/overlay2/f702710b8b88468be7d83b9dcc5a112974bd90cb78d167b485db19eb658d8163/merged",
                "UpperDir": "/var/lib/docker/overlay2/f702710b8b88468be7d83b9dcc5a112974bd90cb78d167b485db19eb658d8163/diff",
                "WorkDir": "/var/lib/docker/overlay2/f702710b8b88468be7d83b9dcc5a112974bd90cb78d167b485db19eb658d8163/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "71d31e775980",
            "Domainname": "",
            "User": "docker",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "1883/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Image": "kyberpunk/mosquitto",
            "Volumes": null,
            "WorkingDir": "/app/mosquitto",
            "Entrypoint": [
                "/usr/local/sbin/mosquitto",
                "-c",
                "/etc/mosquitto/mosquitto.conf"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "507d583fe035dfb0cee7a41b92e0474a83ee2d3b3ec7692166143535f695dcfc",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/507d583fe035",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "otbr_test_90": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "71d31e775980"
                    ],
                    "NetworkID": "d73d534dc7fdc04e31669313241c406fcbc0569dc16d5a8ace78b24cfb3be0e7",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]
ubuntu@ubuntu20:~$ sudo docker container inspect paho
[
    {
        "Id": "674d1f234cd3c14ce3e320660263ad3b90b52ab934c7494dd4c2846e534804f4",
        "Created": "2024-01-05T08:36:11.532995518Z",
        "Path": "/app/paho/MQTTSNGateway/docker_entrypoint.sh",
        "Args": [
            "--broker-name",
            "mosquitto",
            "--broker-port",
            "1883"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 137,
            "Error": "",
            "StartedAt": "2024-01-19T06:38:34.616728119Z",
            "FinishedAt": "2024-01-19T10:35:53.251340088Z"
        },
        "Image": "sha256:676c409c421f992fa177e032a1cc530d86cb4669b797f9d0813f8ea7ecbb4742",
        "ResolvConfPath": "/var/lib/docker/containers/674d1f234cd3c14ce3e320660263ad3b90b52ab934c7494dd4c2846e534804f4/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/674d1f234cd3c14ce3e320660263ad3b90b52ab934c7494dd4c2846e534804f4/hostname",
        "HostsPath": "/var/lib/docker/containers/674d1f234cd3c14ce3e320660263ad3b90b52ab934c7494dd4c2846e534804f4/hosts",
        "LogPath": "/var/lib/docker/containers/674d1f234cd3c14ce3e320660263ad3b90b52ab934c7494dd4c2846e534804f4/674d1f234cd3c14ce3e320660263ad3b90b52ab934c7494dd4c2846e534804f4-json.log",
        "Name": "/paho",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "otbr_test_90",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                59,
                198
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/798a04df891ddbf362ba03cc18442ac632e33f39786622a0803b300529d2bc77-init/diff:/var/lib/docker/overlay2/1248bf72fa3dfacde6ef6db724277a0d61fb1b91e695a8e08eff2b71cc1fb784/diff:/var/lib/docker/overlay2/f6e4eaf33764950bc5a3b170f64d48e5f4c818c32c47e18d8eca248a8d1b2b4a/diff:/var/lib/docker/overlay2/c1c1d7983f95dd1b6ab5bc5735be784f917fe2f27572fbed96d1cb8b40b05d84/diff:/var/lib/docker/overlay2/befa0b701e1cc506c4de9b343f733928638d1eff0ca70706f41d88f0f1f55ab7/diff:/var/lib/docker/overlay2/2b48c6c19b5b0c53d0820a1523e8512c07d6ea57245db15b1ee01bd0f65390c5/diff:/var/lib/docker/overlay2/41d2d0a96ed97642ea7327d6e03c94ada7edfcdb1e043cce7ba817b90e5ea343/diff:/var/lib/docker/overlay2/b7f37aa5a0482821b19d6bd8e82037dcb78827e97dd480f937455497296a02ac/diff:/var/lib/docker/overlay2/21bcba613444312c19fc307a6b0c5c76f49fe15a6c0cff1405114ef2241f0535/diff",
                "MergedDir": "/var/lib/docker/overlay2/798a04df891ddbf362ba03cc18442ac632e33f39786622a0803b300529d2bc77/merged",
                "UpperDir": "/var/lib/docker/overlay2/798a04df891ddbf362ba03cc18442ac632e33f39786622a0803b300529d2bc77/diff",
                "WorkDir": "/var/lib/docker/overlay2/798a04df891ddbf362ba03cc18442ac632e33f39786622a0803b300529d2bc77/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "674d1f234cd3",
            "Domainname": "",
            "User": "docker",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "10000/tcp": {},
                "10000/udp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "--broker-name",
                "mosquitto",
                "--broker-port",
                "1883"
            ],
            "Image": "kyberpunk/paho",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/app/paho/MQTTSNGateway/docker_entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "deb36c6a2c7bc81d19df4a7986c7422e5856eccd75d301fa8c367f061300d636",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/deb36c6a2c7b",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "otbr_test_90": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "674d1f234cd3"
                    ],
                    "NetworkID": "d73d534dc7fdc04e31669313241c406fcbc0569dc16d5a8ace78b24cfb3be0e7",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]