From 528934962f4d06b8e430d3faf62d7c90df798d58 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Sat, 23 Feb 2019 11:35:28 +0900 Subject: [PATCH 01/10] Improve documentation #145 Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 103 ++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index af6094d..e351a0d 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -1,35 +1,35 @@ -# MQTT-SN Transparent / Aggrigating Gateway +# MQTT-SN Transparent / Aggregating Gateway -**MQTT-SN** requires a MQTT-SN Gateway which acts as a protocol converter to convert **MQTT-SN messages to MQTT messages**. MQTT-SN client over SensorNetwork can not communicate directly with MQTT broker(TCP/IP). -This Gateway can run as a transparent or aggrigating Gateway by specifying the gateway.conf. +**MQTT-SN** requires a MQTT-SN Gateway which acts as a protocol converter to convert **MQTT-SN messages to MQTT messages**. MQTT-SN client over SensorNetwork can not communicate directly with MQTT broker (TCP/IP). +This Gateway can be configured to run as a transparent or aggregating gateway in the file *gateway.conf*. -### **step1. Build the gateway** +### **Step 1: Build the gateway** ```` -$ git clone -b experiment https://github.com/eclipse/paho.mqtt-sn.embedded-c -$ cd paho.mqtt-sn.embedded-c/MQTTSNGateway -$ make -$ make install -$ make clean -```` -MQTT-SNGateway, MQTT-SNLogmonitor and *.conf files are copied into ../ directory. +$ git clone https://github.com/eclipse/paho.mqtt-sn.embedded-c +$ cd paho.mqtt-sn.embedded-c/MQTTSNGateway +$ make +$ make install +$ make clean +```` +MQTT-SNGateway, MQTT-SNLogmonitor and *.conf files are copied into **../** directory. If you want to install the gateway into specific directories, enter a command line as follows: ```` $ make install INSTALL_DIR=/path/to/your_directory CONFIG_DIR=/path/to/your_directory ```` - -### **step2. Execute the Gateway.** -```` -$ cd ../ +### **Step 2: Execute the Gateway.** + +```` +$ cd ../ $ ./MQTT-SNGateway [-f Config file name] -```` +```` -### **How to Change the configuration of the gateway** -**../gateway.conf** Contents are follows: - -
    
+### How to change the configuration of the gateway
+Example for **gateway.conf**:
+
+

 
 # config file of MQTT-SN Gateway
 #
@@ -40,7 +40,7 @@ BrokerSecurePortNo=8883
 
 #
 # When AggregatingGateway=YES or ClientAuthentication=YES,
-# All clients must be specified by the ClientList File  
+# All clients must be specified by the ClientList File
 #
 
 ClientAuthentication=NO
@@ -78,35 +78,48 @@ ApiMode=2
 # LOG
 ShearedMemory=NO;
 
-
+
-**BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. **BrokerSecurePortNo** is for TLS connection. -**MulticastIP** and **MulticastPortNo** is a multicast address for GWSEARCH messages. Gateway is waiting GWSEARCH and when receiving it send GWINFO message via MulticastIP address. Clients can get the gateway address (Gateway IP address and **GatewayPortNo**) from GWINFO message by means of std::recvfrom(). -Client should know the MulticastIP and MulticastPortNo to send a SEARCHGW message. -**GatewayId** is used by GWINFO message. -**KeepAlive** is a duration of ADVERTISE message in seconds. -when **AggregatingGateway** or **ClientAuthentication** is **YES**, All clients which connect to the gateway must be declared by a **ClientsList** file. -Format of the file is ClientId and SensorNetwork Address. e.g. IP address and Port No etc, in CSV. more detail see clients.conf. -When **QoS-1** is **YES**, QoS-1 PUBLISH is available. All clients which send QoS-1 PUBLISH must be specified by Client.conf file. -When **PredefinedTopic** is **YES**, **Pre-definedTopicId**s specified by **PredefinedTopicList** are effective. This file defines Pre-definedTopics of the clients. In this file, ClientID,TopicName and TopicID are declared in CSV format. -When **Forwarder** is **YES**, Forwarder Encapsulation Message is available. Connectable Forwarders must be declared by a **ClientsList** file. - +**Broker config** +* *BrokerName* - Domain name/ IP address of the MQTT broker +* *BrokerPortNo* - Port of the MQTT broker +* *LoginID* - Username for login at the broker +* *Password* - Password for login at the broker -### ** How to monitor the gateway from remote. ** +**Broker config for TLS** +* *BrokerSecurePortNo* - TLS Port of the MQTT broker +* *RootCAfile* - Path to the root CA file +* *RootCApath* - Path to the CA certificates +* *CertsFile* - Path to the certificate +* *PrivateKey* - Path to the private key -Uncomment line32 in MQTTSNGWDefined.h. +**Gateway config** +* *MulticastIP* - UDP multicast IP address of the gateway +* *MulticastPortNo* - UDP multicast port of the gateway +* *GatewayId* - ID of the gateway (for advertising) +* *GatewayName* - Name of the gateway (for advertising) +* *KeepAlive* - Connection timeout +* *AggregatingGateway* - If 'YES', all clients which want to connect to the gateway must be declared inside of *clients.conf* +* *ClientAuthentication* - If 'YES', all clients which want to connect to the gateway must be declared inside of *clients.conf* +* *ClientsList* - path/to/your/custom_clients.conf +* *PredefinedTopic* - If 'YES', then predefined topics specified by *predefinedTopic.conf* are effective +* *PredefinedTopicList* - path/to/your/custom_predefinedTopic.conf +* *QoS-1* - If 'YES', QoS-1 PUBLISH is available. All clients which send QoS-1 PUBLISH must be declared inside of *clients.conf* +* *Forwarder* - If 'YES', then Forwarder Encapsulation Message is available. Connectable forwarders must be declared in *clients.conf*. -`//#define RINGBUFFER // print out Packets log into shared memory./"` -```` -$ make -$ make install -$ make clean -```` -restart the gateway. -open ssh terminal and execute LogMonitor. +Multicast address is used for GWSEARCH messages. The Gateway is waiting GWSEARCH and when receiving it, +it sends GWINFO message via MulticastIP address. Clients can get the gateway address (Gateway IP address +and GatewayPortNo) from GWINFO message by means of std::recvfrom(). Client should know the MulticastIP and +MulticastPortNo to send a SEARCHGW message. -`$ ./MQTT-SNLogmonitor` +### How to monitor the gateway from remote -Now you can get the Log on your terminal. +Uncomment line32 in MQTTSNGWDefined.h: +`//#define RINGBUFFER // print out Packets log into shared memory./"` +and rebuild the gateway as shown above. Start the gateway, open a ssh terminal and execute LogMonitor with + +`$ ./MQTT-SNLogmonitor` + +Now you can get the log on your terminal. From 3d5b8f75d1706d23d148d0332d4b78f229441f05 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Tue, 26 Feb 2019 21:51:37 +0900 Subject: [PATCH 02/10] update README Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index e351a0d..a8ea16e 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -120,6 +120,8 @@ Uncomment line32 in MQTTSNGWDefined.h: and rebuild the gateway as shown above. Start the gateway, open a ssh terminal and execute LogMonitor with -`$ ./MQTT-SNLogmonitor` +``` +$ ./MQTT-SNLogmonitor +``` Now you can get the log on your terminal. From d8bced8a62101659005cc08681e18f882fae9baa Mon Sep 17 00:00:00 2001 From: tomoaki Date: Tue, 26 Feb 2019 21:57:34 +0900 Subject: [PATCH 03/10] update README Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index a8ea16e..437a338 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -116,12 +116,18 @@ MulticastPortNo to send a SEARCHGW message. Uncomment line32 in MQTTSNGWDefined.h: -`//#define RINGBUFFER // print out Packets log into shared memory./"` +`//#define RINGBUFFER // print out Packets log into shared memory.` +```` +$ make +$ make install +$ make clean +```` +restart the gateway. +open ssh terminal and execute LogMonitor. -and rebuild the gateway as shown above. Start the gateway, open a ssh terminal and execute LogMonitor with - -``` +```` $ ./MQTT-SNLogmonitor -``` +```` + +Now you can get the Log on your terminal. -Now you can get the log on your terminal. From 3fae393efc1d80a655ed42b6e4a9fe80e0f626b0 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Fri, 17 May 2019 16:55:46 +0900 Subject: [PATCH 04/10] Errata Sensernet Address of UDP is IPAdress:PortNo Signed-off-by: tomoaki --- MQTTSNGateway/clients.conf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MQTTSNGateway/clients.conf b/MQTTSNGateway/clients.conf index ddb2310..0409cdc 100644 --- a/MQTTSNGateway/clients.conf +++ b/MQTTSNGateway/clients.conf @@ -14,7 +14,7 @@ # File format is: # Lines bigning with # are comment line. # ClientId, SensorNetAddress, "unstableLine", "secureConnection" -# in case of UDP, SensorNetAddress format is portNo@IPAddress. +# in case of UDP, SensorNetAddress format is IPAddress: port no. # if the SensorNetwork is not stable, write "unstableLine". # if Broker's Connection is SSL, write "secureConnection". # if the client is a forwarder, "forwarder" is required. @@ -22,12 +22,12 @@ # # Ex: # #Client List -# ClientId1,11200@192.168.10.10 -# ClientID2,35000@192.168.50.200,unstableLine -# ClientID3,40000@192.168.200.50,secureConnection -# ClientID4,41000@192.168.200.52,unstableLine,secureConnection -# ClientID5,41000@192.168.200.53,unstableLine,secureConnection,QoS-1 -# ClientID6,41000@192.168.200.54,unstableLine,secureConnection,forwarder +# ClientId1,192.168.10.10:11200@ +# ClientID2,192.168.50.200:35000,unstableLine +# ClientID3,192.168.200.50:40000,secureConnection +# ClientID4,192.168.200.52:41000,unstableLine,secureConnection +# ClientID5,192.168.200.53:41000,unstableLine,secureConnection,QoS-1 +# ClientID6,192.168.200.54:41000,unstableLine,secureConnection,forwarder # # SensorNetwork address format is defined by SensorNetAddress::setAddress(string* data) function. # From 6cb7935027e36995527211eb6f589b4ee1121786 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Tue, 28 May 2019 16:31:52 +0900 Subject: [PATCH 05/10] BugFix of #151 Signed-off-by: tomoaki --- .cproject | 4 +- MQTTSNGateway/clients.conf | 2 +- .../src/linux/udp6/SensorNetwork.cpp | 42 +++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.cproject b/.cproject index 78de229..3966019 100644 --- a/.cproject +++ b/.cproject @@ -133,7 +133,7 @@ - + @@ -277,7 +277,7 @@ - + diff --git a/MQTTSNGateway/clients.conf b/MQTTSNGateway/clients.conf index 0409cdc..a2c005c 100644 --- a/MQTTSNGateway/clients.conf +++ b/MQTTSNGateway/clients.conf @@ -22,7 +22,7 @@ # # Ex: # #Client List -# ClientId1,192.168.10.10:11200@ +# ClientId1,192.168.10.10:11200 # ClientID2,192.168.50.200:35000,unstableLine # ClientID3,192.168.200.50:40000,secureConnection # ClientID4,192.168.200.52:41000,unstableLine,secureConnection diff --git a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp index e4f0039..b33525d 100644 --- a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp +++ b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp @@ -65,24 +65,52 @@ void SensorNetAddress::setAddress(struct sockaddr_in6 *IpAddr, uint16_t port) /** * convert Text data to SensorNetAddress - * @param buf is pointer of IP_Address:PortNo format text + * @param data is a IP_Address:PortNo format string * @return success = 0, Invalid format = -1 */ int SensorNetAddress::setAddress(string* data) { - const char *cstr = data->c_str(); - inet_pton(AF_INET6, cstr, &(_IpAddr.sin6_addr)); - return 0; + + size_t pos = data->find_last_of(":"); + + if ( pos != string::npos) + { + int portNo = 0; + string port = data->substr(pos + 1); + + if ( ( portNo = atoi(port.c_str()) ) > 0 ) + { + _portNo = htons(portNo); + + string ip = data->substr(1,pos - 1); + const char *cstr = ip.c_str(); + + if (inet_pton(AF_INET6, cstr, &(_IpAddr.sin6_addr)) == 1 ) + { + return 0; + } + } + } + _portNo = 0; + memset((void *)&_IpAddr,0,sizeof(_IpAddr)); + return -1; } + /** * convert Text data to SensorNetAddress - * @param buf is pointer of IP_Address:PortNo format text + * @param data is pointer of IP_Address format text * @return success = 0, Invalid format = -1 */ int SensorNetAddress::setAddress(const char* data) { - inet_pton(AF_INET6, data, &(_IpAddr.sin6_addr)); - return 0; + if ( inet_pton(AF_INET6, data, &(_IpAddr.sin6_addr)) == 1 ) + { + return 0; + } + else + { + return -1; + } } char* SensorNetAddress::getAddress(void) From 18885668cf185ed447f86405b4e68b2ff3221e74 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Thu, 30 May 2019 10:09:14 +0900 Subject: [PATCH 06/10] Update README Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 101 ++++++++---------- .../src/linux/udp6/SensorNetwork.cpp | 3 - 2 files changed, 42 insertions(+), 62 deletions(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index 437a338..bef8415 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -1,35 +1,38 @@ -# MQTT-SN Transparent / Aggregating Gateway +# MQTT-SN Transparent / Aggrigating Gateway -**MQTT-SN** requires a MQTT-SN Gateway which acts as a protocol converter to convert **MQTT-SN messages to MQTT messages**. MQTT-SN client over SensorNetwork can not communicate directly with MQTT broker (TCP/IP). -This Gateway can be configured to run as a transparent or aggregating gateway in the file *gateway.conf*. +**MQTT-SN** requires a MQTT-SN Gateway which acts as a protocol converter to convert **MQTT-SN messages to MQTT messages**. MQTT-SN client over SensorNetwork can not communicate directly with MQTT broker(TCP/IP). +This Gateway can run as a transparent or aggrigating Gateway by specifying the gateway.conf. -### **Step 1: Build the gateway** +### **step1. Build the gateway** ```` -$ git clone https://github.com/eclipse/paho.mqtt-sn.embedded-c -$ cd paho.mqtt-sn.embedded-c/MQTTSNGateway -$ make -$ make install -$ make clean -```` -MQTT-SNGateway, MQTT-SNLogmonitor and *.conf files are copied into **../** directory. +$ git clone -b experiment https://github.com/eclipse/paho.mqtt-sn.embedded-c +$ cd paho.mqtt-sn.embedded-c/MQTTSNGateway +$ make [SENSORNET={udp6|xbee}] +$ make install +$ make clean +```` +By default, a gateway for UDP is built. +In order to create a gateway for UDP6 or XBee, SENSORNET argument is required. + +MQTT-SNGateway, MQTT-SNLogmonitor and *.conf files are copied into ../ directory. If you want to install the gateway into specific directories, enter a command line as follows: ```` $ make install INSTALL_DIR=/path/to/your_directory CONFIG_DIR=/path/to/your_directory ```` + +### **step2. Execute the Gateway.** -### **Step 2: Execute the Gateway.** - -```` -$ cd ../ +```` +$ cd ../ $ ./MQTT-SNGateway [-f Config file name] -```` +```` -### How to change the configuration of the gateway -Example for **gateway.conf**: - -

+### **How to Change the configuration of the gateway**    
+**../gateway.conf**   Contents are follows: 
+   
+
    
 
 # config file of MQTT-SN Gateway
 #
@@ -40,7 +43,7 @@ BrokerSecurePortNo=8883
 
 #
 # When AggregatingGateway=YES or ClientAuthentication=YES,
-# All clients must be specified by the ClientList File
+# All clients must be specified by the ClientList File  
 #
 
 ClientAuthentication=NO
@@ -78,45 +81,25 @@ ApiMode=2
 # LOG
 ShearedMemory=NO;
 
-
+
-**Broker config** -* *BrokerName* - Domain name/ IP address of the MQTT broker -* *BrokerPortNo* - Port of the MQTT broker -* *LoginID* - Username for login at the broker -* *Password* - Password for login at the broker +**BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. **BrokerSecurePortNo** is for TLS connection. +**MulticastIP** and **MulticastPortNo** is a multicast address for GWSEARCH messages. Gateway is waiting GWSEARCH and when receiving it send GWINFO message via MulticastIP address. Clients can get the gateway address (Gateway IP address and **GatewayPortNo**) from GWINFO message by means of std::recvfrom(). +Client should know the MulticastIP and MulticastPortNo to send a SEARCHGW message. +**GatewayId** is used by GWINFO message. +**KeepAlive** is a duration of ADVERTISE message in seconds. +when **AggregatingGateway** or **ClientAuthentication** is **YES**, All clients which connect to the gateway must be declared by a **ClientsList** file. +Format of the file is ClientId and SensorNetwork Address. e.g. IP address and Port No etc, in CSV. more detail see clients.conf. +When **QoS-1** is **YES**, QoS-1 PUBLISH is available. All clients which send QoS-1 PUBLISH must be specified by Client.conf file. +When **PredefinedTopic** is **YES**, **Pre-definedTopicId**s specified by **PredefinedTopicList** are effective. This file defines Pre-definedTopics of the clients. In this file, ClientID,TopicName and TopicID are declared in CSV format. +When **Forwarder** is **YES**, Forwarder Encapsulation Message is available. Connectable Forwarders must be declared by a **ClientsList** file. + -**Broker config for TLS** -* *BrokerSecurePortNo* - TLS Port of the MQTT broker -* *RootCAfile* - Path to the root CA file -* *RootCApath* - Path to the CA certificates -* *CertsFile* - Path to the certificate -* *PrivateKey* - Path to the private key +### ** How to monitor the gateway from remote. ** -**Gateway config** -* *MulticastIP* - UDP multicast IP address of the gateway -* *MulticastPortNo* - UDP multicast port of the gateway -* *GatewayId* - ID of the gateway (for advertising) -* *GatewayName* - Name of the gateway (for advertising) -* *KeepAlive* - Connection timeout -* *AggregatingGateway* - If 'YES', all clients which want to connect to the gateway must be declared inside of *clients.conf* -* *ClientAuthentication* - If 'YES', all clients which want to connect to the gateway must be declared inside of *clients.conf* -* *ClientsList* - path/to/your/custom_clients.conf -* *PredefinedTopic* - If 'YES', then predefined topics specified by *predefinedTopic.conf* are effective -* *PredefinedTopicList* - path/to/your/custom_predefinedTopic.conf -* *QoS-1* - If 'YES', QoS-1 PUBLISH is available. All clients which send QoS-1 PUBLISH must be declared inside of *clients.conf* -* *Forwarder* - If 'YES', then Forwarder Encapsulation Message is available. Connectable forwarders must be declared in *clients.conf*. +Uncomment line32 in MQTTSNGWDefined.h. -Multicast address is used for GWSEARCH messages. The Gateway is waiting GWSEARCH and when receiving it, -it sends GWINFO message via MulticastIP address. Clients can get the gateway address (Gateway IP address -and GatewayPortNo) from GWINFO message by means of std::recvfrom(). Client should know the MulticastIP and -MulticastPortNo to send a SEARCHGW message. - -### How to monitor the gateway from remote - -Uncomment line32 in MQTTSNGWDefined.h: - -`//#define RINGBUFFER // print out Packets log into shared memory.` +`//#define RINGBUFFER // print out Packets log into shared memory./"` ```` $ make $ make install @@ -125,9 +108,9 @@ $ make clean restart the gateway. open ssh terminal and execute LogMonitor. -```` -$ ./MQTT-SNLogmonitor -```` +`$ ./MQTT-SNLogmonitor` Now you can get the Log on your terminal. + + diff --git a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp index b33525d..5d6b7b8 100644 --- a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp +++ b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp @@ -346,7 +346,6 @@ int UDPPort6::open(const char* ipAddress, uint16_t uniPortNo, const char* broadc return 0; } -//TODO: test if unicast is working too.... int UDPPort6::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* addr) { char destStr[INET6_ADDRSTRLEN+10]; @@ -391,8 +390,6 @@ int UDPPort6::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* add WRITELOG("errno in UDPPort::unicast(sendto): %d, %s\n",status,strerror(status)); } - WRITELOG("unicast sendto %s, port: %d length = %d\n", destStr,port,status); - return status; } From 93e297c6d3c3b2819d9fd4717bdf4cf83cf9e8c6 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Sat, 13 Jul 2019 16:38:12 +0900 Subject: [PATCH 07/10] BugFix of #149 Signed-off-by: tomoaki --- .cproject | 4 +- .../GatewayTester/samples/mainTest.cpp | 4 +- MQTTSNGateway/gateway.conf | 10 ++++- MQTTSNGateway/src/MQTTSNGWClientList.cpp | 4 +- MQTTSNGateway/src/MQTTSNGWClientSendTask.cpp | 5 ++- .../src/MQTTSNGWSubscribeHandler.cpp | 37 +++++++++++-------- 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/.cproject b/.cproject index 3966019..62eba26 100644 --- a/.cproject +++ b/.cproject @@ -133,7 +133,7 @@ - + @@ -277,7 +277,7 @@ - + diff --git a/MQTTSNGateway/GatewayTester/samples/mainTest.cpp b/MQTTSNGateway/GatewayTester/samples/mainTest.cpp index 06aa565..934a419 100644 --- a/MQTTSNGateway/GatewayTester/samples/mainTest.cpp +++ b/MQTTSNGateway/GatewayTester/samples/mainTest.cpp @@ -138,7 +138,7 @@ void publishTopic1(void) PUBLISH(topic1,(uint8_t*)payload, strlen(payload), QoS0); } -void subscribeTopic2(void) +void subscribeTopic10(void) { SUBSCRIBE(10, on_Topic02, QoS1); } @@ -190,7 +190,7 @@ TEST_LIST = {// e.g. TEST( Label, Test), TEST("Step0:Subscribe predef topic1", subscribePredefTopic1), TEST("Step1:Publish topic1", publishTopic1), TEST("Step2:Publish topic2", publishTopic2), - TEST("Step3:Subscribe topic2", subscribeTopic2), + TEST("Step3:Subscribe PreDefined topic10. ID is not defined.", subscribeTopic10), TEST("Step4:Publish topic2", publishTopic2), TEST("Step5:Unsubscribe topic2", unsubscribe), TEST("Step6:Publish topic2", publishTopic2), diff --git a/MQTTSNGateway/gateway.conf b/MQTTSNGateway/gateway.conf index c06853b..d01903a 100644 --- a/MQTTSNGateway/gateway.conf +++ b/MQTTSNGateway/gateway.conf @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (c) 2016-2018, Tomoaki Yamaguchi +# Copyright (c) 2016-2019, Tomoaki Yamaguchi # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 @@ -14,7 +14,7 @@ # config file of MQTT-SN Gateway # -BrokerName=iot.eclipse.org +BrokerName=mqtt.eclipse.org BrokerPortNo=1883 BrokerSecurePortNo=8883 @@ -50,6 +50,12 @@ GatewayPortNo=10000 MulticastIP=225.1.1.1 MulticastPortNo=1883 +# UDP6 +GatewayUDP6Bind=FFFF:FFFE::1 +GatewayUDP6Port=10000 +GatewayUDP6Broadcast=FF02::1 +GatewayUDP6If=wpan0 + # XBee Baudrate=38400 SerialDevice=/dev/ttyUSB0 diff --git a/MQTTSNGateway/src/MQTTSNGWClientList.cpp b/MQTTSNGateway/src/MQTTSNGWClientList.cpp index e4e0bb9..5452765 100644 --- a/MQTTSNGateway/src/MQTTSNGWClientList.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClientList.cpp @@ -416,9 +416,9 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId, Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t topicId, bool aggregate) { - if ( clientId->cstring == common_topic ) + if ( strcmp(clientId->cstring, common_topic) == 0 ) { - _gateway->getTopics()->add((const char*)topicName.c_str(), topicId); + theGateway->getTopics()->add((const char*)topicName.c_str(), topicId); return 0; } else diff --git a/MQTTSNGateway/src/MQTTSNGWClientSendTask.cpp b/MQTTSNGateway/src/MQTTSNGWClientSendTask.cpp index fc8c412..eaa6e68 100644 --- a/MQTTSNGateway/src/MQTTSNGWClientSendTask.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClientSendTask.cpp @@ -18,6 +18,7 @@ #include "MQTTSNGateway.h" #include "MQTTSNGWEncapsulatedPacket.h" #include "MQTTSNGWQoSm1Proxy.h" +#include using namespace MQTTSNGW; using namespace std; @@ -75,8 +76,8 @@ void ClientSendTask::run() if ( rc < 0 ) { - WRITELOG("%s ClientSendTask can't send a packet to the client %s%s.\n", - ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), ERRMSG_FOOTER); + WRITELOG("%s ClientSendTask can't send a packet to the client %s. Error=%d%s\n", + ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), errno, ERRMSG_FOOTER); } delete ev; } diff --git a/MQTTSNGateway/src/MQTTSNGWSubscribeHandler.cpp b/MQTTSNGateway/src/MQTTSNGWSubscribeHandler.cpp index cd4bc30..dceb864 100644 --- a/MQTTSNGateway/src/MQTTSNGWSubscribeHandler.cpp +++ b/MQTTSNGateway/src/MQTTSNGWSubscribeHandler.cpp @@ -60,25 +60,22 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack { topic = client->getTopics()->getTopicById(&topicFilter); - - if ( topic ) - { - topicId = topic->getTopicId(); - subscribe = new MQTTGWPacket(); - subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId); - } - else + if ( !topic ) { topic = _gateway->getTopics()->getTopicById(&topicFilter); - if ( !topic ) - { + if ( topic ) + { topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId()); } - else - { - goto RespExit; - } + else + { + goto RespExit; + } } + topicId = topic->getTopicId(); + subscribe = new MQTTGWPacket(); + subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId); + } else if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL) { @@ -148,7 +145,6 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa return nullptr; } - Topic* topic = client->getTopics()->getTopicById(&topicFilter); if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT) { @@ -161,6 +157,17 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa } else { + Topic* topic = nullptr; + + if (topicFilter.type == MQTTSN_TOPIC_TYPE_PREDEFINED) + { + topic = client->getTopics()->getTopicById(&topicFilter); + } + else + { + topic = client->getTopics()->getTopicByName(&topicFilter); + } + if ( topic == nullptr ) { MQTTSNPacket* sUnsuback = new MQTTSNPacket(); From 04bc61dbca837a2200facaad593e66906559bda7 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Fri, 19 Jul 2019 11:41:44 +0900 Subject: [PATCH 08/10] Update README Add Tips for Debug Delete unused define Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 28 +++++++++++++++--------- MQTTSNGateway/src/MQTTSNGWLogmonitor.cpp | 2 -- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index bef8415..22e3d27 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -94,18 +94,15 @@ When **QoS-1** is **YES**, QoS-1 PUBLISH is available. All clients which send Qo When **PredefinedTopic** is **YES**, **Pre-definedTopicId**s specified by **PredefinedTopicList** are effective. This file defines Pre-definedTopics of the clients. In this file, ClientID,TopicName and TopicID are declared in CSV format. When **Forwarder** is **YES**, Forwarder Encapsulation Message is available. Connectable Forwarders must be declared by a **ClientsList** file. - ### ** How to monitor the gateway from remote. ** - -Uncomment line32 in MQTTSNGWDefined.h. - -`//#define RINGBUFFER // print out Packets log into shared memory./"` -```` -$ make -$ make install -$ make clean +Change gateway.conf as follows: +``` +# LOG +ShearedMemory=YES; ```` -restart the gateway. + +Restart the gateway with sudo only once to create shared memories. + open ssh terminal and execute LogMonitor. `$ ./MQTT-SNLogmonitor` @@ -113,4 +110,15 @@ open ssh terminal and execute LogMonitor. Now you can get the Log on your terminal. +## ** Tips: ** +Uncomment the line 62, 63 in MQTTSNDefines.h then you can get more precise logs. +``` +/*================================= + * Log controls + ==================================*/ +//#define DEBUG // print out log for debug +//#define DEBUG_NWSTACK // print out SensorNetwork log +``` + + diff --git a/MQTTSNGateway/src/MQTTSNGWLogmonitor.cpp b/MQTTSNGateway/src/MQTTSNGWLogmonitor.cpp index 50dc482..692e3fe 100644 --- a/MQTTSNGateway/src/MQTTSNGWLogmonitor.cpp +++ b/MQTTSNGateway/src/MQTTSNGWLogmonitor.cpp @@ -13,8 +13,6 @@ * Contributors: * Tomoaki Yamaguchi - initial API and implementation and/or initial documentation **************************************************************************************/ -#define RINGBUFFER - #include "MQTTSNGWProcess.h" #include "MQTTSNGWLogmonitor.h" #include From 2b7f040b57081b709abc9223073f1411f0cf5065 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Sat, 27 Jul 2019 12:04:23 +0900 Subject: [PATCH 09/10] Update a errata of README Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index 22e3d27..d549065 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -110,7 +110,7 @@ open ssh terminal and execute LogMonitor. Now you can get the Log on your terminal. -## ** Tips: ** +## ** Tips ** Uncomment the line 62, 63 in MQTTSNDefines.h then you can get more precise logs. ``` /*================================= From 22e7f0d2720926cedda29584290f7db329372ca6 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Sat, 27 Jul 2019 12:20:57 +0900 Subject: [PATCH 10/10] Bugfix of test Signed-off-by: tomoaki --- MQTTSNGateway/src/tests/TestProcess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTSNGateway/src/tests/TestProcess.cpp b/MQTTSNGateway/src/tests/TestProcess.cpp index 9b3bdb5..56ba0b1 100644 --- a/MQTTSNGateway/src/tests/TestProcess.cpp +++ b/MQTTSNGateway/src/tests/TestProcess.cpp @@ -65,7 +65,7 @@ void TestProcess::run(void) assert(1 == getArgc() || 3 == getArgc() ); assert(0 == strcmp(ARGV, *getArgv())); getParam("BrokerName", value); - assert(0 == strcmp("iot.eclipse.org", value)); + assert(0 == strcmp("mqtt.eclipse.org", value)); /* Test RingBuffer */ for ( i = 0; i < 1000; i++)