Pico SIM7080G Cat-M/NB-IoT

From Waveshare Wiki
Jump to: navigation, search
Pico-SIM7080G-Cat-M-NB-IoT
Pico-SIM7080G-Cat-M-NB-IoT

SIM7080G NB-IoT / Cat-M(EMTC) / GNSS Module For Raspberry Pi Pico, Global Band Support
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

Introduction

The Pico-SIM7080G-Cat-M/NB-IoT is an NB-IoT (NarrowBand-Internet of Things), Cat-M (aka eMTC, enhanced Machine Type Communication), and GNSS (Global Navigation Satellite System) module designed for Raspberry Pi Pico. It supports multiple NB-IoT frequency band, can be controlled via serial AT commands, and supports communication protocols like HTTP/MQTT/LWM2M/COAP, etc. Due to the advantages of low delay, low power, low cost, and wide coverage, it is the ideal choice for IoT applications such as intelligent instruments, asset tracking, remote monitoring, and so on.

Features

  • Standard Raspberry Pi Pico header, supports Raspberry Pi Pico series boards.
  • UART communication, serial AT commands control.
  • Communication protocol support: TCP/UDP/HTTP/HTTPS/TLS/DTLS/PING/LWM2M/COAP/MQTT...
  • GNSS positioning support: GPS, GLONASS, BeiDou, and Galileo.
  • Integrates 3.7V Li-po battery connector and recharge circuit, allowing being powered from external rechargeable Li-po battery, or recharge it in turn.
  • 2 x LED indicators, for monitoring the module operating status.
  • Onboard Nano SIM card slot, supports ONLY 1.8V SIM card (3V SIM card is not available).
  • Comes with online development resources and manuals (MicroPython examples).

Specifications

Product

SIM7080G

SIM7020C / SIM7020E

FREQUENCY BAND

NB-IoT

B1/B2/B3/B4/B5/B8/B12/B13/B18/B19/
B20/B25/B26/B28/B66/B71/B85

SIM7020C:
LTE-FDD:B1/B3/B5/B8
SIM7020E: LTE-FDD:B1/B3/B5/B8/B20/B28

Cat-M

B1/B2/B3/B4/B5/B8/B12/B13/B14/B18/
B19/B20/B25/B26/B27/B28/B66/B85

-

GNSS

GPS, GLONASS, BeiDou, Galileo

-

Applicable region

global applicable

SIM7020C:China
SIM7020E:Asia, Europe, Africa, Australia

DATA RATE

NB-IoT (Kbps)

136 (DL)/150 (UL)

26.15 (DL)/62.5 (UL)

Cat-M (Kbps)

589 (DL)/1119 (UL)

-

OTHERS

Communication protocol

TCP/UDP/HTTP/HTTPS/TLS/DTLS/PING/LWM2M/COAP/MQTT

Power supply

External Li-po battery OR Raspberry Pi Pico USB port

Battery interface

3.7V ~ 4.2V

Logic level

3.3V

Module standalone current

Idle mode:10mA

Idle mode:5.6mA

Sleep mode:1.2mA

Sleep mode:0.4mA

PSM mode:3.2uA

PSM mode:3.4uA

Indicator

NET:NET: network indicator
Charge: recharge indicator

Switch

Li-po battery power supply switch

SIM card

NB-IoT / Cat-M card (1.8V ONLY)

NB card (1.8V / 3V)

Antenna connector

LTE, GNSS

LTE

Dimensions

73.5 × 24.00mm

Pinout Definition

Pico-SIM7080G-Cat-M-NB-IoT-details-inter.jpg

Outline Dimensions

Pico-SIM7080G-Cat-M-NB-IoT-details-size.jpg

Demo Download

cd ~
sudo wget  https://files.waveshare.com/upload/5/5d/Pico-SIM7020X-NB-loT-Demo-Code.zip
unzip Pico-SIM7020X-NB-loT-Demo-Code.zip
cd ~/Pico-SIM7020X-NB-loT-Demo-Code

HTTP

In this example, the Raspberry Pico can connect to the network by NB-IoT. You can use HTTP GET to get the weather information from weather websites and post the temperature of Pico to the server by HTTP POST.
You can access the webpage and check the real-time data posted.
Pico-SIM7020-HTTP-demo-diagram.png

Setup Hardware

Solder female/male pin headers to Pico-SIM7020X-NB-IoT and connect the NB-IoT board to Pico. Connect the battery, Antenna, and insert the NB-IoT card.
Pico-SIM7020X-NB-IoT-connection.png

Setup Server

Use http://pico.wiki/esp-chart.php as an example, we set up the webpage of the server for testing.
Pico-SIM7020-HTTP-Demo-2.png
1. Build environments like php and mysql, etc. Create database file, for example:

  • Database:example_esp_data
  • Password:your_password
  • User Name:your_username
  • Create database table:
CREATE TABLE Sensor (
   id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
   value1 VARCHAR(10),
   value2 VARCHAR(10),
   value3 VARCHAR(10),
   reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)

2. Two example files are provided for the server. they are post-data.php and esp-chart.php.

  • post-data.php: API of HTTP POST (server). SIM7020X module can POST data to the server by using this API.
  • esp-chart.php: Webpage of Client. You can get the newest data that SIM7020X uploaded by this webpage and show it with the chart.

Software setup in Pico

1. Please follow the guides of Raspberry Pi to install and set up Pico for the Pico.

For easy use, we recommend you use the Thonny tool.

  • Thonny website
  • Please set the Thonny development environment to RaspberryPi when setting.
Pico-R3-Tonny1.png

2. Download micro python examples: Pico-SIM7020X-NB-loT-HTTP.py. Here we only list part of the sample codes, for more information on sample codes, please download the codes.

  • HTTP GET:
def httpGetTest():
   sendCMD_waitResp("AT+CHTTPCREATE=\"http://api.seniverse.com\"")    #Create HTTP host instance
   sendCMD_waitResp("AT+CHTTPCON=0")           #Connect server
   sendCMD_waitRespLine("AT+CHTTPSEND=0,0,\"/v3/weather/now.json?key=SwwwfskBjB6fHVRon&location=shenzhen&language=en&unit=c\"")  #send HTTP request
   waitResp()
   sendCMD_waitResp("AT+CHTTPDISCON=0")      #Disconnected from server
   sendCMD_waitResp("AT+CHTTPDESTROY=0")      #Destroy HTTP instance
  • HTTP POST:
def httpPostTest():
   global i
   i=i+1
   sendCMD_waitResp("AT+CHTTPCREATE=\"http://pico.wiki/post-data.php\"")    #Create HTTP host instance
   sendCMD_waitResp("AT+CHTTPCON=0")           #Connect server
   sendCMD_waitRespLine("AT+CHTTPSEND=0,1,\"/post-data.php\",4163636570743a202a2f2a0d0a436f6e6e656374696f6e3a204b6565702d416c6976650d0a557365722d4167656e743a2053494d434f4d5f4d4f44554c450d0a,\"application/x-www-form-urlencoded\","+str_to_hexStr("api_key=tPmAT5Ab3j888&value1="+str(temperature)+"&value2="+str(ADC0_reading)+"&value3="+str(i)))  #send HTTP request
   waitResp()
   sendCMD_waitResp("AT+CHTTPDISCON=0")      #Disconnected from server
   sendCMD_waitResp("AT+CHTTPDESTROY=0")      #Destroy HTTP instance

For more information about the HTTP function of SIM7020X module, please refer to SIM7020_Series_HTTP_Application_Note_V1.02.pdf

3. Connect the Pico-SIM7020X-NB-IoT to Pico and connect the Pico to Raspberry Pi or PC by USB cable.

  • Open the Thonny software, Choose MicroPython(Raspberry Pi Pico), and open the sample codes.
  • Please first click Stop(No.1), and then click the Run(No.2) buttons to run the demo codes. You can check the status by the Shell window(No. 3) for example:
Pico-SIM7020X-NB-IoT-Run-Code.png

4. You can check, modify, or run/debug the sample code by the Thonny software.

  • If you want to make the codes auto-run, please choose File -> Save as -> Raspberry Pi Pico, and save it as main.py.
Pico-Save-as-main py.png

Expected Result

With the Pico-SIM7020X-NB-loT-HTTP.py example, Pico can get the weather information from the weather website by HTTP GET and post the temperature of Puco to pico.wiki by HTTP POST.
At the same time, users can go to the http://pico.wiki/esp-chart.php webpage to check the uploaded data which are shown by charts. For example:

Pico-SIM7020X-NB-IoT-HTTP-GET-Result.png
Pico-SIM7020X-NB-IoT-HTTP-POST-Result.png

TCP examples

This example is used to create a TCP client with NB-IoT network in Raspberry Pico, then connect to a remote server and send requests. The TCP server used in this example is just for testing and it will echo the data sent by the client.
SIM7020 TCPIP support multiple clients and one TCP server, it supports six sockets includes TCP and UDP.
Pico-SIM7020-HTTP-Demo-4.png

Code analysis

  • Defind the IP of the TCP server and the port.
ServerIP = '118.190.93.84'
Port = '2317'
  • Pico-SIM7020C-NB-IoT networking test.
#AT commands test
def atCommandTest():
   sendCMD_waitRespLine("AT")                     #Test connection
   sendCMD_waitRespLine("ATE1")                #Set command echo mode
   sendCMD_waitRespLine("AT+CGMM")
   sendCMD_waitRespLine("AT+CPIN?")        #whether some password is required or not
   sendCMD_waitRespLine("AT+CSQ")          #received signal strength
   sendCMD_waitRespLine("AT+CGREG?")        #the registration of the ME.
   sendCMD_waitRespLine("AT+CGATT?")       #GPRS Service's status
   sendCMD_waitRespLine("AT+CGACT?")       #PDN active status
   sendCMD_waitRespLine("AT+COPS?")       #Query Network information
   sendCMD_waitRespLine("AT+CGCONTRDP")       #Attached PS domain and got IP address automatically
  • Send a request to the TCP server.
def tcpclientTest():
   sendCMD_waitRespLine("AT+CSOC=1,1,1")    #create TCP socket 
   sendCMD_waitRespLine("AT+CSOCON=0,"+Port+",\""+ServerIP+"\"")    #socket_id = 0,connect TCP server
   sendCMD_waitRespLine("AT+CSOSEND=0,0,\"Hello,World\"")    #send TCP data
   sendCMD_waitRespLine("AT+CSOCL=0")    #close TCP socket
  • Convert the data from HEX to a string sent from the server.
if send_data in uart.readline().decode():
   print((uart.readline()).decode())
   print((uart.readline()).decode())
   word = (uart.readline()).decode().split(',') #hexStr_to_str
   get_word = word[2].split('\r')
   word[2] = hexStr_to_str(get_word[0]) 
   print(word[0]+','+word[1]+','+word[2])

Expected result

With the Pico-SIM7020X-NB-loT-TCP.py example, the Client sent the "Hello,World" string to the TCP server and receive the same data from the server.

Pico-SIM7020-HTTP-Demo-5.png

MQTT

This example is used to send MQTT requests by the MB-IoT network in Raspberry Pi Pico. It will connect to the Alibaba Cloud MQTT server, subscribe to a topic, and post a message.

Pico-SIM7020-HTTP-Demo-8.png

Codes analysis

  • Define device information of the MQTT server.
ProductKey = "a1IBIPnZU9G"
Broker_Address = ProductKey + ".iot-as-mqtt.cn-shanghai.aliyuncs.com"
DeviceName = "7020"
DeviceSecret = "8e870f4e611d3e4c2b8f9f017e6a88ab"
  • Test the MQTT function.
 # MQTT Test
def mqttconnectTest():
   sendCMD_waitRespLine("AT+CMQNEW="+"\""+Broker_Address+"\""+",\"1883\",12000,1024")  #create tcp connection 
   sendCMD_waitRespLine("AT+CMQALICFG=0,\""+ProductKey+"\",\""+DeviceName+"\",\""+DeviceSecret+"\"")     #set device parameters  
   sendCMD_waitRespLine("AT+CMQALICON=0,600,1")     # send MQTT request
   time.sleep(3)  
   sendCMD_waitRespLine("AT+CMQSUB=0,\"/"+ProductKey+"/"+DeviceName+"/"+"user/TEST1\",1")               # subscribe to topics
   time.sleep(3)
   sendCMD_waitRespLine("AT+CMQPUB=0,\"/"+ProductKey+"/"+DeviceName+"/user/TEST1\",1,0,0,16,\"3132333435363738\"")  # release the news
   time.sleep(3)
   sendCMD_waitRespLine("AT+CMQUNSUB=0,\"/"+ProductKey+"/"+DeviceName+"/user/TEST1\"")  # unsubscribe topic
   time.sleep(3)
   sendCMD_waitRespLine("AT+CMQDISCON=0")   # disconnect MQTT connection

Buid Alibaba Cloud MQTT Server

1. Go to the Alibaba Cloud IoT platform, the platform is not free and you need to pay for it. The enterprise version is free in the first month.
2. Create a product.
Pico-SIM7020-HTTP-Demo-9.png
Pico-SIM7020-HTTP-Demo-10.png
Click ok and choose Add Device.
3. Set the DeviceName, and check the DeivceSecret of the device. You need to save these data and modify the MQTT codes.
Pico-SIM7020-HTTP-Demo-11.png
Pico-SIM7020-HTTP-Demo-12.png
4. Register topic, click Products--> check 7020_test-->Topic Categories-->Edit Topic Category-->Choose Publish and Subscribe.
Pico-SIM7020-HTTP-Demo-13.png

Expected Result

With the Pico-SIM7020X-NB-loT-MQTT.py example, you can find that you have subscribed to a topic and send a message to it. The server will push this message to you.
Pico-SIM7020-HTTP-Demo-7.png
At the same time, you can check the topic subscribed in the device list.
Pico-SIM7020-HTTP-Demo-6.png

C

  • Compile and make sure it is in the C directory:
cd c/
  • Create and enter the build directory, and add SDK: ../../pico-sdk as the SDK directory. There is a "build" in the demo we provided. Directly enter:
cd build
export PICO_SDK_PATH=../../pico-sdk
(Note: Be sure to write the right path to your own SDK.)
  • Execute cmake and automatically generate Makefile.
cmake ..
  • Open main.c below the C file folder, choose the function you want to test and comment out the functions that are not related to it.

Pico-SIM manual010.jpg

  • Execute make and generate the executable file, and it may take a long time to compile for the first time.
make -j9
  • After compiling, the uf2 file is generated. Press the Pico button, connect the Pico to the USB port of the Raspberry Pi with a Micro USB cable, and then release the button. After connecting, the Raspberry Pi can automatically recognize a movable disk (RPI-RP2), and copy the main.uf2 file under the build file folder to the recognized movable disk (RPI-RP2).
cp main.uf2 /media/pi/RPI-RP2/
  • After downloading, run minicom and you can see the module status. After running minicom, you should reboot the pico.
  • Install minicom.
sudo apt install minicom
  • Run minicom.
minicom -D /dev/serial/by-id/usb-Raspberry_Pi_Pico_000000000000-if00

Running Effect

Pico SIM manual 020.jpg

Support

If you require technical support, please go to the Support page and open a ticket.