Reyax RYWB116 User manual

19-SEP-2019 56312E30
RYWB116
MQTT Client Application
User Guide

2
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
PROTOCOL OVERVIEW
MQTT is a publish-subscribe based "light weight" messaging protocol for use on top of the
TCP/IP protocol.
The MQTT connection itself is always between one client and the broker, no client is connected to
another client directly.
MQTT CLIENT
A MQTT client is any device from a micro controller up to a full fledged server, that has a MQTT
library running and is connecting to an MQTT broker over any kind of network.
MQTT Clients can share the information on a particular topic using MQTT protocol.
MQTT clients connect to the MQTT broker using TCP connection and can subscribe and
publish on any desired topic.
The other clients which are subscribed for that topic will receive the published messages.

3
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
MQTT BROKER
The publish-subscribe messaging pattern requires a message broker.
The broker is primarily responsible for receiving all messages, filtering them,
decide who is interested in it and then sending the message to all subscribed clients.
It also holds the session of all persisted clients including subscriptions and missed messages.
Another responsibility of the broker is the authentication and authorization of clients.
A simple demonstration of subscribing and publishing of temperature is shown below
Figure 1: Demonstration of MQTT protocol

4
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
APPLICATION OVERVIEW
This is a sample application which demonstrates the following MQTT functionality.
1. MQTT client (RYWB116) connects to the MQTT broker which is running on Windows PC 2
2. Subscribes to the given topic
3. Publishes MQTT message on that topic and receives the messages which are published on
that topic
SETUP REQUIRED
1.
Windows PC 1 with Coocox IDE
2.
RYWB116 device
3.
WLAN Access point
4.
Windows PC 2 with MQTT broker installed in it
5.
Windows PC 3 with MQTT utility which acts as MQTT client
NOTE:
1.
MQTT broker for different OS platforms can be downloaded from the link
http://mosquitto.org/download/
2.
MQTT Utility which has to be installed in Windows PC 3 can be downloaded from the below
given link
https://www.eclipse.org/downloads/download.php?file=/paho/1.0/org.eclipse.pah
o.mqtt.utility-1.0.0.jar

5
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
DESCRIPTION
This application is used to configure RYWB116 connected to a WLAN Access point.
This example witness MQTT Client functionality of the RYWB116. This example demonstrates
how message exchanges happens between two MQTT clients on the subscribed topic.
Figure 2: MQTT Client demo set up

6
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
CONFIGURING THE APPLICATION
Edit the rsi_mqtt.c file in the following path.
sapis/examples/wlan/mqtt_client From given configuration,
1.
Configure the module to join to the specific Access point by configuring following
parameters
SSID refers to the name of the Access point to connect.
PSK refers to the secret key if the Access point was configured in WPA/WPA2
security modes.
#define SSID
“<ap_name>”
#define CHANNEL_NO
0
#define SECURITY_TYPE
<security-type>
#define PSK
“<psk>”
2.
To configure the IP of the RYWB116 module in DHCP mode
To configure IP through dhcp set DHCP_MODE to 1, else configure to 0
3.
To configure static IP address
IP address to be configured to the device should be in long format and in
little endian byte order. The following parameters are valid only if
DHCP_MODE is 1.
Example: To configure “192.168.10.1” as IP address, update the macro
DEVICE_IP as 0x010AA8C0.
IP address of the gateway should also be in long format and in little
endian byte order
Example: To configure “192.168.10.1” as Gateway, update the macro
GATEWAY as 0x010AA8C0
IP address of the network mask should also be in long format and in little
endian byte order
Example: To configure “255.255.255.0” as network mask, update the
macro NETMASK as 0x00FFFFFF
4.
Connect to the MQTT broker/server by configuring the following
parameters
MQTT server IP address should be in long format and in little endian
byte order
#define DHCP_MODE <dhcp mode>
#define DEVICE_IP 0X010AA8C0
#define GATEWAY 0x010AA8C0
#define NETMASK 0x00FFFFFF
#define SERVER_IP_ADDRESS 0x640AA8C0

7
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
Server port number of MQTT broker/server
Client port number of the MQTT client
5.
The following parameters are configured if OS is used.
WLAN task priority is given and this should be of low priority
Driver task priority is given and this should be of highest priority
WLAN Task stack size is configured by this macro
Driver Task stack size is configured by this macro
6.
The following parameters are used for the MQTT client specific
information configuration
MQTT client Keep alive period
Memory to initialize MQTT client Info structure
Global buffer or memory which is used for MQTT client initialization.
This buffer is used for the MQTT client information storage.
QOS of the message. This QOS is MQTT protocol specific and the valid
values are 0,1 and 2. This field indicates the level of assurance for
delivery of an Application Message. The QoS levels are
0 - At most once delivery
1 - At least once delivery
2 - Exactly once delivery
MQTT topic to which client is supposed to subscribe
MQTT Message to publish on the topic subscribed
#define CLIENT_PORT 1883
#define RSI_DRIVER_TASK_PRIORITY 1
#define RSI_DRIVER_TASK_STACK_SIZE 500
#define MQTT_CLIENT_INIT_BUFF_LEN 3500
uint8_t mqqt_client_buffer[MQTT_CLIENT_INIT_BUFF_LEN]
#define QOS 0
uint8_t publish_message[] ="THIS IS MQTT CLIENT DEMO
FROM REYAX"
#define SERVER_PORT 1883
#define RSI_WLAN_TASK_PRIORITY 1
#define RSI_WLAN_TASK_STACK_SIZE 500
#define RSI_KEEP_ALIVE_PERIOD 100
#define RSI_MQTT_TOPIC "REYAX"

8
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
MQTT Client ID with which MQTT client connects to MQTT
broker/server
user name for login credentials
password for login credentials
Edit the Wlan configuration file:
sapis/include/rsi_wlan_config.h
CONCURRENT_MODE
DISABLE
RSI_FEATURE_BIT_MAP
FEAT_SECURITY_OPEN
RSI_TCP_IP_BYPASS
DISABLE
RSI_TCP_IP_FEATURE_BIT_MAP
TCP_IP_FEAT_DHCPV4_CLIENT
RSI_CUSTOM_FEATURE_BIT_MAP
0
RSI_BAND
RSI_BAND_2P4GHZ
uint8_t clientID[] = "MQTTCLIENT"
int8_t username[] = "username"
int8_t password[] = "password"

9
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
EXECUTING THE APPLICATION
1. Connect Windows PC 3 and Windows PC 2 to the access point
2. Run MQTT broker application with the server port configured SERVER_PORT on
Windows PC 2 as shown in the screen shot below
3. Open the MQTT client Utility in Windows PC 3 and connect to the MQTT broker which is
running in the Windows PC 2 and subscribe to the topic given in the application file
RSI_MQTT_TOPIC.The screen shot is given below for the MQTT utility
Give the port number of the MQTT broker in the port field as 1883
Enter the topic to subscribe as “REYAX”
Figure 3: MQTT Broker application listening state

10
RYWB116 MQTT Client Application User Guide
Copyright © 2019, REYAX TECHNOLOGY CO., LTD.
4. Connect RYWB116 to the Windows PC running Cocoox IDE.
5. Configure the macros in the files located at
sapis/examples/wlan/rsi_mqtt.c
sapis/include/rsi_wlan_config.h
6. Build and launch the application.
7. After the program gets executed, RYWB116 would be connected to same Access point
having the configuration same that of in the application and get IP.
8. Once the RYWB116 is connected to the MQTT broker, connected MQTT clients information
message is displayed in the MQTT broker application.
9. After the subscription to the topic “REYAX”, publish a message [“THIS IS MQTT
CLIENT DEMO FROM REYAX”] on the subscribed topic.
10. Now this message is received by the MQTT utility which is running on Windows PC 3.
11. Now publish a message using MQTT Utility on the same topic. Now this message is
message received by RYWB116.
LIMITATIONS
MQTT client application keeps on polling for the data to receive on the subscribed topic
irrespective of receive timeout mentioned in the rsi_mqtt_poll_for_recv_data API.
NOTE:1. Multiple MQTT client instances can be created
Taiwan: sales@reyax.com
China: sales@reyax.com.cn
http://reyax.com
Table of contents
Other Reyax Microcontroller manuals
Popular Microcontroller manuals by other brands

Atmel
Atmel AT91 Series Application note

NXP Semiconductors
NXP Semiconductors MPC5777M datasheet

Microchip Technology
Microchip Technology PIC16F716 datasheet

Commodore
Commodore 64 MACRO manual

DEUTSCHMANN AUTOMATION
DEUTSCHMANN AUTOMATION UNIGATE IC-DeviceNet instruction manual

Microchip Technology
Microchip Technology DM164120-1 user guide