eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
314 stars 179 forks source link

MQTT-SN Gateway doesn't work on Ubuntu 64 bit for ARM64 #177

Closed Vitaliy69 closed 4 years ago

Vitaliy69 commented 4 years ago

I compiled the MQTTSNGateway from the develop branch (7 Feb 2020). It's work fine on Fedora 29, but doesn't work on ARM64 (Odroid N2 with Ubuntu x64).

uname -v
Linux odroid 4.9.210-66 #1 SMP PREEMPT Thu Jan 16 09:14:42 -03 2020 aarch64 aarch64 aarch64 GNU/Linux

lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              6
On-line CPU(s) list: 0-5
Thread(s) per core:  1
Core(s) per socket:  3
Socket(s):           2
Vendor ID:           ARM
Model:               4
Model name:          Cortex-A53
Stepping:            r0p4
CPU max MHz:         1896.0000
CPU min MHz:         100.0000
BogoMIPS:            48.00

ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:1e:06:44:0d:10 brd ff:ff:ff:ff:ff:ff

iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

I used default config file (with change Broker Name to 127.0.0.1, used Mosquitto as broker).

Starting log:

./MQTT-SNGateway 

 ***************************************************************************
 * MQTT-SN Transparent Gateway
 * Part of Project Paho in Eclipse
 * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)
 *
 * Author : Tomoaki YAMAGUCHI
 * Version: 1.3.1
 ***************************************************************************

20200207 224440.811 PahoGateway-01 has been started.

 ConfigFile: ./gateway.conf
 PreDefFile: ./predefinedTopic.conf
 SensorN/W:  UDP Multicast 225.1.1.1:1883 Gateway Port 10000
 Broker:     127.0.0.1 : 1883, 8883
 RootCApath: (null)
 RootCAfile: (null)
 CertKey:    (null)
 PrivateKey: (null)

Any ideas how to fix it? Some platform dependent code? Or network interface error?

I use only network messaging (tested with CONNECT and PUBLISH).

Also I have 100% CPU usage with MQTTSNGateway on Ondroid N2.

ty4tw commented 4 years ago

Hi, The GW can run on a RaspberryPi 3B+. So, it's not a problem of ARM64. what kind of client did you use?

Vitaliy69 commented 4 years ago

Hm, may be problen in Odroid N2? I can provide SSH for debugging if needed.

I send data from https://github.com/eclipse/paho.mqtt-sn.embedded-c/tree/master/MQTTSNPacket library and gei in on Node.red. But it's not a client problem, because Gateway output window is empty.

ty4tw commented 4 years ago

Could you monitor UDP packets with a Wireshark or any other network monitor ? I'd like to know the Gateway receives packets or not.

Vitaliy69 commented 4 years ago

Hello! Yes, gateway receives packets fine, but no any reaction.

root@odroid:~# tcpdump udp port 10000 -vv -X -n
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
17:12:36.000531 IP (tos 0x0, ttl 128, id 11019, offset 0, flags [none], proto UDP (17), length 50)
    192.168.1.250.52665 > 192.168.1.100.10000: [udp sum ok] UDP, length 22
    0x0000:  4500 0032 2b0b 0000 8011 8b01 c0a8 01fa  E..2+...........
    0x0010:  c0a8 0164 cdb9 2710 001e 600d 1604 0401  ...d..'...`.....
    0x0020:  000a 4e56 4744 6576 3633 3737 3837 3437  ..NVGDev63778747
    0x0030:  3733                                     73
17:12:37.464435 IP (tos 0x0, ttl 128, id 11020, offset 0, flags [none], proto UDP (17), length 138)
    192.168.1.250.52665 > 192.168.1.100.10000: [udp sum ok] UDP, length 110
    0x0000:  4500 008a 2b0c 0000 8011 8aa8 c0a8 01fa  E...+...........
    0x0010:  c0a8 0164 cdb9 2710 0076 a733 6e0c 0273  ...d..'..v.3n..s
    0x0020:  6400 007b 2249 4422 3a22 3633 3737 3837  d..{"ID":"637787
    0x0030:  3437 3733 222c 2254 5322 3a22 3135 3831  4773","TS":"1581
    0x0040:  3037 3530 3633 222c 224d 4422 3a22 3022  075063","MD":"0"
    0x0050:  2c22 4254 223a 2236 322e 3339 222c 2242  ,"BT":"62.39","B
    0x0060:  5222 3a22 3338 3236 3122 2c22 5254 223a  R":"38261","RT":
    0x0070:  2231 3632 222c 2253 5322 3a22 2d37 3522  "162","SS":"-75"
    0x0080:  2c22 4e4d 223a 2232 227d                 ,"NM":"2"}

Снимок экрана от 2020-02-21 17-12-49 Снимок экрана от 2020-02-21 17-12-44

ty4tw commented 4 years ago

Hi, I understand that UDP port 10000 is receiving CONNECT messages starting with 0x001e.

image

However, I do not know why the GW can not receive it. Could you try again with the latest version of GW ?

Vitaliy69 commented 4 years ago

Compiled the latest version from develop branch:

git rev-list --count HEAD
216

But the same behavior:

root@odroid:/home/src# ./MQTT-SNGateway 
ClientList can not open the Predefined Topic List.     NO

 ***************************************************************************
 * MQTT-SN Transparent Gateway
 * Part of Project Paho in Eclipse
 * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)
 *
 * Author : Tomoaki YAMAGUCHI
 * Version: 1.3.2
 ***************************************************************************

20200222 185220.305 PahoGateway-01 has been started.

 ConfigFile: ./gateway.conf
 ClientList: ./clients.conf
 PreDefFile: ./predefinedTopic.conf
 SensorN/W:  UDP Multicast 225.1.1.1:1883 Gateway Port 10000 TTL: 1
 Broker:     127.0.0.1 : 1883, 8883
 RootCApath: (null)
 RootCAfile: (null)
 CertKey:    (null)
 PrivateKey: (null)

MQTT Connect playload: 16 04 04 01 00 0A 4E 56 47 44 65 76 36 33 37 37 38 37 34 37 37 33, it's work fine on desktop PC with Fedora, but nothing on Odroid. (((

Ok. Will you make a debug version for me with the collection of additional logs in a separate git branch? I will attach all the necessary logs. TIA!

ty4tw commented 4 years ago

I fixed the bug of "ClientList can not open the Predefined Topic List. " I can't solve this issue because I don't have Odroid or I don't know anything about it.

ty4tw commented 4 years ago

My Rasbian was 32 bit. So, I checked GW with ubuntu 64-bit version and the bug was reproduced. image This is not a problem of Odroid.

ty4tw commented 4 years ago

The GW can send ADVERTISE message. And a client can receive ADVERTISE from the GW.
This issue might be a UDP receive problem. image It must be a ARM64 compiler related problem.

Vitaliy69 commented 4 years ago

Hello! I corrected the bug title description.

I checked the latest version on Odroid N2 (Ubuntu 18.04 x86_64):

git rev-list --count HEAD
218

When I send via console:

echo -n -e "\x016\x004\x004\x001\x000\x00A\x04E\x056\x047\x044\x065\x076\x036\x033\x037\x037\x038\x037\x034\x037\x037\x033" | nc -u 192.168.1.100 10000

I got the error:

20200225 134710.069   UNKNOWN           <---  Unknown Client !                    01 36 00 34 00 34 00 31 00 30 00 41 04 45 05 36 04 37 04 34 06 35 07 36 03 36 03 33 03 37 03 37 03 38 03 37 03 34 03 37 03 37 03 33
Error: MQTTSNGWClientRecvTask  Client(192.168.1.10:53839) is not connecting. message has been discarded.

But I tested on the real NB IoT device (GPS tracker with data send via MQTT SN on MTS RUS) and seems it works fine (checked CONNECT, CONACK, PUBLISH, SUBSCRIBE, SUBAC):

Снимок экрана от 2020-02-25 13-46-39

Suppose bug is fixed. Thank you!

ty4tw commented 4 years ago

Thank you for your contribution.