In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to use the TPYBoardv702 short message function, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
TPYBoardv702 is the only MicroPython development board on the market that supports communication and location functions: it supports Python3.0 and above versions to run directly. Support GPS+ Beidou dual-mode positioning, GPRS communication, SMS function, phone function; on-board temperature and humidity, photosensitive, three-axis accelerometer, buzzer, LCD5110 display screen. Provide location testing service platform free of charge.
The communication device on the TPYBord_V7.0.2 development board is a GU620 communication and positioning module developed by Shenzhen Hefangyuan Company. This module is powerful and supports GPS,GPRS,GSM, Bluetooth and other functions. This time, let's talk about the use of the function of sending text messages.
After realizing the function of short message, you can also rely on the function of short message to realize the real-time acquisition of temperature and humidity, longitude and latitude (may compare with SMS fee)
1. A preliminary understanding of the principle of sending short messages
The signal frequency of the mobile phone is very high, usually around 900Mhz, propagated by ionospheric reflection, and the mobile phone message of making a call.
The signal is transmitted to the nearest base station, that is, the mobile or connected signal tower, and the base station lowers the frequency of the high-frequency signal.
Communication between the base station and the base station, this signal is transmitted in a straight line, and the tall buildings will be blocked, so those towers are all
The erection is very high, it is transmitted to the base station near the phone that answers the phone, and then it is converted into a high-frequency signal to send to the mobile phone.
The implementation principle of short message service (SMS-ShortMessageService) is very simple:
The first is store-and-forward mechanism. SMS transmits data packets by the short message center in the mobile network, not the end user. If the user is not in the service area, the short message is stored in the short message center, and then forwarded to him after the user appears, which is not available in GPRS and other services. The second is the transmission confirmation mechanism. In a circuit-switched data environment, the connection is end-to-end, so the user can know whether the connection is completed and the data transfer.
To put it more popularly:
The base station is always transmitting signals, and a very important part of the broadcast messages is the broadcast message. one of the broadcast messages is the paging message (including the phone number). When it finds that a paging message is addressed to it (that is, someone is calling it), it will establish a connection with the base station and contact the person who called you through the base station.
two。 Understand the SMS sending process of GU620
Through the above description, we have learned the basic principles and processes of sending SMS messages. Let's take a look at what the GU620 module needs to do when dealing with these processes.
First of all, we need to set the module to the SMS sending mode, which is set by the AT instruction AT+CMGF=1, which sets the module to open the SMS sending format and send it in text format.
As we said above, send text messages in text mode, but there are many kinds of text formats. Here we execute another instruction to format the text into a text format that our phones can stably and correctly recognize, AT+CSCS= "GB2312". This instruction is to set the text format for sending and receiving text messages to simplified Chinese.
The above two instructions set the mode and text format for sending text messages. Here is how to deal with an unexpected event (an event that occurs outside the process you want to execute). What if a new text message comes in when you are about to send a text message? If the new message is displayed as soon as it is received, it is obviously not very reasonable and will interrupt our process. Here, we use the AT+CNMI=2,1 instruction to store the new message in the SIM card, and then give a prompt to read it when we want to read it.
After we have set up these basic setup steps above, we need to write an important factor in sending text messages, the receiver's mobile phone number, into the module. We use the command AT+CMGS= "mobile phone number", which tells the module the destination number that we want to communicate.
After sending the correct instruction and mobile phone number, the module will prompt for the correct return value. When we get this return value, we can edit the content we want to send (Chinese characters are not supported). In this way, the module will send the edited text message to the previously entered mobile phone number.
When the message is sent successfully, the sent content and the corresponding prompt content will be returned.
3. Set up the program flow
According to the above introduction, we have a general understanding of the basic process of sending text messages, so we painstakingly set up the flow of the program according to this basic process.
1. When the development board is powered on, the red power indicator will be on.
two。 First of all, serial port 4 is defined, and the baud rate is set to 115200. The communication module and 32 chip rely on serial port to communicate.
3. Then we set two variables, Message,number, to store the SMS content and the recipient's mobile phone number.
4. At the top of the program, outside the total loop, use the program to lower the pin Y6 for more than two seconds. Y6 is connected to the switch pin of the communication module.
5. Then pull up Y6 with a delay of 10 seconds to ensure that the communication module starts normally.
6. Then we send AT+CMGF=1\ r\ n, and set the module to SMS sending mode.
7. If the module returns the correct prompt, we send AT+CSCS= "GB2312"\ r\ n to format the text
8. After the module returns the correct prompt, send AT+CNMI=2,1\ r\ n and set the mode of the new message.
9. When set, send AT+CMGS= "'+ number+'"\ r\ n, and send in the mobile phone number.
10. When the module returns a prompt for the correct mobile phone number, send Message+'\ r\ nreply and send the set content to the module.
11. After the module returns the sent text content and the corresponding prompt for successful delivery, the program ends.
4. source code
The following is a simple code I wrote for your reference.
Import pybimport upcd8544from machine import SPI,Pinfrom pybimport UARTfrom ubinascii import hexlifyfrom ubinascii import * leds = [pyb.LED (I) for i in range (1pime5)] P 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) count_=0N2 = Pin (' Y3mm, Pin.OUT_PP) N1 = Pin ('Y6') Pin.OUT_PP) N1.low () pyb.delay (2000) N1.high () pyb.delay (10000) U2 = UART (4, 115200) Message='TPYBoard_GPS00000000000001'# enter the content of the SMS you want to send Number=' destination number'# enter the mobile number w=0r=0while R0 that you want to send: _ dataRead=u2.readall () print ('1print) lcd_5110.lcd_write_string (' Message:',0,0) lcd_5110.lcd_write_string (str (Message)) 0 2) if (_ dataRead==b'AT+CMGF=1\ r\ n\ r\ nOK\ r\ n'): u2.write ('AT+CSCS= "GB2312"\ r\ n') pyb.delay (50) if (u2.any () > 0): _ dataRead=u2.readall () print (' 2nOK') _ dataRead) if (_ dataRead==b'AT+CSCS= "GB2312"\ r\ n\ r\ nOK\ r\ n'): u2.write ('AT+CNMI=2,1\ r\ n') pyb.delay (50) if (u2.any () > 0): _ dataRead=u2.readall () print (' 3dataRead==b'AT+CSCS=') _ dataRead) if (_ dataRead==b'AT+CNMI=2,1\ r\ n\ r\ nOK\ r\ n'): u2.write ('AT+CMGS= "' + number+'"\ r\ n') pyb.delay (50) if (u2.any () > 0): _ dataRead=u2.readall () print ('4VR' _ dataRead) # b'AT+CMGF=1\ r\ n\ r\ nOK\ r\ n'if (_ dataRead== bounded ATMs CMGS = "'+ number+'"\ r\ n\ n >'): u2.write (Message+'\ r\ n') # SMS content pyb.delay (50) If (u2.any () > 0): _ dataRead=u2.readall () print ('5dataRead=u2.readall' _ dataRead) print (len (_ dataRead)) w=len (_ dataRead) _ dataRead=str (_ dataRead) [2rig w] print ('6rig' _ dataRead) if (_ dataRead==Message): print ('7glaoko') lcd_5110.lcd_write_string ('Has been sent',0,5) ritual 10
5. Production of mass SMS sending machine:
1. The SMS group sender is based on the above program code.
two。 In the above code, we create a character variable to store the phone number, and here we create an array to store the phone number
3. After all the phone numbers are entered
4. Let's find out how many phone numbers there are in this array (that is, tell the chip how many mobile phones you want to text)
5. Then we call the data in this array in turn
6. And execute the process of sending text messages to this data.
7. And get the number of data in the array.
8. If all the data in the array is called once, end the sending of the program
6. Short message group sender routine
The following is the routine of the mass SMS machine I have done, which can be used for reference.
Import pybimport upcd8544from machine import SPI,Pinfrom pybimport UARTfrom ubinascii import hexlifyfrom ubinascii import * leds = [pyb.LED (I) for i in range (1pime5)] P 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) count_=0N2 = Pin (' Y3mm, Pin.OUT_PP) N1 = Pin ('Y6') Pin.OUT_PP) N1.low () pyb.delay (2000) N1.high () pyb.delay (10000) U2 = UART (4, 115200) Message='TPYBoard_GPS'# enter the content of the SMS you want to send Number= ['destination number 1' purpose number 2'] # enter the mobile number you want to send, w=0r=0E=0Q=0while R0): _ dataRead=u2.readall () print ('2dataRead=u2.readall' _ dataRead) if (_ dataRead==b'AT+CSCS= "GB2312"\ r\ n\ r\ nOK\ r\ n'): u2.write ('AT+CNMI=2,1\ r\ n') pyb.delay (50) if (u2.any () > 0): _ dataRead=u2.readall ( ) print ('3Rose' _ dataRead) if (_ dataRead==b'AT+CNMI=2,1\ r\ n\ r\ nOK\ r\ n'): u2.write ('AT+CMGS=''+ number [E] +'"\ r\ n') pyb.delay (50) if (u2.any () > 0): _ dataRead=u2.readall () print ('4purl' _ dataRead) # b'AT+CMGF=1\ r\ n\ r\ nOK\ r\ n'if (_ dataRead== bounded ATS CMGS = "'+ number [E] +'"\ r\ n\ n >'): u2.write (Message+'\ r\ n') # SMS content Pyb.delay (50) if (u2.any () > 0): _ dataRead=u2.readall () print ('5u2.any' _ dataRead) print (len (_ dataRead)) w=len (_ dataRead) _ dataRead=str (_ dataRead) [2rig w] print ('6rig' _ dataRead) if (_ dataRead==Message): print ('7dataRead==Message') E=E+1 lcd_5110.lcd_write_string ('OK IS:'+str (E)) 0penny 5) pyb.delay (24000) rang 10 Egg0 read the above content Do you know how to use the TPYBoardv702 SMS function? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.