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
315 stars 178 forks source link

Multiple remarks #160

Closed jsaak closed 4 years ago

jsaak commented 5 years ago

I tried to replace the java version with this (c9e807da319bd68) I was hoping that it will be more stable, and performant. It is faster, but has many bugs unfortunately. These are the errors I found: (using g++ (Debian 4.9.2-10+deb8u1) 4.9.2, armhf)

  1. Could not find any documentation. (I was searching for different log levels, and log methods, setting a will message of the broker <-> gateway connection)

  2. Can not stop the gateway with Ctrl-C (SIGINT): While not connected to the MQTT broker.

    ^C20190718 081511.907 PacketHandleTask stopped.
    20190718 081511.907 ClientSendTask   stopped.
    20190718 081512.003 ClientRecvTask   stopped.
    20190718 081512.363 BrokerRecvTask   stopped.

    but after this, the gateway is still running

  3. When compiling:

    g++ -Wall -O3 -std=c++11   -Isrc -Isrc/linux -Isrc/linux/udp -I../MQTTSNPacket/src -Isrc/tests  -o Build/src/MQTTSNGWSubscribeHandler.o -c -MMD -MP -MF Build/src/MQTTSNGWSubscribeHandler.d src/MQTTSNGWSubscribeHandler.cpp
    src/MQTTSNGWSubscribeHandler.cpp: In member function ‘MQTTSNGW::MQTTGWPacket* MQTTSNGW::MQTTSNSubscribeHandler::handleSubscribe(MQTTSNGW::Client*, MQTTSNGW::MQTTSNPacket*)’:
    src/MQTTSNGWSubscribeHandler.cpp:116:45: warning: ‘subscribe’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    ev1->setBrokerSendEvent(client, subscribe);
                                             ^
  4. when trying to see what Logmonitor does, it does not start, and prevents the Gateway from starting

    jsaak@a20-olimex:[master]~/src/paho.mqtt-sn.embedded-c/MQTTSNGateway/Build$ ./MQTT-SNLogmonitor 
    terminate called after throwing an instance of 'MQTTSNGW::Exception'
    what():  RingBuffer can't create a shared memory.
    zsh: abort      ./MQTT-SNLogmonitor
    jsaak@a20-olimex:[master]~/src/paho.mqtt-sn.embedded-c/MQTTSNGateway/Build$ ./MQTT-SNGateway   
    terminate called after throwing an instance of 'MQTTSNGW::Exception'
    what():  RingBuffer can't create a shared memory.
    zsh: abort      ./MQTT-SNGateway
  5. When connecting with different client-id i get very strange behaviour: first I connect with 0000, then i tried to connect with bb00 But the clientid remains 0000

20190718 084534.709   CONNECT           <---  0000                                0A 04 04 01 FF FF 62 62 30 30
20190718 084534.711   CONNECT           ===>  0000                                10 10 00 04 4D 51 54 54 04 02 FF FF 00 04 30 30 30 30
20190718 084535.113   CONNACK           <===  0000                                20 02 00 00
20190718 084535.114   CONNACK           --->  0000                                03 05 00
ty4tw commented 5 years ago

Hi jsaak,

Thank you for your information.

1) uncomment 62, 63 lines in MQTTSNGWDefines.h then you can get more logs.

/*=================================
 *    Log controls
 ==================================*/
//#define DEBUG          // print out log for debug
//#define DEBUG_NWSTACK  // print out SensorNetwork log

#ifdef  DEBUG
#define DEBUGLOG(...) printf(__VA_ARGS__)
#else
#define DEBUGLOG(...)
#endif

2) The mainGateway is waiting until BrokerSendTask thread stops normally. But, The thread BrokerSendTask stopped for some reason before you enter the Ctrl+C. check the line 260 in MQTTSNGateway.c and MultiTaskProcess::waitStop();


    /* Run Tasks until CTRL+C entred */
    MultiTaskProcess::run();

    /* stop Tasks */
    Event* ev = new Event();
    ev->setStop();
    _packetEventQue.post(ev);
    ev = new Event();
    ev->setStop();
    _brokerSendQue.post(ev);
    ev = new Event();
    ev->setStop();
    _clientSendQue.post(ev);

    /* wait until all Task stop */
    MultiTaskProcess::waitStop();

3) as to compile warning, you may use a master branch. I had a same warning message when I compile the master branch. try to compile a develop branch.

4) Shared memories can be created by only supper user as you know. so, you need to run the gateway as supper user at once with sudo MQTTSNGateway. And ShearedMemory=NO to YES in gateway.conf ( I will add this to README later).

# LOG
ShearedMemory=YES;

5) I could not reproduce this phenomena. Can you check your CONNECT package?

jsaak commented 5 years ago
  1. without broker i guess it never started
  2. i used c9e807d, it may be gone in other branches
  3. This is the most important one!!
$ ./MQTT-SNGateway 
ClientList can not open the Predefined Topic List.     ./predefinedTopic.conf

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

20190719 140020.257 PahoGateway-01 has been started.

 ConfigFile: ./gateway.conf
 SensorN/W:  UDP Multicast 225.1.1.1:1884 Gateway Port 20000
 Broker:     localhost : 1884, 8883
 RootCApath: (null)
 RootCAfile: (null)
 CertKey:    (null)
 PrivateKey: (null)

20190719 140021.076   CONNECT           <---  0000                                0A 04 0C 01 00 3C 30 30 30 30
20190719 140021.077   WILLTOPICREQ      --->  0000                                02 06
20190719 140021.082   WILLTOPIC         <---  0000                                0C 07 50 30 30 2F 73 74 61 74 75 73
20190719 140021.082   WILLMSGREQ        --->  0000                                02 08
20190719 140021.086   WILLMSG           <---  0000                                03 09 58
20190719 140021.090   CONNECT           ===>  0000                                10 1E 00 04 4D 51 54 54 04 36 00 3C 00 04 30 30 30 30 00 09 30 30 2F 73 74 61 74 75 73 00 01 58
20190719 140021.187   WILLMSG           <---  0000                                03 09 58
20190719 140021.264   CONNACK           <===  0000                                20 02 00 00
20190719 140021.264   CONNACK           --->  0000                                03 05 00

20190719 140021.273   REGISTER    0048  <---  0000                                0F 0A 00 00 00 48 30 30 2F 73 74 61 74 75 73
20190719 140021.274   REGACK      0048  --->  0000                                07 0B 00 01 00 48 00

20190719 140021.274   REGISTER    0049  <---  0000                                12 0A 00 00 00 49 30 30 2F 63 61 72 64 5F 72 65 61 64
20190719 140021.274   REGACK      0049  --->  0000                                07 0B 00 02 00 49 00

20190719 140021.276   REGISTER    004A  <---  0000                                0D 0A 00 00 00 4A 30 30 2F 6C 6F 63 6B
20190719 140021.276   REGACK      004A  --->  0000                                07 0B 00 03 00 4A 00

20190719 140021.277   REGISTER    004B  <---  0000                                12 0A 00 00 00 4B 30 30 2F 62 69 6B 65 5F 6D 6F 76 65
20190719 140021.278   REGACK      004B  --->  0000                                07 0B 00 04 00 4B 00

20190719 140021.280   SUBSCRIBE   004C  <---  0000                                13 12 40 00 4C 30 30 2F 6D 6F 64 65 6D 5F 72 65 73 65 74
20190719 140021.280   SUBSCRIBE   004C  ===>  0000                                82 13 00 4C 00 0E 30 30 2F 6D 6F 64 65 6D 5F 72 65 73 65 74 02
20190719 140021.281   SUBACK      004C  <===  0000                                90 03 00 4C 02
20190719 140021.281   SUBACK      004C  --->  0000                                08 13 40 00 05 00 4C 00

20190719 140021.289   SUBSCRIBE   004D  <---  0000                                1D 12 40 00 4D 30 30 2F 6C 6F 77 5F 62 61 74 74 65 72 79 5F 74 68 72 65 73 68 6F 6C 64
20190719 140021.289   SUBSCRIBE   004D  ===>  0000                                82 1D 00 4D 00 18 30 30 2F 6C 6F 77 5F 62 61 74 74 65 72 79 5F 74 68 72 65 73 68 6F 6C 64 02
20190719 140021.290   SUBACK      004D  <===  0000                                90 03 00 4D 02
20190719 140021.290   SUBACK      004D  --->  0000                                08 13 40 00 06 00 4D 00

20190719 140021.296   SUBSCRIBE   004E  <---  0000                                0F 12 40 00 4E 67 65 74 5F 73 74 61 74 75 73
20190719 140021.297   SUBSCRIBE   004E  ===>  0000                                82 0F 00 4E 00 0A 67 65 74 5F 73 74 61 74 75 73 02
20190719 140021.297   SUBACK      004E  <===  0000                                90 03 00 4E 02
20190719 140021.297   SUBACK      004E  --->  0000                                08 13 40 00 07 00 4E 00

20190719 140021.303   SUBSCRIBE   004F  <---  0000                                10 12 40 00 4F 6E 65 77 5F 61 64 64 72 65 73 73
20190719 140021.304   SUBSCRIBE   004F  ===>  0000                                82 10 00 4F 00 0B 6E 65 77 5F 61 64 64 72 65 73 73 02
20190719 140021.304   SUBACK      004F  <===  0000                                90 03 00 4F 02
20190719 140021.304   SUBACK      004F  --->  0000                                08 13 40 00 08 00 4F 00

20190719 140021.310   SUBSCRIBE   0050  <---  0000                                0E 12 40 00 50 30 30 2F 62 75 7A 7A 65 72
20190719 140021.310   SUBSCRIBE   0050  ===>  0000                                82 0E 00 50 00 09 30 30 2F 62 75 7A 7A 65 72 02
20190719 140021.311   SUBACK      0050  <===  0000                                90 03 00 50 02
20190719 140021.311   SUBACK      0050  --->  0000                                08 13 40 00 09 00 50 00

20190719 140021.317   SUBSCRIBE   0051  <---  0000                                0D 12 40 00 51 30 30 2F 64 65 62 75 67
20190719 140021.317   SUBSCRIBE   0051  ===>  0000                                82 0D 00 51 00 08 30 30 2F 64 65 62 75 67 02
20190719 140021.318   SUBACK      0051  <===  0000                                90 03 00 51 02
20190719 140021.318   SUBACK      0051  --->  0000                                08 13 40 00 0A 00 51 00

20190719 140021.323   PUBLISH     0052  <---  0000                                0D 0C 50 00 01 00 52 55 30 7C 34 36 7C
20190719 140021.323   PUBLISH     0052  ===>  0000                                35 13 00 09 30 30 2F 73 74 61 74 75 73 00 52 55 30 7C 34 36 7C
20190719 140021.324   PUBREC      0052  <===  0000                                50 02 00 52
20190719 140021.324   PUBREC      0052  --->  0000                                04 0F 00 52
20190719 140021.329   PUBREL      0052  <---  0000                                04 10 00 52
20190719 140021.329   PUBCOMP     0052  <===  0000                                70 02 00 52
20190719 140021.330   PUBCOMP     0052  --->  0000                                04 0E 00 52
20190719 140021.330   PUBREL      0052  ===>  0000                                62 02 00 52

20190719 140035.680   CONNECT           <---  0000                                0A 04 04 01 FF FF 62 62 30 30
20190719 140035.682   CONNECT           ===>  0000                                10 10 00 04 4D 51 54 54 04 02 FF FF 00 04 30 30 30 30
20190719 140035.683   CONNACK           <===  0000                                20 02 00 00
20190719 140035.683   CONNACK           --->  0000                                03 05 00
ty4tw commented 5 years ago

I 'd like to know the received data of CONNECT message. Uncomment //#define DEBUG_NWSTACK, then you can get it. When it is different from the log of the gateway, it is a bug of the gateway.

ty4tw commented 5 years ago

I 'd like to know the received data of CONNECT message. Uncomment //#define DEBUG_NWSTACK, then you can get it. When it is different from the log of the gateway, it is a bug of the gateway.

jsaak commented 5 years ago

There is nothing wrong with the CONNECT message. It is received from the same udp port and host as the first one. And you are treating it as the same client as previously. Despite the fact, that it is sending a different client id. (It is the same physical device, once in boot mode, once in normal mode)

ty4tw commented 5 years ago

I need a log.

2019年7月20日(土) 18:49 jsaak notifications@github.com:

There is nothing wrong with the CONNECT message. It is received from the same udp port and host as the first one. And you are treating it as the same client as previously. Despite the fact, that it is sending a different client id. (It is the same physical device, once in boot mode, once in normal mode)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt-sn.embedded-c/issues/160?email_source=notifications&email_token=AB3X2BG7QWNVUF2TVK7OATTQALUTBA5CNFSM4IEXSEPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2NLZYQ#issuecomment-513457378, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3X2BD23UKV2BIHPD4C4BLQALUTBANCNFSM4IEXSEPA .

ty4tw commented 5 years ago

I don't need it. The log of you sent is enough. I will look into it.

2019年7月20日(土) 22:55 Tomoaki Yamaguchi tomoaki@tomy-tech.com:

I need a log.

2019年7月20日(土) 18:49 jsaak notifications@github.com:

There is nothing wrong with the CONNECT message. It is received from the same udp port and host as the first one. And you are treating it as the same client as previously. Despite the fact, that it is sending a different client id. (It is the same physical device, once in boot mode, once in normal mode)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt-sn.embedded-c/issues/160?email_source=notifications&email_token=AB3X2BG7QWNVUF2TVK7OATTQALUTBA5CNFSM4IEXSEPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2NLZYQ#issuecomment-513457378, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3X2BD23UKV2BIHPD4C4BLQALUTBANCNFSM4IEXSEPA .

ty4tw commented 5 years ago

can you disconect before connect ?

2019年7月21日(日) 5:03 Tomoaki Yamaguchi tomoaki@tomy-tech.com:

I don't need it. The log of you sent is enough. I will look into it.

2019年7月20日(土) 22:55 Tomoaki Yamaguchi tomoaki@tomy-tech.com:

I need a log.

2019年7月20日(土) 18:49 jsaak notifications@github.com:

There is nothing wrong with the CONNECT message. It is received from the same udp port and host as the first one. And you are treating it as the same client as previously. Despite the fact, that it is sending a different client id. (It is the same physical device, once in boot mode, once in normal mode)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt-sn.embedded-c/issues/160?email_source=notifications&email_token=AB3X2BG7QWNVUF2TVK7OATTQALUTBA5CNFSM4IEXSEPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2NLZYQ#issuecomment-513457378, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3X2BD23UKV2BIHPD4C4BLQALUTBANCNFSM4IEXSEPA .

jsaak commented 5 years ago

i can start with a disconnect before second connect. still i feel it is a workaround of a bug.

ty4tw commented 5 years ago

Hi,

Where is it written in the specification?

2019年7月21日(日) 14:40 jsaak notifications@github.com:

i can start with a disconnect before second connect. still i feel it is a workaround of a bug.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt-sn.embedded-c/issues/160?email_source=notifications&email_token=AB3X2BHKZ2XGGJ4BFKEQE33QAQAFVA5CNFSM4IEXSEPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2N472A#issuecomment-513527784, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3X2BEHZNZODIEXAVG5CZLQAQAFVANCNFSM4IEXSEPA .

jsaak commented 5 years ago

5.3.1 ClientId As with MQTT, the ClientId field has a variable length and contains a 1-23 character long string that uniquely identifies the client to the server.

ty4tw commented 5 years ago

HI,

My implementation follows Fig.4 of specification. This state transformation diagram shows when the clieent is active state, it can send DISCONNECT but not CONNECT. If you want to change the session. You have to change the state to the disconnect by sending DISCONNECT message. This is a reason I ask to DISCONNECT before CONNECT.

jsaak commented 5 years ago

But we are dealing with 2 clients not one. I am struggling to see your point, I am sorry.

ty4tw commented 5 years ago

Hi, Client can not send DISCONNECT before sending CONNECT. image