IoTMigrator: LLM-driven Embedded IoT Code Migration across Different OSes for Cloud-device Integration

Yq, Kaijie Gong, Yi Gao, Hao Wang, Wei DongEMNLP 2025

TL;DR

Migrating embedded IoT device code to new operating systems (OSes) is challenging due to the unique constraints of embedded programming and the specialized Thing Specification Language (TSL) used for cloud connectivity. This paper introduces IoTMigrator, a novel multi-agent system that leverages LLMs to automate this migration process, significantly improving code compilation success and functional completeness compared to existing methods.

What Problem Does This Paper Address?

The proliferation of IoT devices and the rapid evolution of embedded operating systems (like RIOT-OS and Zephyr) necessitate frequent code migration. Manufacturers often need to adapt their existing device code, which is typically written for one OS and uses a specific cloud communication standard (TSL), to new OS environments. This migration is far more complex than standard software migration because embedded systems have strict resource limitations, real-time requirements, and often interact directly with hardware. Furthermore, the TSL paradigm, while crucial for cloud integration, introduces its own set of complexities that traditional code migration or generation techniques struggle to handle. Existing LLM-based approaches, while powerful for general code tasks, often fail in this domain by importing incorrect libraries or generating incomplete code, as illustrated by the example of an LLM mistakenly using Arduino-specific libraries for RIOT-OS.

Methods

IoTMigrator employs a three-agent pipeline designed to tackle the intricacies of embedded TSL code migration:

  1. Outline Generator: This agent analyzes the user's requirements and existing reference code (often Arduino-based) to extract key information (metadata like parameters and functions) and decompose the migration task into smaller sub-tasks. It generates an "outline" that guides the subsequent agents.
  2. TSL Enhancer: This is the core innovation. It focuses on the TSL paradigm's unique characteristics, specifically separating communication and peripheral control code generation. It leverages a rating mechanism and tool chains (including multi-OS search, compilation, and template import) to independently generate and test these components, ensuring functional completeness and correctness. This modular approach reduces the LLM's tendency to oversimplify code to achieve compilation.
  3. Code Generator: This agent takes the outputs from the TSL Enhancer and synthesizes them into the final, executable target code. It utilizes a tool chain that includes search, compilation, and a novel library check mechanism to resolve missing library issues.

The system also incorporates a rating mechanism to evaluate generated code and provide feedback for iterative improvement.

Datasets

The authors created a new benchmark corpus consisting of six typical IoT applications. These applications were implemented in both RIOT-OS and Zephyr, with Arduino code serving as the reference. This corpus covers various IoT functionalities, including environment sensing, device actuation, user interaction, and security alerting, and is designed to specifically test TSL-based code migration.

Key Insights and Ideas

  • TSL's unique challenges: The paper highlights that TSL's structured approach to device properties, events, and services requires specialized handling, which general-purpose LLM code migration tools lack.
  • Modular generation is key: Separating communication and peripheral control code generation, as done by the TSL Enhancer, significantly improves the quality and completeness of the migrated code.
  • LLMs can be misled by reference code: The authors demonstrate how LLMs can incorrectly infer library dependencies from reference code, leading to compilation failures and functional errors in embedded contexts.
  • Dedicated tool chains are crucial: IoTMigrator's success relies on a tailored tool chain that includes multi-OS compilation and a specific library checking mechanism, adapted for the embedded OS environment.
  • Human-like evaluation: The strong correlation between the LLM's scoring and expert human evaluations suggests the rating mechanism effectively captures code quality and completeness.

Key Results

IoTMigrator demonstrated significant improvements over baselines (AutoIoT, CodeAgent, RagDebug) across both RIOT and Zephyr OSes:

  • Compilation Pass Rate: Average improvements of at least 50.5% in RIOT and 83.4% in Zephyr.
  • Task Completeness Score: Average improvements of at least 13.0% in RIOT and 18.4% in Zephyr.
  • The system also showed strong generalization capabilities, performing well with different LLMs (e.g., DeepSeek-V3).
  • Analysis of API and library recall rates indicated IoTMigrator's superior ability to correctly utilize required components.

Limitations and Future Work

The authors acknowledge two main limitations:

  • Custom Driver Issues: IoTMigrator currently cannot address custom driver issues, which they plan to refine in future work.
  • Limited Scope of Experiments: The current experiments are limited to specific OSes and TSL tasks. Future work will involve testing on new OSes and expanding the range of TSL tasks.

Summary updated

BibTeX
@inproceedings{yq2025iotmigrator,
  author = {Yq and Kaijie Gong and Yi Gao and Hao Wang and Wei Dong},
  title = {{IoTMigrator: LLM-driven Embedded IoT Code Migration across Different OSes for Cloud-device Integration}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure