Getting started with edge development on Linux using open source

Leverage Quarkus to scale IoT application development and deployment environments.
62 readers like this.
Looking at a map

opensource.com

There are many reasons why Linux is such a popular platform for processing Internet of Things (IoT) edge applications. A major one is transparency. Linux security capabilities are built on open source projects, giving users a transparent view of security risks and threats and enables them to apply fixes quickly with security module patches or kernel-level updates. Another Linux advantage is that developers can choose from various programming languages to develop, test, and run device communications over various networking protocols—other than HTTP(s)—when developing IoT edge applications. It also enables developers to address server programming for controlling data flow from IoT devices to front-end graphical user interface (GUI) applications.

This article explains how to get started with IoT edge development using Quarkus, a cloud-native Java framework that enables you to integrate a lightweight message broker for processing data streams from IoT devices in a reactive way.

For this article, I'm using CentOS Stream, which I feel provides a reliable open source platform to handle the business applications I work on, from traditional enterprise Java to cloud, IoT edge, artificial intelligence (AI), and machine learning (ML) environments. It's a midstream platform operating between Fedora and Red Hat Enterprise Linux (RHEL).

[Read next: Deploy Quarkus everywhere with RHEL]

 

You don't have to use CentOS to use Quarkus, of course. However, if you want to follow along with this article precisely, you can install CentOS Stream so there will be no difference between what you read here and what you see onscreen.

You can learn more about Quarkus by reading my article Writing Java with Quarkus in VS Code.

Step 1: Send IoT data to the lightweight message broker

To quickly spin up a lightweight message broker, you can use Eclipse Mosquitto. It's an open source message broker that implements the MQTT protocol. MQTT processes messages across IoT devices, such as low-power sensors, mobile phones, embedded computers, and microcontrollers. Mosquitto can be installed on various devices and operating system platforms, but you can also spin up the broker container image after installing a container engine (e.g., Docker) and a command-line interface (CLI) tool.

I use the Podman tool for running Linux containers. Compared to other container engines, this saves resources (CPU and memory especially) when you install and run an extra container engine in your environment. If you haven't already, install Podman before continuing. Then run the Mosquitto message broker with this command:

$ podman run --name mosquitto \
--rm -p "9001:9001" -p "1883:1883" \
eclipse-mosquitto:1.6.2

You see this output:

1619384779: mosquitto version 1.6.2 starting
1619384779: Config loaded from /mosquitto/config/mosquitto.conf.
1619384779: Opening ipv4 listen to socket on port 1883.
1619384779: Opening ipv6 listen socket on port 1883.

Step 2: Process reactive data streams with Quarkus

For this example, imagine you have IoT devices connected to a warehouse that continually send temperature and heat data to back-end servers to monitor the building's condition and save power resources.

Your imaginary setup uses one ESP8266-01 WiFi module that streams temperature and heat data in the JSON data format. The stream's IoT edge data is transmitted to the Mosiquitto message broker server running on your machine.

Define the ESP8266-01 emulator in a Java application on Quarkus:

Device esp8266 = new Device("ESP8266-01");

@Outgoing("device-temp")
public Flowable<String> generate() {
  return Flowable.interval(2, TimeUnit.SECONDS)
    .onBackpressureDrop()
    .map(t -> {
      String data = esp8266.toString();
      return data;
  });
}

Quarkus also enables you to process data streams and event sources with the SmallRye Reactive Messaging extension, which interacts with various messaging technologies such as Apache Kafka, AMQP, and especially MQTT, the standard for IoT messaging. This code snippet shows how to specify incoming data streams with an @Incoming() annotation:

@Incoming("devices")
@Outgoing("my-data-stream")
@Broadcast
public String process(byte[] data) {
  String d = new String(data);
  return d;
}

You can find this solution in my GitHub repository.

Step 3: Monitor the real-time data channel

Quarkus uses reactive messaging and channels to receive, process, and showcase messages with a browser-based front-end application. You can run the Quarkus application in development mode for live coding or continue adding code in the inner-loop development workflow.

Issue the following Maven command to build and start the application:

./mvnw compile quarkus:dev

Once your Quarkus application starts, you should see incoming IoT data from the ESP8266-01 device.

 

You can use the dashboard to monitor how the IoT edge data (e.g., temperature, heat) is processing. Open a new web browser and navigate to http://localhost:8080. You should start seeing some statistics.

 

Conclusion

With Quarkus, enterprises can scale application development and deployment environments with minimal cost and without high maintenance or licensing fees. From a DevOps perspective, enterprise developers can still use familiar open source technologies (such as Java) to implement IoT edge applications, while operators can control and monitor production using a Linux-based system (like CentOS Stream) with data gathered from big data, IoT, and artificial intelligence (AI) technologies. 

What to read next

What is edge computing?

Edge computing is poised to boost the next generation of IoT technology into the mainstream. Here's how it works with the cloud to benefit business operations in all…

danieloh
Technical Marketing, Developer Advocate, CNCF Ambassador, Public Speaker, Published Author, Quarkus, Red Hat Runtimes

Comments are closed.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.