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

forwarder encapsulation does not work as expected #181

Closed martinkirsche closed 4 years ago

martinkirsche commented 4 years ago

I'm trying to use the MQTT-SN Gateway together with an MQTT-SN Forwarder that encapsulates each MQTT-Paket it receives. Even so the MQTT-SN Gateway seems to decapsulate the packages only establishing a connection works (CONNECT + CONNACK) but every command after that will produce the Client(127.0.0.1:22002) is not connecting. message has been discarded. error message.

I think the encapsulated MQTT-SN packages look like described at MQTT For Sensor Networks (MQTT-SN) Protocol Specification Version 1.2 part 5.5 Forwarder Encapsulation so I assume that this is a bug within the gateway.

Here is the log output of the gateway:

 ***************************************************************************
 * 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
 ***************************************************************************

20200213 221856.160 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:     localhost : 1883, 8883
 RootCApath: (null)
 RootCAfile: (null)
 CertKey:    (null)
 PrivateKey: (null)

20200213 221859.383   ENCAPSULATED      <---  Forwarder01                         05 FE 00 00 41 07 04 04 01 00 01 41

20200213 221859.383   CONNECT           <---  A                                   07 04 04 01 00 01 41
20200213 221859.385   CONNECT           ===>  A                                   10 0D 00 04 4D 51 54 54 04 02 00 01 00 01 41
20200213 221859.665   CONNACK           <===  A                                   20 02 00 00
20200213 221859.665   ENCAPSULATED      --->  Forwarder01                         FE 00 00 41 03 05 00
20200213 221859.665   CONNACK           --->  A                                   03 05 00
20200213 221859.666   ENCAPSULATED      <---  Forwarder01                         05 FE 00 00 42 07 04 04 01 00 01 42

20200213 221859.666   CONNECT           <---  B                                   07 04 04 01 00 01 42
20200213 221859.666   CONNECT           ===>  B                                   10 0D 00 04 4D 51 54 54 04 02 00 01 00 01 42
20200213 221900.165   CONNACK           <===  B                                   20 02 00 00
20200213 221900.165   ENCAPSULATED      --->  Forwarder01                         FE 00 00 42 03 05 00
20200213 221900.165   CONNACK           --->  B                                   03 05 00
20200213 221900.166   ENCAPSULATED      <---  Forwarder01                         05 FE 00 00 41 02 16

20200213 221900.166   PINGREQ           <---  Unknown Client !                    02 16
Error: Client(127.0.0.1:22002) is not connecting. message has been discarded.
20200213 221900.166   ENCAPSULATED      <---  Forwarder01                         05 FE 00 00 42 02 16

20200213 221900.166   PINGREQ           <---  Unknown Client !                    02 16
Error: Client(127.0.0.1:22002) is not connecting. message has been discarded.

I use the following python script to emulate the forwarder:

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("127.0.0.1", 22002))

sock.sendto(bytearray([0x05, 0xFE, 0x00, 0x00, 0x41, 0x07, 0x04, 0x04, 0x01, 0x00, 0x01, 0x41]), ("127.0.0.1", 10000))
print(sock.recvfrom(8))

sock.sendto(bytearray([0x05, 0xFE, 0x00, 0x00, 0x42, 0x07, 0x04, 0x04, 0x01, 0x00, 0x01, 0x42]), ("127.0.0.1", 10000))
print(sock.recvfrom(8))

sock.sendto(bytearray([0x05, 0xFE, 0x00, 0x00, 0x41, 0x02, 0x16]), ("127.0.0.1", 10000))
sock.sendto(bytearray([0x05, 0xFE, 0x00, 0x00, 0x42, 0x02, 0x16]), ("127.0.0.1", 10000))

print(sock.recvfrom(7))
print(sock.recvfrom(7))
ty4tw commented 4 years ago

Hi, Thank you for your info. I'll fix it soon.

martinkirsche commented 4 years ago

Hi, thanks for fixing it so fast. It works like a charm now.