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 GPRS function Test by MicroPython

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

Share

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

This article mainly introduces MicroPython how to achieve GPRS functional testing related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this MicroPython how to achieve GPRS functional testing article will have a harvest, let's take a look.

What is TPYBoardV702

TPYBoardV702 is the only MicroPython development board on the market that supports communication functions: it supports Python3.0 and above versions to run directly. Support GPS+ Beidou dual-mode communication, GPRS communication, SMS function, phone function; board temperature and humidity, photosensitive, three-axis accelerometer, buzzer, LCD5110 display screen. Communication test service platform is provided free of charge. The physical object is as follows:

Second, use TPYBoardV702 to upload data to the server using GPRS function.

1. Specific requirements

Use TPYBoardV702 to upload data to the server using GPRS function.

2. Required devices

TPYBoardV702 development board

One Gsm mobile phone card

TPYBoardV702 develops board GPRS communication function without external connection.

3. Introduction to the function and use of onboard communication

The overall highlight of the V702 development board is the on-board communication function, which can be used as long as a usable mobile phone card is inserted into the card slot of the development board (does not support telecommunications).

The communication functions on the development board include phone, SMS, GPRS and other functions. In this experiment, we only use GPRS.

We use the GPRS function mainly to transmit data to the server transparently, so our first step is to turn on the transparence function.

Then we need to establish a connection with the server, and then we need to know the address and port of the server. In this experiment, we use the official test platform to send a self-edited data packet to learn how to use the GPRS function.

Let's talk about the production process in detail.

Third, the main process of production

Let's start with the previous picture, and then we'll talk about the code.

Putty data monitoring chart

Sample positioning map

1. Production process

(1) the first step is to insert the mobile phone card into the slot of the development board to ensure that the mobile phone card can be used.

(2) after the above work is completed, we begin to edit the main (). Py file code

(3) declare and define the class libraries that need to be used

(4) define the variables we need to use.

(5) declare and define the interfaces we need to use. Here we mainly use the serial port 4. When we declare the serial port 4, we need to set the serial port baud rate to 115200.

(7) Let's start with the writing of the main function. In this experiment, we use the data packet. Let's first create a new packet in accordance with the format.

(8) after completing the above, the most important thing we need to do is to define the "Y6" pin as the output, then pull the "Y6" pin down for more than two seconds, and then pull the pin up. Because the "Y6" pin is a switch that controls the opening of the entire on-board communication system, if we do not use the communication system at ordinary times, in order to save power consumption, the on-board communication system is turned off and only need to lower the "Y6" pin for more than two seconds.

(9) when the red inline LED light on the development board is flashing quickly, it means that the onboard communication system is starting, and when the red inline indicator light ends the flash (if the mobile phone plugged into the development board slot is available, the indicator is in slow flash state), it means that the onboard communication system has been activated.

(10) after completing the above work, the preparation work has been completed. Next, we need to set the communication mode of the communication system to transparent transmission, and then connect with the corresponding server address and port.

(11) after establishing a connection with the server, you can start to send data to the server, just send the data out of serial port 4 directly, and the communication system will send the data you sent to the server intact.

2. Specific code:

Import pybimport upcd8544from machine import SPI,Pinfrom pybimport UARTfrom ubinascii import hexlifyfrom ubinascii import * # above is the class library leds = [pyb.LED (I) for i in range (1Magi 5)] that is declared to be used. MOSI 'X8' data flow (Master out) Slave in) # CLK = > SPI (1). SCK 'X6' SPI clockRST = pyb.Pin (' X20') CE = pyb.Pin ('X19') DC = pyb.Pin (' X18') LIGHT = pyb.Pin ('X17') lcd_5110 = upcd8544.PCD8544 (SPI, RST, CE, DC, LIGHT) # above are functions that initialize the display screen Although # is not used to show this time But standby count_=0N2 = Pin ('Y3cycles, Pin.OUT_PP) N1 = Pin (' Y6legs, Pin.OUT_PP) # define communication system startup pin N1.low () pyb.delay (2000) N1.high () pyb.delay (10000) # pull high and low pin, start communication system U2 = UART (4, 115200) # define serial port 4 Set baud rate to 115200K=5# set a selection variable Kwhile (Knowledge5): # this loop is to set the communication area mode to transparent mode. U2.write ('AT+CIPMODE=1\ r\ n') pyb.delay (500) if (u2.any () > 0): print (' transparent') _ dataRead=u2.readall () print ('transparent', _ dataRead.decode ('utf-8')) if (_ dataRead.find (baked OK') >-1): Khaso pyb.delay (20) u2.write (' AT+CIPSTART= "TCP") The statement "139.196.109.178", 30000\ r\ n') # is used to build a communication connection. Pyb.delay (10000) print ('123') while (Knowledge0): # this is to determine whether a communication connection has been established, and if no communication connection has been established, # then wait. Pyb.delay (3000) if (u2.any () > 0): _ dataRead=u2.readall () print ('oo' _ dataRead) if (_ dataRead.find (b'CONNECT OK') >-1): # this judgment is to determine whether a connection has been established with the server. Then change the value of the selection variable to enter the next # loop pyb.LED (1). On () while (Knowledge1): # this cycle is where the data transfer command is executed, in which various data are cut, spliced and sent. Print ('DOU') # u2.write (' + +') at this time, the whole system enters transparent communication mode. If you want to exit, send'+ + 'and you can # exit; # u2.write (' ATO0') wants the system to enter transparent mode from instruction mode, then send 'ATO0', to enter transparent mode. # pyb.delay (1500) pyb.LED (2). Off () pyb.LED (3). Off () pyb.LED (2). On () u2.write ('TPGPS,1234567890abcde,36.67191670119.17200000,201701120825,25,50,END') # this message format is based on the sample message format of the service platform. # replace the latitude and longitude data in this format with the latitude and longitude obtained from the positioning system, which can be located in real time. Pyb.delay (13000) # delay time. Officially provided test platform has upload frequency limit if (u2.any () > 0): # after sending data to the server, the server will judge the data and return the corresponding message # (see service platform for message parameters) # this return is only applicable to the official service platform. Whether the platform built by the customer # has this function, the customer can build it by himself. _ dataRead=u2.readall () print ('1212 pyb.delay) pyb.LED (3). On () pyb.delay (10000) this is the end of the article on "how MicroPython implements GPRS functional testing". Thank you for reading! I believe you all have a certain understanding of "how MicroPython implements GPRS functional testing". If you want to learn more, you are welcome to follow the industry information channel.

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