The top 6 programming languages for IoT projects

本文探讨了物联网(IoT)环境中不同设备层级所采用的主要编程语言,包括传感器层面的C语言,到更高级别设备上的Java、Python、JavaScript等,并介绍了每种语言的特点及应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

What we mean when we say 'IoT devices'

Skerrett divides the IoT architectural environment into three major sections: the sensors that create the data, the hubs or local gateways that organize it, and the geographically distant, centralized servers that collect the data.

“If you’re writing for a sensor on bare metal, you’re probably using C,” said Skerrett. The ability to work directly with the RAM makes C one of the first choices of hardware developers.

The rest of the machines in the chain, though, are as familiar as desktop computers, from the developer's perspective. Thus, developers are able to use the language that’s familiar to them.

The hubs may be a smartphone or a small console, but they are just general-purpose machines inside. They usually run a standard operating system and often feel no different from a big machine, at least when communicating via the command line.

Choosing a language for IoT

There’s no reason why they can’t choose the language in the same way they do for a desktop project. If a Raspberry Pi is running Linux, it's behavior is not that different from a desktop. 

By the time the debate on languages makes its way to the servers, there’s no difference there, either. They speak with the hubs and sensors—usually with some kind of microservice architecture—then the data is pushed into standard databases.

While the usual suspects of popular languages dominate the IoT space already, the Eclipse survey found at least 14 different languages that were mentioned by 5 percent or more of the developers.

“Our Internet of Things effort at Eclipse is polyglot,” said Skerrett. “It’s not one language.”

The Eclipse Project’s IoT open-source effort has been expanding, and there are now more than 20 different projects spanning millions of lines of code. Much is in Java, but there’s plenty in Python, JavaScript, C, and other important frameworks.

Here are some of the top choices that are being used to build the foundations of the next generation of things connected to the Internet.

Java

The top choice of the Eclipse survey and another survey by embedded-computing.com was Java, a result that’s not surprising for a language still known for being “write once, run anywhere.” The original project was aimed at set-top boxes, one of the first domains for non-desktop computing.

Java’s advantages are well known. Developers can create and debug code on their desktop and then move it to any chip with a Java Virtual Machine. That means the code can run not just on places where JVMs are common (servers and smartphones), but also on the smallest machines.

Java ME, or micro edition, has been available on small phone handsets and other embedded devices since the specification was approved in 2000. It saved space with a very limited collection of class libraries and other tools. Today, most of the focus is on Java SE Embedded, which is much closer in capability to the Standard Edition. Developers can use the latest features of the Java 8 platform and then move their code to a smaller, embedded device.

Most of the computing resource savings with Java SE Embedded comes from stripping out the classes needed to display information when the machines can be configured to run headlessly, without a monitor or keyboard. All of the communication goes through the network.

There are multiple open-source projects, such as Pi4J and BlueJ, that show how the embedded version of Java runs well, even on chips that seem limited.

C

The syntax is cluttered with punctuation, and there are a million different little mistakes you can make, but the language is still the first choice for many programmers who write for the lowest layer of software, the one closest to the hardware. The language hides nothing from you, and that means you can fiddle with every part of the code to squeeze out the best performance from an underpowered device. Every bit can be flipped. Every value on the stack is available. Just don’t make a mistake, because there are few safety nets.

Victor Berrios is the chief technical officer at the ZigBee Alliance, a group that supports the ZigBee standard, which links small devices. “From what we see in the market, C remains the language of choice for constrained devices,” he said. “These typically do not include a 'commercial'-level OS but rather a basic task-scheduler type of resource management also coded in C.”

More advanced or bigger devices with full operating systems still use plenty of C code, he added, but he said that other languages such as Java are starting to be used just as frequently. When a smartphone comes from Apple, much of the programming is still done in Objective C, but this will probably be gradually replaced by Swift (see below).

Python

It started as a scripting language to glue together real code, but it’s increasingly used as the main language for many developers. When small devices have enough memory and computational power, the developers are free to choose the language that makes their life easier and that is more and more often turning out to be Python.

Kinman Covey, a microcontroller developer, says that Python is both easy to learn and supported by a large, helpful community. The syntax is clean and simple, attracting a greater range of programmers. The language is often the first choice for social scientists and biologists, for instance. When they need a smart device in the lab, they’re happy to use a language they know, Python.

“Python is the language of choice for one of the most popular microcontrollers on the market, the Raspberry Pi,” said Covey. Much of the training literature is written in Python, and many schools use the platform to teach computer programming. If the project is relatively simple and there are no great computational demands, it’s possible to build effective tools from the same boards and libraries that are used in elementary schools.

There are also versions designed to be even smaller. The MicroPython board and software package is a small microcontroller optimized to run Python on a small board that’s only a few square inches.

JavaScript

While many still think of JavaScript as a language for popping up alert boxes on web pages, the language’s relatively newfound popularity on the server makes it a surprisingly popular choice for IoT applications. A full 41.8 percent of the developers in the Eclipse survey chose JavaScript, and 31.5 percent indicated that they were using Node.js in their projects.

Much of this work is focused on the servers and gateways or hubs that gather the information and then store it. The smaller smart hubs and sensors that run Linux can usually run Node.js.

But even if most of the Node.js code runs on larger machines, there are some efforts designed to bring it to smaller ones. Espruino and Tessel are two examples of microcontrollers that run JavaScript from the beginning. Tessel, for instance, is built around Node.js, making it easy for web developers to move into the IoT without learning a new language.

Swift

While Swift is still mainly used to build applications for Apple’s iOS and macOS devices, the preponderance of these machines means that it’s often part of the IoT stack. If you want your things to interact with an iPhone or an iPad, you’re probably going to want to build the app in Swift (or perhaps its predecessor, Objective C).

There are other good reasons to work in this space. Apple wants to make its iOS devices the center of the home network of sensors, so it’s been creating libraries and infrastructure that handle much of the work. These libraries are the foundation of its HomeKit platform, which provides support for integrating the data feeds from a network of compatible devices. This means you can concentrate on the details of your task and leave much of the integration overhead to HomeKit. 

PHP

This language may be the first choice of bloggers and website prototypers, but it is also surprisingly popular in the IoT. After the big languages and their cousins such as C#, PHP is the one language that is mentioned the most often by developers in the Eclipse survey; 11.2 percent say they are including PHP code in their stack.

While the code’s role on the server to juggle microservices is an obvious application, it is also finding some traction at the lowest level. A number of Raspberry Pi developers are talking about starting up a full LAMP stack with Apache, MySQL, and PHP running on top of Linux. They are effectively inverting the paradigm and turning the lowliest thing on the Internet into a full web server.

If a Raspberry Pi has enough spare cycles—and it often does—then putting a LAMP stack on the chip makes development simpler. All of the server-side code developed over the last 20 years can find a home in a small sensor. It may seem like a toy next to the full-strength, pointer juggling machismo of C, but if it gets the job done quickly and makes the boss happy, why not use it?

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值