Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

  1. Blog
  2. Article

Galem KAYO
on 16 March 2020

Turning your Raspberry Pi 4 into an edge gateway – Part 2


In the first part of this tutorial, we installed and configured EdgeX foundry on a Raspberry Pi 4, turning it into an edge gateway. In this tutorial, the gateway will be connected to dummy IoT devices. These dummy devices will be virtually simulated by software. They will send messages transmitting random measurements to an MQTT broker hosted in the cloud. These messages will be forwarded to MQTT clients that subscribes to receive them.

Connecting the Southbound

The IoT data flow from devices to the edge gateway is referred to as the Southbound. In EdgeX, communication between IoT devices and gateways is assured by device services. A device service is a microservice that implements an interface to an IoT communication protocol (Modbus, OPC-UA, REST, BLT, Zigbee, MQTT, BACNet, SNMP etc…).

The Virtual Device Service is convenient for configuring and testing  your Raspberry Pi 4 gateway. It allows you to carry out tests without any real IoT device. This way, microservices running on the gateway can be configured and troubleshooted without any IoT device connected. The Virtual Device Service also simulates dummy IoT devices that generate and transmit random numbers of different types: integer, unsigned integer, boolean and float.

The Virtual Device Service can be enabled very easily with the following command:

sudo snap set edgexfoundry device-virtual=on

Upon enablement, the service and the virtual devices it simulates become visible in the edgeX web UI.

Creating an MQTT server in the cloud

Edge gateways are the juncture between devices and servers. We will now configure the receiving end in the cloud: a server hosting a custom MQTT broker. The MQTT broker will receive the messages sent from the virtual devices. The messages will then be dispatched to subscribing client devices.

The MQTT broker is installed on a Ubuntu 18.04 (bionic) server instance running AWS cloud. MQTT is quite easily installed on the Ubuntu cloud instance in a snap, as follows:

sudo snap install mosquitto

The status of the broker can then be inquired:

sudo systemctl status snap.mosquitto.mosquitto.service

Connecting the Northbound

With the MQTT server hosted in the cloud, a Northbound connection needs to be established between the Raspberry Pi 4 gateway and the server. An EdgeX Export Service is a microservice that moves data collected by device services to a server in the cloud. An Export Service can be created as follows:

sudo snap set edgexfoundry export-client=on
sudo snap set edgexfoundry export-distro=on

Upon activation, data transfer to the MQTT server can be configured. Parameters like the server IP address, port, communication protocol, data format, topic and encryption are to be specified as described in the screenshot below.

Once saved, the Export Service will connect to the MQTT broker and create a topic. The Export Service will publish data collected from virtual devices through this topic.

Consuming the virtual IoT data flow

At this point, you have a Raspberry Pi 4 gateway listening to virtual IoT devices, and forwarding the data collected from devices to an MQTT server hosted on a public cloud.

Now, any MQTT client running on any device can consume the IoT data flow originating from virtual devices. Clients only need to subscribe to the associated topic via our MQTT broker.

To read this data flow, we will install an MQTT client on a Ubuntu desktop, and subscribe to the topic created above via the Export Service. It should be noted that this data flow can be accessed via any MQTT client software installed on any desktop device.

sudo snap install mosquitto
mosquitto_sub -h <your_ip_adress_here> -t <topic_name_here>

The virtual IoT data flow can be read in the terminal. The stream corresponds to the data created by the Virtual Devices, in the format specified by our Export Service.

Resources

Next steps

In the third part of this tutorial, the gateway will be connected to a physical IoT device. We will also test the device management capabilities of EdgeX Foundry.

Related posts


Gabriel Aguiar Noury
21 November 2024

EdgeIQ and Ubuntu Core; bringing security and scalability to device management 

Internet of Things Article

Today, EdgeIQ and Canonical announced the release of the EdgeIQ Coda snap and official support of Ubuntu Core on the EdgeIQ Symphony platform. EdgeIQ Symphony helps you simplify and scale workflows for device fleet operations, data consumption and delivery, and application orchestration. Distributing EdgeIQ Coda as a snap brings the power ...


Ishani Ghoshal
21 November 2024

Ubuntu 20.04 LTS end of life: standard support is coming to an end. Here’s how to prepare. 

Ubuntu Article

In 2025, Ubuntu 20.04 LTS (Focal Fossa) will reach the end of its standard five-year support window. It’s time to start thinking about your options for upgrading. What is an Ubuntu long-term support (LTS) release?  Ubuntu long-term support releases (LTS) are released every 2 years by Canonical. Canonical provides patching and maintenance ...


Felipe Vanni
20 November 2024

Join Canonical in London at Dell Technologies Forum

AI Storage

Canonical is excited to be partnering with Dell Technologies at the upcoming Dell Technologies Forum – London, taking place on 26th November. This prestigious event brings together industry leaders and technology enthusiasts to explore the latest advancements and solutions shaping the digital landscape. Register to Dell Technologies Forum ...