In recent years, the swift expansion of Internet of Things (IoT) applications has been notable. However, developing a
comprehensive IoT application is highly challenging for nonexpert developers due to the highly diverse characteristics of embedded operating systems. LLM-based methods provide a paradigm for code generation through natural language, which can greatly simplify and accelerate the development of IoT applications. While promising, existing works have failed to account for the specific characteristics of embedded operating system, resulting in the lower quality of generated IoT code. In this paper, we present IoTPilot, an LLM-driven embedded IoT programming tool. We have observed that the conflicts between LLM internal APIs/headers and external OS-specific APIs/headers are key factors leading to the low quality of generated embedded IoT applications. Thus, we introduce two effective self-thinking chains to integrate internal LLM knowledge with external documentation, addressing conflicts in APIs and headers. We provide embedded IoT benchmarks (IoTEval), which include 45 embedded IoT applications built on RIOT, Zephyr, and Contiki OS. Results show that IoTPilot can improve the performance of IoT code generation on all the three embedded OSes compared with existing state-of-the-art (SOTA) methods.