diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index 8504eda..e04ffa6 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -36,17 +36,16 @@ BrokerSecurePortNo=8883 # All clients must be specified by the ClientList File # -#ClientsList=/path/to/your_clients.conf - ClientAuthentication=NO AggregateGateway=NO -Forwarder=NO QoS-1=NO -OoS-1ProxyName=Proxy007 +Forwarder=NO +#ClientsList=/path/to/your_clients.conf + +PredefinedTopic=NO #PredefinedTopicList=/path/to/your_predefinedTopic.conf - #RootCAfile=/etc/ssl/certs/ca-certificates.crt #RootCApath=/etc/ssl/certs/ #CertsFile=/path/to/certKey.pem @@ -79,10 +78,11 @@ ShearedMemory=NO; 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 **AggregateGateway** 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 **AggregateGateway** 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 **YE**S, Forwarder Encapsulation Message is available. Connectable Forwarders must be declared by a **ClientsList** file. +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. ** diff --git a/MQTTSNGateway/gateway.conf b/MQTTSNGateway/gateway.conf index e2a1d25..52481de 100644 --- a/MQTTSNGateway/gateway.conf +++ b/MQTTSNGateway/gateway.conf @@ -23,20 +23,16 @@ BrokerSecurePortNo=8883 # All clients must be specified by the ClientList File # -AggregateGateway=NO ClientAuthentication=NO +AggregateGateway=NO +QoS-1=NO +Forwarder=NO #ClientsList=/path/to/your_clients.conf -QoS-1=NO -OoS-1ProxyName=Proxy007 - PredefinedTopic=NO #PredefinedTopicList=/path/to/your_predefinedTopic.conf -Forwarder=NO -#ForwardersList=/path/to/your_forwarers.conf - #RootCAfile=/etc/ssl/certs/ca-certificates.crt #RootCApath=/etc/ssl/certs/ #CertsFile=/path/to/certKey.pem diff --git a/MQTTSNGateway/src/MQTTSNGWAdapterManager.cpp b/MQTTSNGateway/src/MQTTSNGWAdapterManager.cpp index 45be65a..935d58d 100644 --- a/MQTTSNGateway/src/MQTTSNGWAdapterManager.cpp +++ b/MQTTSNGateway/src/MQTTSNGWAdapterManager.cpp @@ -150,7 +150,8 @@ void AdapterManager::checkConnection(void) { _aggregater->checkConnection(); } - else if ( _qosm1Proxy->isActive()) + + if ( _qosm1Proxy->isActive()) { _qosm1Proxy->checkConnection(); } diff --git a/MQTTSNGateway/src/MQTTSNGWAggregater.cpp b/MQTTSNGateway/src/MQTTSNGWAggregater.cpp index e6765ca..1eceedd 100644 --- a/MQTTSNGateway/src/MQTTSNGWAggregater.cpp +++ b/MQTTSNGateway/src/MQTTSNGWAggregater.cpp @@ -46,7 +46,9 @@ void Aggregater::initialize(void) { /* Create Aggregated Clients */ _gateway->getClientList()->setClientList(AGGREGATER_TYPE); - setup((const char*)(_gateway->getGWParams()->gatewayName), Atype_Aggregater); + + string name = _gateway->getGWParams()->gatewayName; + setup(name.c_str(), Atype_Aggregater); _isActive = true; } } diff --git a/MQTTSNGateway/src/MQTTSNGWClientList.cpp b/MQTTSNGateway/src/MQTTSNGWClientList.cpp index c0ecf85..488944b 100644 --- a/MQTTSNGateway/src/MQTTSNGWClientList.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClientList.cpp @@ -79,7 +79,11 @@ void ClientList::setClientList(int type) { throw Exception("ClientList::initialize(): No client list defined by the configuration."); } - params->clientListName = strdup(fileName.c_str()); + + if ( params->clientListName == nullptr ) + { + params->clientListName = strdup(fileName.c_str()); + } } void ClientList::setPredefinedTopics(bool aggrecate) diff --git a/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp b/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp index 7e70a52..b927532 100644 --- a/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp @@ -58,7 +58,6 @@ void ClientRecvTask::initialize(int argc, char** argv) void ClientRecvTask::run() { Event* ev = nullptr; - Client* client = nullptr; AdapterManager* adpMgr = _gateway->getAdapterManager(); QoSm1Proxy* qosm1Proxy = adpMgr->getQoSm1Proxy(); bool isAggrActive = adpMgr->isAggregaterActive(); @@ -69,6 +68,7 @@ void ClientRecvTask::run() while (true) { + Client* client = nullptr; Forwarder* fwd = nullptr; WirelessNodeId nodeId; @@ -105,7 +105,6 @@ void ClientRecvTask::run() } - Client* client = nullptr; SensorNetAddress* senderAddr = _gateway->getSensorNetwork()->getSenderAddress(); if ( packet->getType() == MQTTSN_ENCAPSULATED ) @@ -124,12 +123,6 @@ void ClientRecvTask::run() nodeId.setId( encap.getWirelessNodeId() ); client = fwd->getClient(&nodeId); packet = encap.getMQTTSNPacket(); - - if ( client == nullptr ) - { - /* get client of Forwarder or QoSm1Proxy */ - client = _gateway->getClientList()->getClient(senderAddr); - } } } else @@ -138,8 +131,7 @@ void ClientRecvTask::run() if ( qosm1Proxy->isActive() ) { - /* get ClientId not Client which can send QoS-1 PUBLISH */ - const char* clientName = qosm1Proxy->getClientId(senderAddr); + const char* clientName = qosm1Proxy->getClientId(senderAddr); if ( clientName ) { @@ -152,13 +144,11 @@ void ClientRecvTask::run() continue; } } - else - { - client = _gateway->getClientList()->getClient(senderAddr); - } } } + client = _gateway->getClientList()->getClient(senderAddr); + if ( client ) { /* write log and post Event */ diff --git a/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp b/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp index 1126d52..53bbb43 100644 --- a/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp +++ b/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp @@ -114,17 +114,17 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket* MQTTGWPacket* publish = new MQTTGWPacket(); publish->setPUBLISH(&pub); - if ( !_gateway->getAdapterManager()->isAggregaterActive() ) + if ( _gateway->getAdapterManager()->isAggregaterActive() && client->isAggregated() ) + { + return publish; + } + else { Event* ev1 = new Event(); ev1->setBrokerSendEvent(client, publish); _gateway->getBrokerSendQue()->post(ev1); return nullptr; } - else - { - return publish; - } } void MQTTSNPublishHandler::handlePuback(Client* client, MQTTSNPacket* packet) diff --git a/MQTTSNGateway/src/MQTTSNGWQoSm1Proxy.cpp b/MQTTSNGateway/src/MQTTSNGWQoSm1Proxy.cpp index 591043e..50ff56c 100644 --- a/MQTTSNGateway/src/MQTTSNGWQoSm1Proxy.cpp +++ b/MQTTSNGateway/src/MQTTSNGWQoSm1Proxy.cpp @@ -54,14 +54,9 @@ void QoSm1Proxy::initialize(void) /* Create QoS-1 Clients */ _gateway->getClientList()->setClientList(QOSM1PROXY_TYPE); - /* set ClientId of this Proxy */ - const char* name = CLIENTPROXY; - if (_gateway->getParam("QoS-1ProxyName", param) == 0 ) - { - name = param; - } /* initialize Adapter */ - setup(name, Atype_QoSm1Proxy); + string name = string(_gateway->getGWParams()->gatewayName) + "QoS-1"; + setup(name.c_str(), Atype_QoSm1Proxy); _isActive = true; } } diff --git a/MQTTSNGateway/src/MQTTSNGateway.h b/MQTTSNGateway/src/MQTTSNGateway.h index 3344cfa..b4c0f5c 100644 --- a/MQTTSNGateway/src/MQTTSNGateway.h +++ b/MQTTSNGateway/src/MQTTSNGateway.h @@ -43,8 +43,6 @@ namespace MQTTSNGW #define CLIENT "Client" #define CLIENTS "Clients" #define UNKNOWNCL "Unknown Client !" -#define CLIENTPROXY "ClientProxy" -#define CLIENTPROXY_SECURE "ClientProxyS" #define LEFTARROW "<---" #define RIGHTARROW "--->"