Library for MQTT

Committer:
pavleradojkovic
Date:
Mon Jun 20 16:24:43 2022 +0000
Revision:
0:ba7e439238ab
Inital commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pavleradojkovic 0:ba7e439238ab 1 # MQTT-SN Transparent / Aggrigating Gateway
pavleradojkovic 0:ba7e439238ab 2
pavleradojkovic 0:ba7e439238ab 3 **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).
pavleradojkovic 0:ba7e439238ab 4 This Gateway can run as a transparent or aggrigating Gateway by specifying the gateway.conf.
pavleradojkovic 0:ba7e439238ab 5
pavleradojkovic 0:ba7e439238ab 6 ### **step1. Build the gateway**
pavleradojkovic 0:ba7e439238ab 7 ````
pavleradojkovic 0:ba7e439238ab 8 $ git clone -b experiment https://github.com/eclipse/paho.mqtt-sn.embedded-c
pavleradojkovic 0:ba7e439238ab 9 $ cd paho.mqtt-sn.embedded-c/MQTTSNGateway
pavleradojkovic 0:ba7e439238ab 10 $ make
pavleradojkovic 0:ba7e439238ab 11 $ make install
pavleradojkovic 0:ba7e439238ab 12 $ make clean
pavleradojkovic 0:ba7e439238ab 13 ````
pavleradojkovic 0:ba7e439238ab 14 MQTT-SNGateway, MQTT-SNLogmonitor and *.conf files are copied into ../ directory.
pavleradojkovic 0:ba7e439238ab 15 If you want to install the gateway into specific directories, enter a command line as follows:
pavleradojkovic 0:ba7e439238ab 16 ````
pavleradojkovic 0:ba7e439238ab 17 $ make install INSTALL_DIR=/path/to/your_directory CONFIG_DIR=/path/to/your_directory
pavleradojkovic 0:ba7e439238ab 18 ````
pavleradojkovic 0:ba7e439238ab 19
pavleradojkovic 0:ba7e439238ab 20
pavleradojkovic 0:ba7e439238ab 21 ### **step2. Execute the Gateway.**
pavleradojkovic 0:ba7e439238ab 22
pavleradojkovic 0:ba7e439238ab 23 ````
pavleradojkovic 0:ba7e439238ab 24 $ cd ../
pavleradojkovic 0:ba7e439238ab 25 $ ./MQTT-SNGateway [-f Config file name]
pavleradojkovic 0:ba7e439238ab 26 ````
pavleradojkovic 0:ba7e439238ab 27
pavleradojkovic 0:ba7e439238ab 28
pavleradojkovic 0:ba7e439238ab 29 ### **How to Change the configuration of the gateway**
pavleradojkovic 0:ba7e439238ab 30 **../gateway.conf** Contents are follows:
pavleradojkovic 0:ba7e439238ab 31
pavleradojkovic 0:ba7e439238ab 32 <pre><dev>
pavleradojkovic 0:ba7e439238ab 33
pavleradojkovic 0:ba7e439238ab 34 # config file of MQTT-SN Gateway
pavleradojkovic 0:ba7e439238ab 35 #
pavleradojkovic 0:ba7e439238ab 36
pavleradojkovic 0:ba7e439238ab 37 BrokerName=iot.eclipse.org
pavleradojkovic 0:ba7e439238ab 38 BrokerPortNo=1883
pavleradojkovic 0:ba7e439238ab 39 BrokerSecurePortNo=8883
pavleradojkovic 0:ba7e439238ab 40
pavleradojkovic 0:ba7e439238ab 41 #
pavleradojkovic 0:ba7e439238ab 42 # When AggregatingGateway=YES or ClientAuthentication=YES,
pavleradojkovic 0:ba7e439238ab 43 # All clients must be specified by the ClientList File
pavleradojkovic 0:ba7e439238ab 44 #
pavleradojkovic 0:ba7e439238ab 45
pavleradojkovic 0:ba7e439238ab 46 ClientAuthentication=NO
pavleradojkovic 0:ba7e439238ab 47 AggregatingGateway=NO
pavleradojkovic 0:ba7e439238ab 48 QoS-1=NO
pavleradojkovic 0:ba7e439238ab 49 Forwarder=NO
pavleradojkovic 0:ba7e439238ab 50
pavleradojkovic 0:ba7e439238ab 51 #ClientsList=/path/to/your_clients.conf
pavleradojkovic 0:ba7e439238ab 52
pavleradojkovic 0:ba7e439238ab 53 PredefinedTopic=NO
pavleradojkovic 0:ba7e439238ab 54 #PredefinedTopicList=/path/to/your_predefinedTopic.conf
pavleradojkovic 0:ba7e439238ab 55
pavleradojkovic 0:ba7e439238ab 56 #RootCAfile=/etc/ssl/certs/ca-certificates.crt
pavleradojkovic 0:ba7e439238ab 57 #RootCApath=/etc/ssl/certs/
pavleradojkovic 0:ba7e439238ab 58 #CertsFile=/path/to/certKey.pem
pavleradojkovic 0:ba7e439238ab 59 #PrivateKey=/path/to/privateKey.pem
pavleradojkovic 0:ba7e439238ab 60
pavleradojkovic 0:ba7e439238ab 61 GatewayID=1
pavleradojkovic 0:ba7e439238ab 62 GatewayName=PahoGateway-01
pavleradojkovic 0:ba7e439238ab 63 KeepAlive=900
pavleradojkovic 0:ba7e439238ab 64 #LoginID=your_ID
pavleradojkovic 0:ba7e439238ab 65 #Password=your_Password
pavleradojkovic 0:ba7e439238ab 66
pavleradojkovic 0:ba7e439238ab 67
pavleradojkovic 0:ba7e439238ab 68 # UDP
pavleradojkovic 0:ba7e439238ab 69 GatewayPortNo=10000
pavleradojkovic 0:ba7e439238ab 70 MulticastIP=225.1.1.1
pavleradojkovic 0:ba7e439238ab 71 MulticastPortNo=1883
pavleradojkovic 0:ba7e439238ab 72
pavleradojkovic 0:ba7e439238ab 73 # XBee
pavleradojkovic 0:ba7e439238ab 74 Baudrate=38400
pavleradojkovic 0:ba7e439238ab 75 SerialDevice=/dev/ttyUSB0
pavleradojkovic 0:ba7e439238ab 76 ApiMode=2
pavleradojkovic 0:ba7e439238ab 77
pavleradojkovic 0:ba7e439238ab 78 # LOG
pavleradojkovic 0:ba7e439238ab 79 ShearedMemory=NO;
pavleradojkovic 0:ba7e439238ab 80
pavleradojkovic 0:ba7e439238ab 81 </dev></pre>
pavleradojkovic 0:ba7e439238ab 82
pavleradojkovic 0:ba7e439238ab 83 **BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. **BrokerSecurePortNo** is for TLS connection.
pavleradojkovic 0:ba7e439238ab 84 **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().
pavleradojkovic 0:ba7e439238ab 85 Client should know the MulticastIP and MulticastPortNo to send a SEARCHGW message.
pavleradojkovic 0:ba7e439238ab 86 **GatewayId** is used by GWINFO message.
pavleradojkovic 0:ba7e439238ab 87 **KeepAlive** is a duration of ADVERTISE message in seconds.
pavleradojkovic 0:ba7e439238ab 88 when **AggregatingGateway** or **ClientAuthentication** is **YES**, All clients which connect to the gateway must be declared by a **ClientsList** file.
pavleradojkovic 0:ba7e439238ab 89 Format of the file is ClientId and SensorNetwork Address. e.g. IP address and Port No etc, in CSV. more detail see clients.conf.
pavleradojkovic 0:ba7e439238ab 90 When **QoS-1** is **YES**, QoS-1 PUBLISH is available. All clients which send QoS-1 PUBLISH must be specified by Client.conf file.
pavleradojkovic 0:ba7e439238ab 91 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.
pavleradojkovic 0:ba7e439238ab 92 When **Forwarder** is **YES**, Forwarder Encapsulation Message is available. Connectable Forwarders must be declared by a **ClientsList** file.
pavleradojkovic 0:ba7e439238ab 93
pavleradojkovic 0:ba7e439238ab 94
pavleradojkovic 0:ba7e439238ab 95 ### ** How to monitor the gateway from remote. **
pavleradojkovic 0:ba7e439238ab 96
pavleradojkovic 0:ba7e439238ab 97 Uncomment line32 in MQTTSNGWDefined.h.
pavleradojkovic 0:ba7e439238ab 98
pavleradojkovic 0:ba7e439238ab 99 `//#define RINGBUFFER // print out Packets log into shared memory./"`
pavleradojkovic 0:ba7e439238ab 100 ````
pavleradojkovic 0:ba7e439238ab 101 $ make
pavleradojkovic 0:ba7e439238ab 102 $ make install
pavleradojkovic 0:ba7e439238ab 103 $ make clean
pavleradojkovic 0:ba7e439238ab 104 ````
pavleradojkovic 0:ba7e439238ab 105 restart the gateway.
pavleradojkovic 0:ba7e439238ab 106 open ssh terminal and execute LogMonitor.
pavleradojkovic 0:ba7e439238ab 107
pavleradojkovic 0:ba7e439238ab 108 `$ ./MQTT-SNLogmonitor`
pavleradojkovic 0:ba7e439238ab 109
pavleradojkovic 0:ba7e439238ab 110 Now you can get the Log on your terminal.
pavleradojkovic 0:ba7e439238ab 111
pavleradojkovic 0:ba7e439238ab 112