Developing IoT Embedded Devices with .NET Core and C#

(Give DotNet a star to enhance .Net skills)

Source: Chizhe Gongliang

cnblogs.com/whuanle/p/10589496.html

1. Support for IoT Platforms

Let’s take a look at some excellent cloud computing IoT platforms in China (excluding developer platforms for specific products like QQ Connect and Xiaomi IoT, only listing some cloud computing vendors’ IoT platforms)

Aliyun IoT:https://iot.aliyun.com/

Huawei IoT:https://developer.huawei.com/ict/cn/site-iot-next

Tencent Cloud IoT Communication:https://cloud.tencent.com/product/iothub

Baidu Cloud Tiangong:https://cloud.baidu.com/solution/iot/index.html

China Mobile OneNET:https://open.iot.10086.cn

When it comes to IoT, there are various aspects to consider for development, including device authentication, device access, gateways, device management, subscriptions, data management and analysis, application development, etc. Here, I will focus solely on the development of embedded devices.

Among these platforms, only Aliyun provides a device-side SDK for C#, which is not open-source and cannot be cross-platform (it can only be used under .NET Framework 4.7, don’t ask me how I know), and the device access method is HTTP/2. The platform most friendly to C#/.NET should be Aliyun, while Tencent Cloud’s IoT is relatively less impressive.

The provided device-side access and application development are primarily in C and Python (C is the king of embedded development), with communication protocols such as HTTPS, MQTT/MQTTS, etc.

Developing IoT Embedded Devices with .NET Core and C#

Aliyun IoT Device-side SDK Documentation

https://help.aliyun.com/document_detail/101488.html?spm=a2c4g.11186623.2.26.554a5b3eaMSYnh#concept-xlx-dzz-ggb

Aliyun IoT Cloud-side SDK Documentationhttps://help.aliyun.com/document_detail/63638.html?spm=a2c4g.11186623.6.678.1ede4c07i0qvHR

Developing IoT Embedded Devices with .NET Core and C#

As for abroad, I will only mention Amazon Cloud and Azure Cloud.

https://www.amazonaws.cn/iot/

https://www.azure.cn/zh-cn/

They are divided into China and international regions, with Microsoft’s Azure China region operated by 21Vianet (not very comfortable).

Developing IoT Embedded Devices with .NET Core and C#

Developing IoT Embedded Devices with .NET Core and C#

As shown in the pictures, Amazon does not support C#, and embedded devices only support C language, while other aspects do not support C#/.NET.

Only Azure supports .NET extensively and unreservedly.

2. Embedded Devices

The device side of IoT devices is not limited to devices such as Raspberry Pi, smartwatches, drones, and Bluetooth, and can include smartphones, smartwatches, computers, etc., which can all serve as IoT device endpoints.

Here, I will only discuss ARM32/64 embedded development boards, taking Raspberry Pi and domestic Orange Pi as examples.

Operating systems include Win 10 IoT Core, Ubuntu, Debian, etc.

If you want to buy, get Raspberry Pi, don’t buy other brands, or you’ll regret it.

1. System Support

Raspberry Pi supports a wide variety of systems, and the system kernel is relatively new, allowing for easy installation of .NET Core SDK and Runtime.

As for the domestic Orange Pi, it’s a real disappointment, with an older system kernel, lower GCC version, and various incompatible drivers. There are few systems that can be used normally, and it generates a lot of heat.

Not long ago, I bought an Orange Pi 3 and installed .NET Core SDK 2.2, but I had to change the apt source first, then update the apt list, and install a new version of gcc (the .NET Core requires gcc greater than 5.2, Debian system must be greater than or equal to 9).

Developing IoT Embedded Devices with .NET Core and C#

2. Resource Documentation

Raspberry Pi is very popular, and many software support Raspberry Pi. Almost all technologies related to embedded systems will mention Raspberry Pi, so you don’t have to worry about a lack of learning materials or corresponding sensors.

I won’t elaborate further.

Only development boards with larger memory and CPU can run programs developed in .NET; C language is still king. A single-chip microcontroller has only a few KB of memory, while the ARM version of .NET Core requires at least 300MB of memory.

3. Current Methods of .NET Development for Embedded Applications

1. Using Dynamic Link Libraries Generated by C/C++

Cross-platform development — C# using dynamic link libraries generated by C/C++https://www.cnblogs.com/whuanle/p/10582654.html

By using interfaces encapsulated in C/C++, you can control GPIO (the pins on the board), etc. This method can only be used under Linux. When developing C# programs, there is no need to directly deal with the underlying implementation; you can indirectly manipulate it through reserved C/C++ interfaces. C/C++ can handle various communication protocols, logic processing, circuit control, etc., encapsulating them into .SO libraries for C# to use. This way, developers can focus on business development without worrying about underlying implementations.

I have an article on .NET Core cross-platform serial communication that uses the SerialPortStream library, which can be used on both Windows and Linux. If you want to use it on Linux, you must first compile the official C project to generate a dynamic link library and include it in your project before running it. The underlying implementation uses C language, making application development independent of communication methods.

2. Using Windows 10 IoT Core

This means developing on the Windows 10 IoT Core system.

Benefits:Let’s take a look at some images

Developing IoT Embedded Devices with .NET Core and C#

Developing IoT Embedded Devices with .NET Core and C#

Developing IoT Embedded Devices with .NET Core and C#

Developing IoT Embedded Devices with .NET Core and C#

A complete C# development environment allows for various aspects of development, with official libraries provided to operate various device interfaces and pins. You do not need to master a lot of hardware knowledge to quickly get started on projects, directly using C#/.NET to interact with various sensors, supported by the best IDE in the universe, Visual Studio, excellent cloud computing platform Azure, great ecosystem support, and the convenience of using traditional WPF and other software interfaces.

In the past, using development boards required mastering embedded device development, Wi-Fi, Bluetooth, GPIO, network cards, ARM32/64, circuits, and other protocols and hardware knowledge. Now, using C# can accomplish everything.

3. Mono

While learning to use development boards, I found that some libraries can be used on Mono, allowing for C# project development using Monodevelop to control GPIO. I am not familiar with Mono and have not implemented it in practice.

As for .NET Core for embedded development, I haven’t discovered any advantages of using .NET Core for embedded software development at my current level.

Firstly, .NET Core (currently the latest ARM 2.2.105) cannot directly use sensors. This may be due to my lack of proficiency, as I have not found any examples of using .NET Core on Linux to control sensors or use GPIO.

Of course, there are examples of developing .NET Core projects using GPIO on Windows 10 IoT Core, but that is not on Linux.

Secondly, few cloud computing vendors support .NET. Here, support means supporting .NET development access to IoT platforms on devices. Devices like Raspberry Pi, which have complete functionality and hardware configuration, can connect directly to servers. Other devices with very small memory and no network card can only be developed using C language and can only connect to IoT platforms through gateways. Even if the underlying device access is well established, to connect to the IoT platform, APIs, SDKs, and documentation are necessary. There is indeed very little documentation available for .NET.

Personally, I feel that .NET Core has developed well in cloud computing, Docker, web development, etc., but not so much in embedded areas. Of course, this is just my personal feeling.

If using Windows IoT Core, it doesn’t matter whether it’s .NET Core or .NET Framework.

Looking forward to the official release of .NET Core 3.0.

Developing IoT Embedded Devices with .NET Core and C#

Developing IoT Embedded Devices with .NET Core and C#

The above content is just my personal understanding. I am currently a junior student, lacking experience, and if there are any errors or incorrect viewpoints, I sincerely hope that the experts will provide guidance.

Recommended Reading

(Click on the title to jump to read)

New Changes in .NET Core 3.0

ASP.NET Core File System

C# Cancellation of Asynchronous Operations You Might Not Know

Did you gain anything from reading this article? Please share it with more people.

Follow “DotNet” and give it a star to enhance .Net skills.

Developing IoT Embedded Devices with .NET Core and C#

If you like it, just hit “Like”~

Leave a Comment