1. What is the internet of things?
Readers should be familiar with the concept of Internet of Things (Internet of Things). The concept of Internet of Things was first put forward in 1999. It was once called the third wave of world Information Industry Development after computer and Internet, and has been developed for more than 20 years now. Nowadays, in our daily life, we have access to many internet of things products, such as various smart home appliances and smart door locks, which are mature applications of Internet of Things technology. The earliest definition of the internet of things is to connect all objects with the Internet through information sensing devices such as radio frequency identification to realize intelligent identification and management. Of course, with the development of the internet of things today, its definition and scope have been expanded and changed. The following are the characteristics of the modern internet of things. 1.1 IoT is Internet the Internet of Things is a part of the Internet. The Internet of Things uses the infrastructure of the Internet as the carrier of information transmission, that is, modern IoT products must be connected to the internet in some way, while "things" upload/download data through the Internet, and interact with people. Take the example of remotely starting a car through a mobile App. When a user completes the startup operation through the App, the command is sent from a mobile phone connected to the Internet to the cloud platform, the cloud platform finds the vehicle-side computer that has been connected to the Internet, and then issues the command. The vehicle-side computer executes the startup command and feeds back the execution result to the cloud platform. At the same time, this operation is recorded in the cloud. You can query the history of remote unlocking from the App at any time. **This is a typical IoT scenario. It is an Internet application. Things are connected to the internet. Data and information interact through the Internet, and data is aggregated to the cloud like other Internet applications.
1.2 The main body of the internet of things is "things" as mentioned above, the modern Internet of Things application is an Internet application, but there is a big difference between the Internet application and the traditional Internet application, that is, the main body of the traditional Internet production and consumption data is people, the main body of data production and consumption in the modern Internet of Things is things.
In modern IoT scenarios, data producers are "things", such as smart devices or sensors, and data consumers are often "things". In the application of intelligent agriculture, the temperature sensor in the incubator periodically transmits the temperature in the incubator to the control center. When the temperature is below a certain threshold, the center opens the heating device remotely according to the preset rules. In this scenario, the data producer is the temperature sensor, and the data consumer is the heating device. Both of them are "things", and people are not directly involved in them.
The biggest difference between IoT and traditional Internet is that data producers and consumers are mainly things, and data content is also closely related to things. 1.3 IoT and AI artificial intelligence is one of the most popular words in the IT field in recent years. Looking at the development route of artificial intelligence, we can see that there are two main reasons why the development of artificial intelligence can advance by leaps and bounds.
- The development of hardware makes the learning time of deep learning neural network Shorten rapidly.
- In the era of big data, the cost of obtaining large amounts of data becomes lower.
In fact, the second reason is particularly important. Due to the characteristics of neural networks, a large amount of data is required for learning. The effective data volume available for learning often determines the effect of the neural network trained at last, the importance of algorithms can be ranked behind the data volume. IoT devices, such as smart home appliances and wearable devices, generate massive amounts of data every day. After processing and cleaning, these data can be used as good training data to feed the neural network. At the same time, the trained neural network can be re-applied to IoT devices, thus forming a virtuous circle. Figure 1-1 shows the data collection-iteration cycle of the IoT application artificial intelligence method. Data is collected and trained by IoT devices. After the training is completed in the data center, the model is applied to IoT devices and the results are evaluated for the next iteration.
IoT is a good application scenario for AI. With the rapid development of artificial intelligence, the internet of things, a theory and technology also proposed many years ago, will usher in a new spring. Currently, internet data portals gradually converge to several Giants (such as Alibaba and Tencent), and the cost of obtaining data for smaller companies is getting higher and higher, * * the Internet of Things, a data field that has not yet been fully developed, is particularly important. * *. This is also the reason why this book focuses on the development of IoT platform but skips the development of front-end devices. Because front-end devices tend to be the same and there will be homogeneous competition. How to collect and use the massive amounts of data generated by devices, is the decisive factor for whether you have a competitive advantage. 1.4 The current situation and prospect of the Internet of Things
with the advent of the 5G era, the development of the Internet of Things will be very rapid. At the same time, new financing in the direction of the Internet of Things has been on the rise. The following describes the development prospects of the IoT industry from the perspective of application scenarios. IoT has a wide range of application scenarios, including:
- smart city
- intelligent Architecture
- internet of Vehicles
- smart Community
- smart Home
- smart Medical treatment
- industrial IoT
in different scenarios, IoT applications differ greatly, and terminals and network architectures are highly heterogeneous, which means that there are enough market segments in the IoT industry, it is very difficult for a company with dominant market share to appear. At the same time, because the market is large enough, enough companies can survive. This kind of situation is not common in the Internet industry. The head effect of the Internet industry is very obvious. The vast majority of the market share is often occupied by two or three companies in the head. Compared with internet mode, IoT mode is more important. IoT applications are always accompanied by front-end devices, which means that switching costs for users are relatively high. After all, removing and reinstalling devices is much more complicated than downloading an application again. This means that the driving force of capital is relatively weaker in the Internet of Things industry. If you get the first-mover advantage, then the latter wants to catch up with or push you out of the market only by the power of capital, then the price he pays is much higher than that in the Internet industry. So,The Internet of Things industry is still a blue ocean, and small-scale companies are fully capable of competing with large-scale companies in this industry. After the popularity of AI and blockchain is cooled down, the internet of things is likely to become the next tuyere. As a programmer, it is very necessary to reserve some knowledge in advance before the storm comes. 2. Common IoT protocols 2.1 MQTT Protocol MQTT Protocol (Message Queue Telemetry Transport, Message Queue Telemetry transmission protocol) was developed by Andy Stanford-Clark of IBM and Arlen Nipper of Arcom in 1999 for a project connecting the oil pipeline through satellite network. To meet the requirements of low power consumption and low network bandwidth, the MQTT protocol was designed with the following features:
- simple implementation
- provide QoS for data transmission
- lightweight and low bandwidth usage
- any type of data can be transmitted
- can Keep Session (Session)
with years of development, the focus of MQTT is no longer on embedded systems, but on a wider world of the internet of things.
The MQTT Protocol has the following features:
- application layer protocol based on TCP
- C/S architecture
- decouples the sender and receiver of a message by using the subscription/publish mode.
- Provides three types of message QoS(Quality of Service): at most once, at least once, only once
- sending and receiving messages are asynchronous, and the sender does not need to wait for the receiver to reply.
The MQTT architecture consists of a Broker and multiple clients connected to the Broker, as shown in Figure 2-1. MQTT can provide communication guarantee for a large number of low-power IoT devices with unreliable working network environment. It has also made great achievements in the field of mobile Internet. Many Android App push functions are implemented based on MQTT protocol, and some IM implementations are also based on MQTT protocol.
2.2 MQTT-SN protocol the MQTT-SN(MQTT for Sensor Network) protocol is the MQTT Sensor version. Although MQTT is a lightweight application layer protocol, MQTT runs on the TCP protocol stack. For some devices with very limited computing power and power, such as sensors, it is not suitable.
MQTT-SN runs on UDP and retains most signaling and features of MQTT, such as subscription and publishing. MQTT-SN gateway is introduced as a MQTT-SN gateway. The Gateway converts MQTT-SN protocol to MQTT protocol and communicates with remote MQTT Broker. MQTT-SN supports automatic gateway discovery. The communication model of MQTT-SN protocol is shown in Figure 2-2. 2.3 CoAP protocol coAP(Constrained Application Protocol) Protocol is a Protocol that runs on devices with limited resources. The CoAP protocol is usually run on UDP.
The CoAP protocol is designed to be very small, and the smallest data packet is only 4 bytes. The CoAP protocol adopts the C/S architecture and uses a request-response interaction mode similar to the HTTP protocol. The device can use a URL similar to coap:// 192.168.1.150:5683/2ndfloor/temperature to identify an entity, and use PUT, GET, POST, DELET requests the command to obtain or modify the status of the entity.
At the same time, CoAP provides an observation mode, in which the observer can indicate the observed entity object to the CoAP server through OBSERVE instructions. When the status of an object changes, the observer can receive the latest status of the object, which is similar to the subscription function in MQTT. The communication model of CoAP protocol is shown in Figure 2-3.
2.4 LwM2M protocol lwM2M( Lightweight Machine-To-Machine) protocol is a Lightweight protocol defined by Open Mobile Alliance(OMA) for IoT. It uses RESTful interfaces to provide access, management, and communication functions for devices. It is also suitable for devices with limited resources. The architecture of the LwM2M protocol is shown in Figure 2-4. The LwM2M protocol uses the CoAP protocol to transmit data and signals. In the LwM2M architecture, the CoAP protocol can be run on UDP or SMS, and data can be safely transmitted through DTLS (Datagram Transport Layer Security).
The LwM2M Bootstrap Server guides the LwM2M Client to register and connect to the LwM2M Server. Then, the LwM2M Server and the LwM2M Client can interact through the interface specified by the protocol. 2.5 HTTP protocol as we said before, the Internet of Things is also the internet. HTTP, a protocol widely used in the Internet, can also be applied to the internet of things in an appropriate environment. On some devices with abundant computing and hardware resources, such as those running Android operating systems, you can use HTTP to upload and download data, just like developing mobile applications. Devices can also use WebSocket running over HTTP to actively receive data from servers. 2.6 LoRaWAN protocol LoRaWAN protocol is a low-power WAN protocol proposed and promoted by LoRa Alliance, which is different from several protocols we introduced earlier. Both the MQTT Protocol and the CoAP protocol run on the application layer. The underlying layer uses TCP or UDP protocol for data transmission. The entire protocol stack runs on the IP network. The LoRaWAN protocol is the physical layer/data link layer protocol, which solves the problem of how devices access the internet and does not run on IP networks. LoRa(Long Range) is a wireless communication technology, which has the characteristics of Long use distance and low power consumption. In the preceding scenario, users can use the LoRaWAN technology for networking and install LoRA-supporting modules on engineering equipment. The LoRa relay device sends data to the LoRa gateway that is located outside the tunnel and has Internet access, loRa gateway encapsulates the data into a data protocol package (such as MQTT) that can be transmitted over TCP or UDP in the IP network and then sends the data to the data center in the cloud.2.7 NB-IoT protocol the NB-IoT(Narrow Band Internet of Things) protocol is the same as the LoRaWAN protocol, which connects devices to the physical layer/data link layer of the Internet.
Different from LoRA, NB-IoT protocol is built and run on cellular networks, which consumes less bandwidth and can be directly deployed to the existing GSM network or LTE network. The device is installed with chips that support NB-IoT and corresponding internet of things network card, and then connected to NB-IoT base station to access the Internet. In addition, the NB-IoT protocol does not require the gateway to perform protocol conversion like the LoRaWAN protocol. The connected device can directly use the IP network for data transmission.
Compared with the traditional base station, the gain of the NB-IoT protocol is increased by about 20dB, which can cover the underground garage, pipeline, basement and other places where the signal is difficult to cover before.