Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Connect Quarkus applications with Drogue IoT and LoRaWAN

June 10, 2021
Jens Reimann
Related topics:
Edge computingJavaKubernetesQuarkus
Related products:
Red Hat OpenShift

Share:

    The goal of the Drogue IoT project is to make it easy to connect devices and cloud-based applications with each other. In this article, we'll show how to implement firmware based on Drogue Device that can communicate with Quarkus applications in the cloud using the low-power LoRaWAN protocol.

    Drogue IoT

    A lot of open source technology already exists in the realm of messaging and IoT (Internet of Things), so it makes sense to try to use as many existing tools as possible. However, technologies change over time, and not everything that exists now is fit for the world of tomorrow. C and C++ still have issues with memory safety, and cloud native, serverless, and pods are concepts that might need a different approach when designing cloud-side applications. So, Drogue IoT is here to help.

    Drogue Device is a firmware framework written in Rust with an actor-based programming model. Drogue Cloud is a thin layer of services that creates an IoT-friendly API for existing technologies like Knative and Apache Kafka and provides a cloud-friendly API using CloudEvents on the other side. The idea is not to provide separated components but to give you an overall solution that's ready to run: IoT as a service. The Drogue IoT architecture is shown in Figure 1.

    Overview diagram of the Drogue IoT architecture
    Figure 1: Overview diagram of the Drogue IoT architecture.

    LoRaWAN network coverage

    LoRaWAN is a low-power wireless network that enables you to run a device on batteries for months, sending telemetry data to the cloud every now and then. To accomplish that, you need LoRaWAN network coverage, and The Things Network (TTN) provides exactly this. You can extend the TTN network by running your own gateway, should your local area lack coverage. TTN provides a public service that allows you to exchange data between devices and applications.

    Drogue Device

    Exchanging data with Drogue Device is easy. The following snippet focuses on the actual code exchanging data:

    let mut tx = String::<heapless::consts::U32>::new();
    let led = match self.config.user_led.state().unwrap_or_default() {
        true => "on",
        false => "off",
    };
    write!(&mut tx, "ping:{},led:{}", self.counter, led).ok();
    let tx = tx.into_bytes();
    
    let mut rx = [0; 64];
    let result = cfg
        .lora
        .request(LoraCommand::SendRecv(&tx, &mut rx))
        .unwrap()
        .await;

    Notice the await keyword? Yes, that is indeed asynchronous Rust running on an embedded STM32 Cortex-M0 device. Thanks to the embassy framework and the drivers in Drogue Device, asynchronous programming becomes pretty simple. And thanks to Rust, your code is less likely to cause any undefined behavior, like corrupted memory.

    Quarkus

    On the cloud side, we want to have a simple "reconcile loop." The device reports its current state, and we derive the desired state from that. This might result in a command that we want to send back to the device. Again, focusing on the code that is important:

    @Incoming("event-stream")
    @Outgoing("device-commands")
    @Broadcast
    public DeviceCommand process(DeviceEvent event) {
    
        var parts = event.getPayload().split(",");
    
        // then we check if the payload is, what we expect...
        if (parts.length != 2 || !parts[0].startsWith("ping:") || !parts[1].startsWith("led:")) {
            // .. if not, return with no command
            return null;
        }
    
        // check if the configured response is about the LED, and if it matches ...
        if (!this.response.startsWith("led:") || parts[1].equals(this.response)) {
            // ... it is not, or it matches, so we return with no command
            return null;
        }
    
        var command = new DeviceCommand();
        command.setDeviceId(event.getDeviceId());
        command.setPayload(this.response.getBytes(StandardCharsets.UTF_8));
    
        return command;
    
    }

    Pretty simple, isn't it? Of course, you could make it more complicated, but we leave that up to you.

    The Quarkus application consumes CloudEvents, which provide a standardized representation of events for different messaging technologies like Kafka, HTTP, and MQTT.

    Drogue Cloud

    So far, this is pretty straightforward, focusing on the actual use case. However, we are missing a big chunk in the middle: How do we connect Quarkus with the actual device? Sure, we could recreate all of that ourselves—implementing the TTN API, registering devices, processing events. Alternatively, we could simply use Drogue Cloud and let it do the plumbing for us.

    Creating a new application and device is easy using the drg command-line tool:

    $ drg create application my-app
    $ drg create device --app my-app my-device

    The device registry in Drogue Cloud not only stores device information but can also reconcile with other services. Adding the following information will make it sync with TTN:

    $ drg create application my-app --spec '{
        "ttn": {
                "api": {
                    "apiKey": "...",
                    "owner": "my-ttn-username",
                "region": "eu1"
                }
        }
    }'
    $ drg create --app my-app device my-device --spec '{
        "ttn": {
            "app_eui": "0123456789ABCDEF",
            "dev_eui": "ABCDEF0123456789",
                "app_key": "0123456789ABCDEF...",
            "frequency_plan_id": "...",
            "lorawan_phy_version": "PHY_V1_0",
                "lorawan_version": "MAC_V1_0"
        }
    }'

    This creates a new TTN application, registers the device, sets up a webhook, creates the gateway configuration in Drogue Cloud, and ensures that credentials are present and synchronized.

    Learn more in the LoRaWAN end-to-end workshop

    Did that seem a bit fast? Yes, indeed! This is a lot of information for a single article, so we wanted to focus on the most important parts. We put together everything you need to know in a workshop so you can read through it in more detail and get more background, too. By the end of this workshop, you should end up with a web front-end to control your device, as shown in Figure 2.

    Screenshot of the workshop's Quarkus web frontend
    Figure 2: The Quarkus web front-end.

    Most importantly, you'll have a solid foundation for creating your own applications on top of Drogue IoT.

    Last updated: June 28, 2023

    Related Posts

    • LoRaWAN setup at the EclipseCon IoT playground

    • Behind the Internet of Things Middleware Demo at Red Hat Summit

    • IoT edge development and deployment with containers through OpenShift: Part 1

    • IoT edge development and deployment with containers through OpenShift: Part 2

    Recent Posts

    • Cloud bursting with confidential containers on OpenShift

    • Reach native speed with MacOS llama.cpp container inference

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue