15 December, 2020

Edge Computing with Syrus 4G IoT Gateway and Flespi MQTT broker

Build, run, and deploy your application with real-time computing resources and data storage embedded in Syrus 4G and use all the power of the Flespi IoT platform to get your project done.

“New business requirements and technical capabilities are driving more computing and communications power toward the edge of the network”, according to Gartner Research report. 

"Edge architectures and technologies will be an essential component of innovative products and services." Digital Communications Technologies LLC (DCT) based in Miami Florida with more than 20 years of manufacturing smart IoT devices with powerful management & diagnostic tools and advanced interactions through APIs & SDKs announce that its Syrus 4G IoT telematics gateway with edge computing power is fully integrated with the Flespi MQTT broker

Developers, system integrators, service providers, and IT professionals who want to harness the power of developing from the edge and benefit from an open development platform using Syrus 4G operational system APEX can now integrate with Flespi IoT platform via an MQTT publish/subscribe broker. 

The following tutorial describes how to integrate Syrus 4G with Flespi MQTT broker and start receiving data from multiple sources like CAN J1939 / J1708 / OBDII, Bluetooth or Wi-Fi peripherals, RS232 / RS485 connected accessories, multiple input/output signals, 3-axis accelerometer, and GNSS + 2G/3G/4G global band cellular module.

Developers just need to add the code + creativity based on fleet operators’ requests. Here is a list of ongoing applications that are being developed and hosted into Syrus 4G using Node or Python SDKs and all capture data reported via the Flespi MQTT broker:

  • Virtual Co-pilot with in-cabin BT speaker voice alerts

  • Video telematics with Open SDK dash cameras via Wi-Fi and/or Ethernet

  • Face recognition applications for automatic driver ID

  • Engine diagnostics analysis

  • Hands-Free two-way audio communications

  • ADAS analysis and reporting

  • TPMS integration with different hardware vendors.

Developing Architecture for Syrus 4G

syrus 4g iot gateway architecture

Integration Syrus 4G — Flespi

Description  

Here's a detailed integration example between Syrus 4G IoT Telematics Gateway with Flespi Platform over MQTT connection. 

syrus 4g flespi integration

Getting Started 

Preparing Flespi  MQTT Broker 

1. Token creation

Log in to your Flespi Account and go to the Tokens section:

flespi token create

Click the green “+” button in the bottom right corner:

add new flespi token

A prompt will be displayed where you can configure the name, expiration date, and restrictions. If you need more info about these fields, follow the guide here

flespi token config mqtt

2. Channel creation

Go to the Telematics Hub section and select Channels:

flespi channel create

Click the green “+” button in the bottom right corner. 

A prompt will be displayed where you type the name of your channel, set TTL, and the protocol that you will use — in this case, it’s “mqtt”, so we need to configure the Broker URI, the username (which is the Token from the previous section) and topics:

flespi mqtt channel config

Note that the Clean session toggle should be disabled — this way you will not lose messages that arrive when the channel is offline.

flespi channel config mqtt topics

3. Create a device

Go to the Telematics Hub section and select Devices:

flespi device create

Click the green “+” button in the bottom right corner. 

A prompt will be displayed where you should fill the fields with the name of your device, device type (“mqtt”), TTL, and rotation size:

flespi mqtt device config

Syrus 4G IoT Telematics Gateway Configuration

The first step to do is to make sure you have the latest version of Apex OS.

1. Preparing your System

Go to Management Tool (http://192.168.9.2 if you’re over USB cable), select System, and confirm that you’re up to date:

syrus 4 management tool

Now go to Applications Manager -> Check for updates and make sure you have the latest version of the SyrusJS application installed:

syrus 4 management tool check for updates

2. Create an instance

In the application manager pull down the menu of SyrusJS, this will show all the versions of the application installed; select the latest one, and Create a New Instance:

syrus 4 management tool create new instance

Name your instance and select the Create Instance button: 

syrus 4 management tool create instance button

Now you have your instance created:

syrus 4 management tool instance created

3. Creating your configuration files

We need to create two files on any notepad application (notepad++, sublime, vscode, etc). You can name it as you want but the extension must be syrus.conf:

syrus 4 management tool create config files

The first file contains the destination data, protocol, output format, MQTT URI, username and topics, here is an example:

### DESTINATIONS
define destination mqtt json mqtt://mqtt.flespi.io:443 protocol="wss" username="FlespiToken [YOUR_TOKEN]" subscribe="dev/messagesrx" publish="dev/messagestx"

Replace [YOUR_TOKEN] with the value from Flespi.

More information: https://syrus.pegasusgateway.com/syrdocs/syrus4/syruslang/#destinations 

The second file contains all the events that will be sent to Flespi over MQTT. Here is an example that will send Ignition On/Off events and track points every minute:

#######  ###### ####### ######  #######
############ START MQTT EVENT ###########
define fieldset mqtt fields="ident":$modem.imei,"position.latitude":$gnss.latitude,"position.longitude":$gnss.longitude,"position.direction":$gnss.heading,"position.hdop":$gnss.hdop,"position.pdop":$gnss.pdop,"position.vdop":$gnss.vdop,"position.speed":$gnss.mph,"position.altitude":$gnss.altitude,"event.label":label,"event.enum":code,"io_in1":$io.in1,"io_in2":$io.in2,"io_in3":$io.in3,"io_out1":$io.out1,"io_out2":$io.out2,"io_ign":$io.ign,"io_pwr":$io.ex_pwr_st
 
define group mqtt
set destinations group=mqtt mqtt
 
define tracking_resolution mqtt_tracking 60m 25deg 1000mts
 
define signal ignitionON min_duration=5s $io.ign == true
define signal ignitionOFF min_duration=5s $io.ign == false
 
define event ignitionONmqtt group=mqtt fieldset=mqtt ack=seq label=ignonmqtt code=102 trigger=ignitionON
define event ignitionOFFmqtt group=mqtt fieldset=mqtt ack=seq label=ignoffmqtt code=103 trigger=ignitionOFF
 
# Define tracking event, a single tracking resolution signal that can be controlled by different actions
define event trackingOffMqtt group=mqtt fieldset=mqtt ack=seq label=prdtst code=100 trigger=@tracking_resolution.mqtt_tracking.signal,ignitionOFF,and
define event trackingOnMqtt group=mqtt fieldset=mqtt ack=seq label=trckpnt code=101 trigger=@tracking_resolution.mqtt_tracking.time,ignitionON,and
define event trackingHeadingMqtt group=mqtt fieldset=mqtt ack=seq label=heading code=140 trigger=@tracking_resolution.mqtt_tracking.heading,ignitionON,and
define event trackingDistanceMqtt group=mqtt fieldset=mqtt ack=seq label=distance code=141 trigger=@tracking_resolution.mqtt_tracking.distance,ignitionON,and
 
############ END MQTT EVENT ###########
#######  ###### ####### ######  #######

If you need more information about how to configure other events, please refer to the SyrusLang documentation.

4. Upload your configuration files

Select your created instance:

syrus 4 management tool select instance

Go to the Data Folder tab:

syrus 4 management tool data folder

Select Upload File:

syrus 4 management tool upload file

Search on your local disk for the previously created configuration files and upload them one by one:

syrus 4 management tool loading files

Go to the Configuration tab, pull down Configuration and Destination File, select your previously updated items, and click the Save button:

syrus 4 management tool configuration and destination file

5. Start your instance

Finally, go back to the Information tab and click the Start button:

syrus 4 management tool configuration start

Check your data in Flespi Device

Select your device and go to the Toolbox tab:

flespi mqtt device toolbox tab messages

If you click on the message, you will see its content with all the required parameters:

{
   "can.engine.rpm": 1352,
   "can.engine.temperature": 91,
   "can.fuel.consumed": 10,
   "can.fuel.temperature": 80,
   "can.intake.map": 142,
   "can.throttle.pedal.level": 37.6,
   "can.vehicle.speed": 31.7,
   "channel.id": 39053,
   "device.id": 1299173,
   "device.name": "867698041079602",
   "device.type.id": 172,
   "event.enum": "103",
   "event.label": "ignoffmqtt",
   "ident": "867698041079602",
   "io_ign": false,
   "io_in1": "false",
   "io_in2": "false",
   "io_in3": "false",
   "io_out1": "false",
   "io_out2": "false",
   "position.altitude": "1.136",
   "position.direction": 291.27,
   "position.hdop": 9.99,
   "position.latitude": "20.993832",
   "position.longitude": "-89.711002",
   "position.pdop": 9.99,
   "position.speed": 0.25289869676324,
   "position.vdop": 9.99,
   "protocol.id": 39,
   "server.timestamp": 1605907709.701692,
   "timestamp": 1605907709.666925
}

Once you see that the proper data is correctly registered in the flespi device, it can be consumed via REST API and MQTT API or forwarded to other platforms for further processing.

***

The Syrus ecosystem by DCT offers top-notch multi-purpose hardware and development tools that can be used in a variety of use cases across industries. Flespi MQTT broker extends the integration capabilities and gives solution development companies flexibility and accessibility to efficiently handle loads of telemetry data and incorporate it into the ongoing projects.