Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize NB-IoT Communication with LiteOS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to achieve NB-IoT communication with LiteOS". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve NB-IoT communication with LiteOS".

1. Environment preparation hardware preparation

Development board

NB-IoT Communication Module (BC35-G)

BC35-G is a high-performance, low-power multi-band NB-IoT wireless communication module, which supports B1/B3/B8/B5/B20/B28 band and is compatible with BC95 in design and AT instructions.

The baud rate of the Bear pie NB-IoT communication expansion module is 9600bps.

Software preparation

QCOM Serial Port Assistant

Document preparation

BC35-G AT Command Manual

This document comes from the remote official! When reading this tutorial, please refer to this document for detailed instructions on the AT directive!

Changeover switch

If the switch in the upper right corner of the Bear development board is turned on to the AT-PC, the module is directly connected to the PC for easy debugging.

All tools and documentation are available on the official account of "Cubs Open Source Community" in reply to "Communication Module"!

2. NB-IoT AT instruction AT

Instruction: AT

Function: test whether the AT instruction function is normal

Example:

ATOK acquires signal strength indication

Instruction: AT+CSQ

Function: returns the signal strength indication and channel error rate received from UE, in which the first value rssi should be between 0 and 31, if it is 99, the signal cannot be detected, and the second parameter ber is always 99 because the module does not currently support it.

Example:

+ CSQ:26,99OK query network registration status

Instruction: AT+CEREG?

Function: query the current EPS network registration status. The first parameter returned by the instruction indicates that the network is not allowed to register URC, the second parameter indicates the network registration status, 1 indicates that the local network has been registered, 5 indicates that the roaming network has been registered, and the remaining values indicate that the registration failed.

Example:

+ CEREG:0,1OK queries whether the network is activated

Instruction: AT+CGATT?

Function: this command is used to query whether UE is currently attached to the PS domain. A return value of 1 indicates that it has been attached, that is, the network is activated successfully.

Example:

+ IP address of CGATT:1OK query module

Instruction: AT+CGPADDR

Function: this command is used to query the current ip address of the module.

Example:

+ CGPADDR:0,10.44.108.10OK3. Based on UDP protocol to connect remote server communication example 3.1. Disable the registration feature of IoT platform

Because the NB-IoT module can be directly connected to the IoT platform, when testing the UDP connection separately, it is necessary to turn off the IoT platform registration function after the successful activation of the network and before obtaining the ip address.

Disable this feature using the following command:

AT+QREGSWT=23.2. Build a remote UDP server

First, we need to build a UDP server, which can be done in two ways:

Use Python, Java, C # and other languages to write server programs on the server.

Use the network debugging assistant to start the UDP server on the local PC

Because the NB-IoT module registers the public network ip address directly, we use the first method to run a UDP test server written by Python on the Linux server:

The local PC uses a local area network, and the public network cannot access this PC directly according to the ip address. Private network penetration is required and is not recommended.

The Python program here is as follows:

# udp-server.pyfrom socket import * host =''port = 800' create server socketserver_socket = socket (AF_INET,SOCK_DGRAM) # bind socket listening address server_addr = (host,port) server_socket.bind (server_addr) print ('UDP Server Start...') # process connection request while (True): # receive the client's data data Addr = server_socket.recvfrom (1024) print ("Receive from% Good bye% s"% addr% data) if data = = b "quit": server_socket.sendto (b "Good bye!\ n", addr) continue server_socket.sendto (b "Hello,udp client!\ n", addr)

Run:

Python3 udp-server.py

The effect is as follows:

3.3. Module communicates with server to create Socket

To connect to the UDP server using the AT command, you first need to create a Socket of type UDP. The instructions for creating socket are as follows:

AT+NSOCR=

The first parameter is socket, DGRAM indicates UDP;, the second parameter represents protocol type, UDP is 17, UDP is 6, the last parameter specifies the local port used by socket, and 0 indicates random assignment.

So the example of creating a UDP socket is as follows:

The AT+NSOCR=DGRAM,17,01OK module sends messages to the server

Directive:

AT+NSOST=

The first parameter is the Socket number returned by AT+NSOCR, the second parameter is the ip address of the UDP server, or you can use the domain name, the third parameter is the port on which the UDP server is listening, the fourth parameter is the length of the data to be sent, and the last parameter is the hexadecimal data to be sent.

Note: this command is for UDP scoket connection servers only, and all parameters have no quotation marks!

Example:

AT+NSOST=1122.51.89.94,8000,4,303132331,4OK

After sending, you can also see it on the server side:

The module receives server messages

After the module sends data to the server, the server will automatically send a message, and the module will print out a prompt to receive the message:

+ NSONMI:1,18

This message indicates that socket numbered 1 received 18 bytes of data.

You can view the received data using the following command, the first parameter is the socket number, and the second parameter is the data length of the query:

AT+NSORF=

View the data you just received:

AT+NSORF=1181122.51.89.94,8000,18,48656C6C6F2C75647020636C69656E74210A,0OK

The data received is the penultimate parameter and is in hexadecimal format:

48656C6C6F2C75647020636C69656E74210A

Use online tools to convert the data to a string:

Close scoket

After the communication is complete, you can use the following command to close the socket that was originally created:

AT+NSOCL=

Example:

AT+NSOCL=1OK so far, I believe you have a deeper understanding of "how to achieve NB-IoT communication in LiteOS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report