All Collections
Connect your Devices
Connect Robustel R1520 Dual-SIM Cellular VPN Router to Ubidots through MQTT
Connect Robustel R1520 Dual-SIM Cellular VPN Router to Ubidots through MQTT

This article explores the required configuration steps to set up and connect the Robustel R1520 to Ubidots using MQTT protocol

S
Written by Sergio M
Updated over a week ago

Robustel's R1520 is a high-performance, industrial-grade gateway provisioned with dual-SIM 4G LTE network connectivity, thus, allowing fast and reliable internet access in remote areas. It has the required interfaces to connect to sensors/devices featuring several different connection protocols such as Modbus Serial RS-485, RS-232, Modbus TCP/IP, Wi-Fi AP Mode, digital Input/Output (DI/DO), analogue input (AI).

Aside its broad hardware features, the software of the R1520 also stands out: You can manage and configure the R1520 by accessing RobustOS, Robustel's proprietary router operating system, from any web browser .RobustOS makes it straightforward for the user to configure and manage the services on the R1520 such as MQTT, Modbus, etc., thanks to its no-code approach.

Requirements

Table of Contents

1. Configure the R1520 to connect to the internet

  • Provide power to the R1520 by connecting it using the included power connector as shown below:

  • Connect the router’s Ethernet port to a PC with a standard Ethernet cable.

  • In order to be able to log in to the R1520, manually configure the PC with a static IP address on the same subnet as the gateway address (192.168.0.1); therefore, your PC's static IP address should be in the subnet 192.168.0.x.

  • Enter the gateway's web interface, by typing 192.168.0.1 into your web browser's search bar:

  • When prompted for credentials, use admin in both fields and tap the LOGIN button.

Note: The following steps are meant to configure the R1520 to connect to the internet using Wi-Fi Client mode. If you require to connect it to the internet using Ethernet or cellular, please refer to the official documentation.

  • Once the web interface loads, click Interface WiFi and set the following parameters:

  • Click Interface Link Manager. Click on the Primary Link drop-down menu and select WLAN. Once you have done this, the WLAN entry will be displayed under the Link Settings section.

  • Click the edit button corresponding to the WLAN entry.

  • Once in the WLAN settings page, edit the following settings as specified below and then click the Submit button.

    • Connection Type: DHCP.

    • SSID: Set your local network SSID.

    • Connect to Hidden SSID: Set this option according to your requirements. However, in this guide, it will be disabled.

    • Password: Set your local network password.

    • Enable: Enable this feature according to your requirements. In this guide, it will be enabled.

  • After clicking the Submit button, you will be taken to the previous visualization. Click this page's Submit button and then click on Save & Apply. If this step is completed successfully, your R1520 will connect to the internet.

2. Download and install the required E2C Apps

  • Register on Robustel's RCMS Cloud.

  • Once logged in, click on App Center, select E2C APP and then use the Series filter to select R1520 Series.

  • Download both the e2c_s_modbus and e2c_n_mqtt E2C Apps. These apps let the user handle the Modbus interface and the MQTT service respectively.

  • Head back to the R1520 web interface.

  • Go to System App Center.

  • Click the browse button and select any of the two previously download E2C Apps. Once you locate the file, click the Install button. Repeat this step until you have installed both E2C Apps and then click the Save & Apply button.

  • After installing the two apps, they will be displayed under the Installed Apps section.

3. Configure the E2C-Modbus

Note: This guide assumes that your sensor is already connected to the R1520 Modbus RS485 interface. If that is not the case, please refer to the device's hardware documentation in order to know more about its Modbus interface.

  • In the R1520 web interface, go to Edge2Cloud E2C Modbus and edit the following settings in the General Settings tab:

    • Enable: Enable this option by clicking the slider and making sure it's on the ON position.

    • Configure Tags in GUI: Enable this option by clicking the slider and making sure it is on the ON position. This will let you configure which Modbus slave and which address you want to read, as well as to assign Tags to it; all from the graphical interface.

    • All the other settings that were not mentioned are up to the user to configure according to their requirements.

  • In the Serial Port Settings edit the following settings:

    • Device Port: Select COM2 from the drop-down menu. This is the virtual port in charge of the Serial RS485 interface.

    • Baud Rate, Data Bits, Stop Bits, Parity: Select these settings according to your sensor's settings.

  • In the Channels section, click on the "+" icon to add the Tags:

  • Once you click the "+" icon, the following visualization will be displayed. There, edit the settings as follows:

    • Tag: This is the label associated to this variable. I.e, in the output JSON file, this variable will appear as

      {"xy-md02-temperature" : <some numerical value>}

    • Type: This is the interface through which the Modbus protocol will run. In this guide, RTU is used since the sensor is connected through the serial port to the R1520. Nonetheless, you must select this according to your particular implementation.

    • Slave ID: This is the address of the slave device that you want to read from.

    • Function Code: You should select this according to what you wish to read from the sensor. In this case, both the temperature and humidity are input register, however, select this according to your requirements.

    • Address: This is the address of the input register required to be read. Match this value according to your requirements.

    • Click the Submit button to save the changes.

  • Repeat the above process for every sensor/register/coil that you require. At last, it will look as shown below. Click the Submit button and then hit Save & Apply.

Note: In this particular example, two different input register's values are required to be sent to Ubidots: temperature and humidity, that is why two different Channels are shown above.

  • If everything was configured correctly, the sensor readings can be visualized on the Status tab as shown below:

4. Configure the E2C-Broker

  • Go to Edge2Cloud E2C Broker. Click on the General tab

  • Edit the settings as follows:

    • Enable: Set the slider to ON to enable the Broker.

    • Save message to database: Set the slider to ON.

    • Remote Access Enable: Set the slider to ON.

    • Other unmentioned parameters are to be set according to the user requirements.

  • Click the Submit button and then hit Save & Apply.

5. Configure the E2C-MQTT

  • Go to your Ubidots account Devices Functions.

  • Create a new Function and edit its code. Paste the following one, but first, make the following changes:

    • Set the Ubidots token that you wish to use for this application on the variable token at line 7.

    • Edit the operations_on_data dictionary so its keys match the Tags that you are assigning to each Modbus register on the R1520 E2C Modbus App.

    • Edit the operations_on_data dictionary so its values match the required operations on each variable.

  • For instance, if you used "xyz-sensor-reading-1" and "xyz-sensor-reading-2" as the Tags names on the E2C Modbus App, then the operations_on_data dictionary keys should be "xyz-sensor-reading-1" and "xyz-sensor-reading-2".

  • Also, you should edit the lambda function according to the required operations on the data according to your sensor's datasheet. For instance, the sensor used on this guide reports the temperature and humidity values, both multiplied by a factor of 10, so in order to get the actual measurement, it is needed to divide the obtained value by 10.

import requests
import time

REQUESTS_FUNCTIONS = {"get": requests.get, "post": requests.post}
BASE_URL = "https://industrial.api.ubidots.com"
excluded_keys = ["deviceType", "subDeviceId", "timestamp"]
token = '<your-ubidots-token>'

operations_on_data = {
"xy-md02-temperature": lambda x: x / 10,
"xy-md02-humidity" : lambda x: x / 10,
}


def main(args):

#Print arguments for debugging purpose
print(args)
incoming_payload_list = args['payload']['payload']
device_label = args['topic'].rsplit('/')[-1]
payload = {}

for each_device_json in incoming_payload_list:
for each_device_key, each_device_value in each_device_json.items():
if each_device_key in excluded_keys:
continue
if isinstance(each_device_json[each_device_key], dict):
if each_device_key in excluded_keys:
continue
inner_json = each_device_json[each_device_key]
for inner_key,inner_value in inner_json.items():
if not inner_key in excluded_keys:
payload[inner_key] = {"value" : operations_on_data[inner_key](inner_value), "timestamp" :inner_json['timestamp'] }
else:
payload[each_device_key] = each_device_value


# Use the remaining parameters as payload
req = update_device(device_label, payload, token)

# Prints the request result
print("[INFO] Request result:")
print(req.text)
return {"status": "Ok", "result": req.json()}

def update_device(device, payload, token):
"""
updates a variable with a single dot
"""

url = "{}/api/v1.6/devices/{}".format(BASE_URL, device)
headers = {"X-Auth-Token": token, "Content-Type": "application/json"}

req = create_request(url, headers, payload, attempts=5, request_type="post")

return req

def create_request(url, headers, data, attempts, request_type):
"""
Function to create a request to the server
"""

request_func = REQUESTS_FUNCTIONS.get(request_type)

kwargs = {"url": url, "headers": headers}

if request_type == "post":
kwargs["json"] = data

try:
req = request_func(**kwargs)
print("[INFO] Request result: {}".format(req.text))
status_code = req.status_code
time.sleep(1)

while status_code >= 400 and attempts < 5:
req = request_func(**kwargs)
print("[INFO] Request result: {}".format(req.text))
status_code = req.status_code
attempts += 1
time.sleep(1)

return req
except Exception as e:
print("[ERROR] There was an error with the request, details:")
print(e)
return None
  • After editing the code, click the Make it live button.

  • Copy the HTTPs Endpoint URL corresponding to this function. It will be something like:

    https://parse.ubidots.com/prv/<your-ubidots-username>/<your-ubifunction-name>
  • Go back to the R1520 web interface.

  • Click on the Status tab and scroll down to the LAN Status section. Copy the MAC address of your R1520. This will be used as a unique identifier on Ubidots.

  • Go to Edge2Cloud E2C MQTT. There, select the MQTT tab.

  • In the General Settings tab edit the following settings:

    • Enable: Set the slider to the ON position in order to enable the MQTT service.

    • MQTT TLS Enable: Disable this option. This tutorial will not use encryption. If you require TLS, please refer to the documentation to configure it.

    • Remote Server: functions.ubidots.com. This is Ubidots dedicated endpoint for UbiFunctions.

    • Remote Port: 1883. This is the port for no-secured connection.

    • Username: Your Ubidots username.

    • Password: Your Ubidots Token.

    • Client ID: Any random and unique 15 length character string.

  • All other unmentioned settings are up for the user to be configured.

  • In the Topic Settings tab, set the Publish Topic, Response Topic and Subscribe Topic to:

/prv/<your-ubidots-username>/<your-ubifunction-name>/<your-r1520-mac-address>
  • For instance, if your Ubidots username is JohnDoe, the function's name is Robustel App, and your device's MAC address is F1:AB:7D:C1:56:AF, then the topic is:

/prv/johndoe/robustel-app/f1ab7dc156af

  • Click the Submit button and then hit Save & Apply.

  • If everything was configured correctly, heading to the Status tab on the E2C MQTT App should display the Connected status.

  • Also, by this point, you should be able to see a newly created device on your Ubidots account, whose label is precisely the R1520 MAC address and its variables are the Tags set on the E2C Modbus App on the R1520 web interface.

6. Feedback, suggestions and related articles

Feel free to post questions or suggestions in our community portal, or contact us via support@ubidots.com.

Other users also found helpful...

Did this answer your question?