mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 07:26:52 +01:00
@@ -133,7 +133,7 @@
|
||||
|
||||
<sourceEntries>
|
||||
|
||||
<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNClient|MQTTSNGateway/src/MQTTSNGWProxy.cpp|MQTTSNGateway/src/linux/udp6|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry excluding="MQTTSNGateway/src/linux/udp6|MQTTSNGateway/GatewayTester|MQTTSNClient|MQTTSNGateway/src/MQTTSNGWProxy.cpp|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
|
||||
</sourceEntries>
|
||||
|
||||
@@ -277,7 +277,7 @@
|
||||
|
||||
<entry excluding="MQTTSNGWProxy.cpp|mainLogmonitor.cpp|tests|tests/mainTestProcessFramework.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/>
|
||||
|
||||
<entry excluding="xbee|udp6" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
||||
<entry excluding="udp6|xbee" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
||||
|
||||
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -7,10 +7,13 @@ This Gateway can run as a transparent or aggrigating Gateway by specifying the g
|
||||
````
|
||||
$ git clone -b experiment https://github.com/eclipse/paho.mqtt-sn.embedded-c
|
||||
$ cd paho.mqtt-sn.embedded-c/MQTTSNGateway
|
||||
$ make
|
||||
$ 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:
|
||||
````
|
||||
@@ -91,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`
|
||||
@@ -110,3 +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
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
#
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "MQTTSNGateway.h"
|
||||
#include "MQTTSNGWEncapsulatedPacket.h"
|
||||
#include "MQTTSNGWQoSm1Proxy.h"
|
||||
#include <errno.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
* Contributors:
|
||||
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
|
||||
**************************************************************************************/
|
||||
#define RINGBUFFER
|
||||
|
||||
#include "MQTTSNGWProcess.h"
|
||||
#include "MQTTSNGWLogmonitor.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -66,24 +66,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)
|
||||
@@ -319,7 +347,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];
|
||||
@@ -364,8 +391,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++)
|
||||
|
||||
Reference in New Issue
Block a user