Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Connect Quarkus applications with Drogue IoT and LoRaWAN

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

    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

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    • How EvalHub manages two-layer Kubernetes control planes

    • Tekton joins the CNCF as an incubating project

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.