This document provides practical examples of workflows for Internet of Things (IoT) applications using Lemline. They manage the sensors of the tutorial shop's warehouse: device provisioning, telemetry processing, firmware updates, predictive maintenance and energy optimization.
Run the Examples
Complete the SQLite setup and run the commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. Start the tutorial shop from the root of the Lemline source checkout. Its /devices routes hold three warehouse sensors; the shop page lists them under Devices.
docker compose -f examples/tutorial-services/compose.yaml up -d
Devices answer through events, which the tutorial publisher sends for you. The telemetry workflow is started by events, so it must be registered before the worker starts. Stop the setup worker with Ctrl+C, save the publisher below as tutorial-publisher.yaml and the telemetry workflow as device-telemetry.yaml, register both and start the worker again:
bin/lemline definition post -f tutorial-publisher.yaml
bin/lemline definition post -f device-telemetry.yaml
bin/lemline listen --debug
Run the other commands from a second terminal in the setup directory. Publish each device event only after the instance that waits for it has started waiting: an event only resumes the instances already listening.
Device Provisioning Workflow
This example provisions a new warehouse sensor: it registers it if the shop does not know it, obtains credentials, stores its configuration, asks the device to activate and waits for its confirmation.
The shop answers HTTP 404 for the unknown sensor-4, so the catch registers it. The instance then waits for the activation. Send it as the device would:
Each reading starts a device-telemetry instance about 10 seconds later; only the second emits com.example.device.temperature.high.
Firmware Update Workflow
This workflow requests a firmware update for each eligible device of a zone, those whose firmware is older than the target version. For each one it waits for a status event matching the campaign and the device, then records the installed version. If no status arrives within 60 seconds, it reads the device's current state from the shop instead. A real campaign would wait hours.
After 60 to 70 seconds the listener times out, the workflow reads sensor-1 from the shop, and its firmware stays 1.0.0.
Predictive Maintenance Workflow
This workflow runs every 24 hours. For each device it asks the shop for a failure prediction, then opens a maintenance ticket above 0.7, warns the maintenance team above 0.4, and does nothing otherwise. schedule.every runs it once when it is started, then at each interval; schedule.cron would wait for the next matching time instead.
bin/lemline definition post -f predictive-maintenance-workflow.yaml
bin/lemline instance start examples predictive-maintenance
The predictions are 0.13 for sensor-1, 0.78 for sensor-2 and 0.42 for sensor-3: the run opens a Maintenance ticket document for sensor-2 and leaves a Failure probability 0.42 message for maintenance about sensor-3. The schedule repeats every 24 hours while a worker runs.
Energy Optimization Workflow
This workflow runs every 15 minutes. It asks the shop for a plan based on the zone's sensor readings, requests the HVAC and lighting changes with two events, and waits up to five minutes for both devices to confirm the same request. Without both confirmations it records the optimization with none.
The instance completes and the shop's audit list shows Optimization applied: hvac 19, lighting 70, 2 confirmations for the dock. The schedule repeats every 15 minutes while a worker runs; stop the worker when you are done. Stop the shop too:
docker compose -f examples/tutorial-services/compose.yaml down
Best Practices for IoT Workflows
When implementing IoT workflows with Lemline, consider these best practices:
Device Identity Management: Implement secure device identity and credential management
Batch Processing: Process telemetry data in batches for efficiency
Error Handling: Use robust error handling and retry mechanisms for device communications
Correlation: Properly correlate events from the same device across different workflows
Timeouts: Set appropriate timeouts for device communication, which may be unstable (Lemline only enforces timeouts on listen tasks; HTTP calls use fixed limits of 15 s to connect and 30 s per request)
Stateful Workflows: Use workflow context for maintaining state about devices
Digital Twins: Update digital twin representations with the latest device state
Progressive Deployment: Implement batched or phased deployments for firmware updates
Monitoring: Include appropriate logging and monitoring for device interactions
Data Validation: Always validate incoming telemetry data before processing
Conclusion
These examples demonstrate how to implement common IoT patterns as workflows using Lemline. The workflows cover the entire IoT lifecycle, from device provisioning to telemetry processing, firmware updates, predictive maintenance, and energy optimization.
By leveraging Lemline's workflow capabilities, you can build robust, scalable IoT solutions that handle complex device management and data processing requirements while maintaining reliability and performance.
For more examples of specific integrations, see the Integration Examples document.
Run the warehouse exercise to deliver a real event to the manager’s inbox.