Building an IoT system from scratch

background

Time: One day a year ago

Coordinate: Shenzhen

On a normal weekend that can't be normal, a few small partners gathered together to imagine the future of the Internet of Things. Among the small partners are hardware developers, embedded developers, software developers; full-stack engineers of Internet companies, industrial control system maintainers of nuclear power plants, and wifi protocol developers of router manufacturers. We have found that there is no open source and commercially available IoT platform or system in the world. Here is commercial, not to build a few demos to connect the hardware to the Internet, the app is so easy!

The following points must be considered:

Must have complete hardware, embedded, cloud-integrated protocols and architecture design

Achieve true hardware intelligence, ability to learn based on data and work autonomously

Must have high performance, stability and scalability

Must be able to adapt to thousands of different hardware devices, from PCs to mobile phones, from microcontrollers with extremely limited computing resources to controllers with extremely limited network bandwidth

Must be able to adapt to different network scenarios, including cable, wifi, 3g/4g, gprs, etc.

Must have very reliable security

Need to minimize R&D and production costs

When the media and technology workers are holding the Internet of Things as a future perspective and looking forward to the situation, we decided to do something, not as a spectator! This ordinary weekend can not be normal, maybe not very ordinary for us.

We decided to launch the design and development of a full suite of commercially available IoT systems and, in the near future, all open source.

Design-iot

So everyone used their spare time to start the protocol design and system design, and slowly started the project. A few months later, the development of the first commercial version was successfully completed. During this period, several small partners resigned from work and conducted full-time research and development. We have come to the present with no financing and no resources. The bitterness is not much to say. In this article, we will record the path we have taken in system design and R&D, so that you are also an Internet of Things enthusiast.

Overall design

An IoT system involves hardware, software, cloud, and app. It must be designed from the top. The system that relies on a single link does not have good applicability and scalability. In order to avoid this situation, we can adapt the system to the widest range of IoT scenarios (even industrial scenarios), and each architectural design discussion is attended by all team members. The general system architecture is as follows:

Overall design

protocol

In an IoT system, the protocol is the key link between the upper and lower layers. In the IoT system, we divide the protocol into two major layers: the communication layer and the business layer.

Protocol

The communication layer is basically the network infrastructure of the traditional Internet, responsible for the transmission of data in the nodes of the Internet of Things system.

The business layer is divided into two layers. The bottom layer is the specification of the data exchange format under the IoT scenario, and the upper layer is the service data specification that the IoT scenario needs to transmit specifically.

The communication layer Internet infrastructure is currently very mature and versatile, but the business layer protocols are still a wide variety. One thing that can be determined is that the protocol that ultimately dominates IoT applications must be as open and free as TCP/IP in the Internet age. Currently, there are XMPP, MQTT, COAP, etc. that meet this feature and use more. For specific comparisons, please refer to my previous article "Introduction to Internet of Things Communication Protocol".

The text is summarized as follows:

Protocols such as HTTP, websocket, and XMPP, which are used in the Internet, are designed according to Internet application scenarios. Although many vendors apply them to the Internet of Things system, they are bound to be unacceptable. The common problem of these protocols is fundamental. The diversity of IoT devices cannot be applied, and the demand for low-power and low-cost of many IoT devices cannot be applied, and it is difficult to use them in IoT devices with extremely low resources.

The COAP protocol is designed for resource-constrained embedded devices, but since many IoT devices are hidden inside the LAN, COAP devices cannot be addressed by external devices as servers. Before ipv6 is popular, coap can only be applied to LANs (such as wifi). ) Communication, which also greatly limits its scope of application.

MQTT considers the difference in computing performance of different devices in the protocol design, so all protocols are coded in binary format, and the codec format is very easy to develop and implement. The smallest packet is only 2 bytes, which is also very adaptable for low-power and low-speed networks. There is a very complete QOS mechanism, which can select up to one, at least once, and just one message delivery mode according to the business scenario. It runs on the TCP protocol and supports the TLS (TCP+SSL) protocol. Since all data communication passes through the cloud, security is well protected.

We finally chose to use MQTT as the main protocol for the business transport layer. However, the design of the MQTT protocol itself is aimed at open devices. For the IoT system that can be used commercially, it is necessary to ensure the security of the device and the perfect authorization mechanism. So we made some customizations and restrictions when implementing the MQTT protocol.

In the upper layer of the business layer (the business layer), the current IoT system is designed to each other for their own business scenarios. Is there a specification for unifying business data based on IoT scenarios? We think it is feasible and necessary. If the communication protocol is like a sound, there is a communication protocol, and no one can communicate with each other. Only a unified language can communicate smoothly. So we abstract the business scenarios of sensors and actuators in the IoT node and design a business layer protocol that contains the semantics of the IoT business data. At present, the business layer agreement has been open source, and it is hoped to bring certain reference value to the fans and practitioners.

Cloud platform

Internet users in the Internet era are mainly PCs and mobile phones. It is conceivable that in the Internet of Things era, Internet terminals will be diversified and quantified. It is conservatively estimated that each person has dozens of networked devices, and the data size is bound to increase geometrically. Therefore, the Internet of Things cloud platform is destined to be a large-scale mass distributed system.

At present, many fans or vendors can realize the networking of devices by building simple web systems (such as web interfaces implemented by php, nodejs, and python), but it is conceivable that in real commercial scenarios, stability, performance, and scalability are inevitable. Suffering from the impact, unable to cope.

In the process of technology selection and architecture design, we also consider the above factors to design and implement:

The go language is used as the main development language. The go language has a simple syntax and is easy to develop high-concurrency programs. It has a unique advantage in the development of high-performance cloud computing systems.

Adopt microservice distributed architecture. The microservice architecture can build a more stable and scalable distributed system and is the most popular architecture in distributed systems.

Use docker to reduce operating costs. Docker can easily upgrade the system and error rollback, ensuring the stability of the system when it is released.

The external interface is designed in a RESTful style. The RESTful interface is easy to upgrade and compatible, and has very easy to understand semantics that lowers the developer's learning threshold.

Multiple copy deployment. Any service module we guarantee at least two running instances at the same time, and automatically load and schedule according to the service discovery mechanism to increase system availability.

The general cloud architecture is as follows

Arch.001

At present, our system has been released to version 0.8.0, and will be optimized for the convenience of installation and operation, and is planned to be released in the 1.0 version.

Embedded

In addition to the traditional part, the embedded software of IoT hardware must be added to the networking logic and the management of sensors and controllers. In order to improve development efficiency and facilitate reuse, we designed and developed a lightweight IoT embedded development framework and abstracted the IoT business for porting to different hardware platforms. What we want to do is that an IoT embedded application can run on different hardware platforms without changing any business layer code.

Iot

At present, many large enterprises (Huawei, Hewlett-Packard, Google, etc.) have launched the Internet of Things operating system. In the future, the Internet of Things will have a coexistence of multiple operating systems. The minimum system resources and specific application scenarios that different operating systems can run are different, but we believe that the upper-layer business of the Internet of Things is universal, which is why we design the IoT embedded development framework.

Safety

In recent days, IoT devices from various manufacturers have heard hacked news. From TCL to Tesla, hackers have successfully achieved cracking and random manipulation. As in the Internet age, security is destined to be easily overlooked in the early stages of the Internet of Things. For this reason, we also did not take it lightly when designing the system:

All access layer communications are encrypted using tls, including open interfaces to apps and business servers.

User and device key information are encrypted and saved

Complete user authentication mechanism for devices

Other security measures for Internet security scenarios

Security is not a one-off event. It needs to be considered when the system is built, and the security tools and rules are constantly improved.

Development board

In order to reduce the development cost of IoT hardware, we designed the ISAN development board TIsan based on esp8266, and implemented our embedded development framework and IoT protocol in TIsan. The development board related code has been fully open source, and is currently crowdfunding in Taobao.

Tisan

Why is the development board available? We believe that this is a tool for learning, communicating and precipitating technology. I hope more fans can make good products together.

In the name of open source

Time flies, white gaps. Along the way, we are obsessively putting all the designs into practice and contributing to the future of IoT technology. IoT technology involves many directions, and our strength is limited. This is why we developed projects from the very beginning in the form of open source.

Now, we are calling for contributors!

If you have the same dedication and hobbies as I do for the Internet of Things and open source technologies, please pay attention to or join our open source project. In the future, we will gradually release all system designs and projects. We hope that more of our small partners will contribute to the project, whether it is to submit an issue or contribute code.

Hope we are not alone.

Semiconductor Parts

Semiconductor Parts

Semiconductor Parts

YANGZHOU POSITIONING TECH CO., LTD. , https://www.yzpst.com

Posted on