Difference between revisions of "Template:Pico-SIM7080G-Manual"
(Created page with "=== AT Test === ==== Example description ==== This routine is mainly to facilitate the user to directly test the AT command transmission and reception of the verification modu...") |
|||
Line 45: | Line 45: | ||
2、Download micro python examples:[https://www.waveshare.com/w/upload/5/5d/Pico-SIM7020X-NB-loT-Demo-Code.zip 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. | 2、Download micro python examples:[https://www.waveshare.com/w/upload/5/5d/Pico-SIM7020X-NB-loT-Demo-Code.zip 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: | * HTTP GET: | ||
− | def | + | # HTTP GET TEST |
− | + | def http_get(): | |
− | + | send_at('AT+SHDISC', 'OK') | |
− | + | send_at('AT+SHCONF="URL",\"'+http_get_server[0]+'\"', 'OK') | |
− | + | set_http_length() | |
− | + | send_at('AT+SHCONN', 'OK', 3000) | |
− | + | if send_at('AT+SHSTATE?', '1'): | |
+ | set_http_content() | ||
+ | resp = str(send_at_wait_resp('AT+SHREQ=\"'+http_get_server[1]+'\",1', 'OK',8000)) | ||
+ | # print("resp is :", resp) | ||
+ | try: | ||
+ | get_pack_len = int(resp[resp.rfind(',')+1:-5]) | ||
+ | if get_pack_len > 0: | ||
+ | send_at_wait_resp('AT+SHREAD=0,'+str(get_pack_len), 'OK', 5000) | ||
+ | send_at('AT+SHDISC', 'OK') | ||
+ | else: | ||
+ | print("HTTP Get failed!\n") | ||
+ | except ValueError: | ||
+ | print("ValueError!\n") | ||
+ | else: | ||
+ | print("HTTP connection disconnected, please check and try again\n") | ||
* HTTP POST: | * HTTP POST: | ||
− | def | + | def http_post(): |
− | + | send_at('AT+SHDISC', 'OK') | |
− | + | send_at('AT+SHCONF="URL",\"' + http_post_server[0] + '\"', 'OK') | |
− | + | set_http_length() | |
− | + | send_at('AT+SHCONN', 'OK', 3000) | |
− | + | if send_at('AT+SHSTATE?', '1'): | |
− | + | set_http_content() | |
− | + | send_at('AT+SHCPARA', 'OK') | |
− | + | if send_at('AT+SHBOD=62,10000', '>', 1000) : | |
+ | send_at(http_post_tmp, 'OK') | ||
+ | resp = str(send_at_wait_resp('AT+SHREQ=\"/'+http_post_server[1]+'\",3','OK', 8000)) | ||
+ | # print("resp is :", resp) | ||
+ | try: | ||
+ | get_pack = int(resp[resp.rfind(',')+1:-5]) | ||
+ | print(get_pack) | ||
+ | if get_pack > 0: | ||
+ | send_at_wait_resp('AT+SHREAD=0,' + str(get_pack), 'OK', 3000) | ||
+ | send_at('AT+SHDISC', 'OK') | ||
+ | else: | ||
+ | print("HTTP Post failed!\n") | ||
+ | except ValueError: | ||
+ | print("ValueError!\n") | ||
+ | else: | ||
+ | print("Send failed\n") | ||
+ | else: | ||
+ | print("HTTP connection disconnected, please check and try again\n") | ||
− | <font color="red">For more information about the HTTP function of SIM7020X module, please refer to [ | + | <font color="red">For more information about the HTTP function of SIM7020X module, please refer to [[:File:SIM7070/SIM7080_Series_HTTP_Application_Note_V1.02.pdf]]</font> |
3、Connect the Pico-SIM7020X-NB-IoT to Pico and connect the Pico to Raspberry Pi or PC by USB cable.<br /> | 3、Connect the Pico-SIM7020X-NB-IoT to Pico and connect the Pico to Raspberry Pi or PC by USB cable.<br /> | ||
Line 78: | Line 109: | ||
At the same time, users can go to the [http://pico.wiki/esp-chart.php http://pico.wiki/esp-chart.php] webpage to check the uploaded data which are showed by charts.For example:<br /> | At the same time, users can go to the [http://pico.wiki/esp-chart.php http://pico.wiki/esp-chart.php] webpage to check the uploaded data which are showed by charts.For example:<br /> | ||
:[[File:Pico-SIM7020X-NB-IoT-HTTP-GET-Result.png|800px]]<br />[[File:Pico-SIM7020X-NB-IoT-HTTP-POST-Result.png|800px]] | :[[File:Pico-SIM7020X-NB-IoT-HTTP-GET-Result.png|800px]]<br />[[File:Pico-SIM7020X-NB-IoT-HTTP-POST-Result.png|800px]] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 04:01, 11 June 2021
AT Test
Example description
This routine is mainly to facilitate the user to directly test the AT command transmission and reception of the verification module through the Thony software. The main program will first power on the module directly, and then check the network condition, then it will loop to detect the AT command input by the user, send it to the module through the serial port, and then return the AT command of the module to the Pico serial port for printing.
For the detailed AT command set, please see: SIM7080_Series_AT_Command_Manual_V1.02.pdf
Expected result
HTTP
With 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.
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.
Setup Server
Use http://pico.wiki/esp-chart.php as example, we setup the webpage of server for testing.
1、Build envrionments 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
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 be RaspberryPi when setting
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:
# HTTP GET TEST def http_get(): send_at('AT+SHDISC', 'OK') send_at('AT+SHCONF="URL",\"'+http_get_server[0]+'\"', 'OK') set_http_length() send_at('AT+SHCONN', 'OK', 3000) if send_at('AT+SHSTATE?', '1'): set_http_content() resp = str(send_at_wait_resp('AT+SHREQ=\"'+http_get_server[1]+'\",1', 'OK',8000)) # print("resp is :", resp) try: get_pack_len = int(resp[resp.rfind(',')+1:-5]) if get_pack_len > 0: send_at_wait_resp('AT+SHREAD=0,'+str(get_pack_len), 'OK', 5000) send_at('AT+SHDISC', 'OK') else: print("HTTP Get failed!\n") except ValueError: print("ValueError!\n") else: print("HTTP connection disconnected, please check and try again\n")
- HTTP POST:
def http_post(): send_at('AT+SHDISC', 'OK') send_at('AT+SHCONF="URL",\"' + http_post_server[0] + '\"', 'OK') set_http_length() send_at('AT+SHCONN', 'OK', 3000) if send_at('AT+SHSTATE?', '1'): set_http_content() send_at('AT+SHCPARA', 'OK') if send_at('AT+SHBOD=62,10000', '>', 1000) : send_at(http_post_tmp, 'OK') resp = str(send_at_wait_resp('AT+SHREQ=\"/'+http_post_server[1]+'\",3','OK', 8000)) # print("resp is :", resp) try: get_pack = int(resp[resp.rfind(',')+1:-5]) print(get_pack) if get_pack > 0: send_at_wait_resp('AT+SHREAD=0,' + str(get_pack), 'OK', 3000) send_at('AT+SHDISC', 'OK') else: print("HTTP Post failed!\n") except ValueError: print("ValueError!\n") else: print("Send failed\n") else: print("HTTP connection disconnected, please check and try again\n")
For more information about the HTTP function of SIM7020X module, please refer to File:SIM7070/SIM7080_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:
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.
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 showed by charts.For example: