micropython+ Beidou +gps+gprs:tpyboardv702 SMS Function usage Instructions

Source: Internet
Author: User

Reprint please indicate the source of the article as a link (micropythonqq technology Group: 157816561, public number: Micropython player)

TPYBoardv702 is the only Micropython Development Board in the market that supports the communication positioning function: Supports Python3.0 and above to run directly. Support gps+ Beidou dual-mode positioning, GPRS communication, SMS function, telephone function, onboard temperature and humidity, photosensitive, triaxial accelerometer, buzzer, LCD5110 display. Provide location testing Service platform free of charge.

tpybord_v7.0.2 Development Board on-board communication device is a GU620 communication positioning module developed by Shenzhen Fangyuan Company, this module is powerful, and support GPS,GPRS,GSM, Bluetooth and other functions, this time to specifically say the use of the function of sending SMS.

Can realize the text message function can also rely on the function of text messages to achieve real-time temperature and humidity, through the latitude of real-time access (may compare the cost of SMS),

  1. Basic message Sending principle

Mobile phone signal frequency is very high, generally around 900Mhz, by the ionospheric reflection spread, telephone phone letter

To the nearest base station, that is, a mobile or connected signal tower, and the high frequency signal frequency is lowered by the base station,

Communication between the base station and the base station, the signal is transmitted in a straight line, the high buildings are blocked, so the towers are

Vertical high, to the phone's mobile phone near the base station, and then turn into a high-frequency signal to the mobile phone.

The implementation of the short Message Service (Sms-shortmessageservice) is simple:

The first is the storage and forwarding mechanism. SMS delivery of the work by the mobile network in the short message center rather than the end user to complete, if the user is not in the service area, the short message is stored in the short message center, and so on users appear, and then forwarded to him, this is GPRS and other services do not have. The second is the delivery confirmation mechanism. In a circuit-switched data environment, the connection is end-to-end, so the user is able to know whether the connection is complete, and how the data is passed.

Popular Point says:

The base station is always in the transmission signal, one of the important part is broadcast message, the broadcast message is a kind of paging message (including phone number), each phone is always listening to the paging message, when it found a pager message is to it (that is, someone is calling it), it will establish a connection with the base station, Contact the person who is calling you through the base station.

  2. Learn about the GU620 SMS delivery process

As described above, we understand the basic principles and processes of text messaging, and I'll 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 text message to send the mode, this through at command At+cmgf=1, to set, this instruction is to set the module to open the text message send format, and sent in text format.

The above one we said, the text message in the mode of sending, but the text has many kinds of formats, here we execute an instruction, the text format is set to our hand function stable and correctly recognize the text format, at+cscs= "GB2312", this instruction is to send and receive text message format set to Simplified Chinese.

The above two describes the setting of the mode and text format for sending text messages, and here is a way to deal with an unexpected event (an event that occurs outside of the process you want to perform), and what if a new text message comes in when you are about to send a message? If a new text message is received and displayed immediately, it is obviously not very reasonable, it will interrupt our process, here we use the at+cnmi=2,1 instruction to store the new message received into the SIM card, and then give a hint, when we want to read it again, it is more common sense.

After we set up the above basic setup steps, we need to send a message of an important factor, the receiver's mobile phone number to write into the module, we use the instruction at+cmgs= "mobile phone number", this instruction is to tell the module want to communicate the purpose of the number.

After sending the correct instruction and phone number, the module will prompt the correct return value, when we get the return value, we can edit the content we want to send (not support Chinese characters), so the module will send the edited text message to the mobile phone number entered earlier.

When the send is successful, the sent content is returned, along with the corresponding prompt content.

  3. Set up the program flow

According to the above introduction, we generally understand the basic flow of text messaging, then we are suffering based on this basic process to set up the process of the program.

1. Power on the board and the red supply indicator lights up;

2. First defines the serial port 4, the baud rate is set to 115200, the communication module and 32 chip is relies on the serial port communication;

3. We then set up two variable message,number to store the SMS content and the receiver's mobile phone number;

4. At the top of the program, the outside of the total cycle, using the program to pull the pin Y6 two seconds or more, Y6 is connected to the communication module of the switch pin;

5. Then pull the high Y6, delay 10 seconds, this is to ensure that the communication module normal boot;

6. After we send the at+cmgf=1\r\n, set the module for the SMS send mode;

7. If the module returns the correct prompt content, we send at+cscs= "GB2312" \ r \ n, set the format of the text;

8. After the module returns the correct prompt content, sends the at+cnmi=2,1\r\n, sets the new short interest mode;

9. After setting, send At+cmgs= "' +number+ '" \ r \ n, send the mobile phone number in;

10. When the module returns the correct prompt for the mobile phone number, send message+ ' \ r \ n ', sending the set content to the module;

11. The module returns the text content sent and the corresponding prompt to send a successful message, ending the program.

  4. Source code

Here is a simple code that I wrote to provide reference for you.

Import pybimport upcd8544from Machine import spi,pinfrom pyb import uartfrom ubinascii import hexlifyfrom ubinascii Import *leds = [Pyb. LED (i) for I in range (1,5)]p,l,shuchu=0,0,0spi = Pyb. SPI (1) #DIN =>x8-mosi/clk=>x6-sck#din =>spi (1). 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 (' Y3 ', 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 ' #输入你想要发送的短信的内容; number= ' Destination number ' # Enter the phone number you want to send W=0r=0while r<1:u2.write (' at+cmgf=1\r\n ') Pyb.delay (U2.any () >0): _dataread=u2.read All () print (' 1: ', _dataread) lcd_5110.lcd_write_string (' Message: ', 0,0) lcd_5110.lcd_write_string (str (M essage), 0,2) if (_dataread==b ' at+cmgf=1\r\n\r\nok\r\n '): U2.write (' at+cscs= ' GB23"\ r \ n") Pyb.delay (U2.any () >0): _dataread=u2.readall () prin T (' 2: ', _dataread) if (_dataread==b ' at+cscs= "GB2312" \r\n\r\nok\r\n '): U2.write (' at+cnmi=2, 1\r\n ') Pyb.delay (U2.any () >0): _dataread=u2.readall                            () Print (' 3: ', _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 (' 4: ', _da                                    Taread) #b ' at+cmgf=1\r\n\r\nok\r\n ' if (_dataread== B ' at+cmgs= ' ' +number+ ' "\r\n\r\n> '):                                   U2.write (message+ ' \ r \ n ') #短信内容 Pyb.delay (50) if (U2.any () >0): _dataread=u2.readall () p Rint (' 5: ', _dataread) print (len (_dataread)) W                                        =len (_dataread) _dataread=str (_dataread) [2:w]                                            Print (' 6: ', _dataread) if (_dataread==message):                                            Print (' 7:ok ') lcd_5110.lcd_write_string (' has been sent ', 0,5) r=10

  

  5. SMS Bulk mechanism for:

1. The bulk message machine is based on the above program code;

2. In the above code, we created a character variable to store the phone number, where we set up an array to hold the phone number;

3. After the phone number is fully entered;

4. Let's check the array with a few phone numbers (that is, tell the chip you want to send text messages to several mobile phones);

5. Then we call the data in this array in turn;

6. And carry out the process of sending text messages to this data;

7. And get to this is the first data in the array;

8. If the data in the array is all called once, the end of the program is sent;

6. SMS Mass Machine Routines

Below is I do the SMS mass machine routine, give out a reference.

Import pybimport upcd8544from Machine import spi,pinfrom pyb import uartfrom ubinascii import hexlifyfrom ubinascii Import *leds = [Pyb. LED (i) for I in range (1,5)]p,l,shuchu=0,0,0spi = Pyb. SPI (1) #DIN =>x8-mosi/clk=>x6-sck#din =>spi (1). 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 (' Y3 ', 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 ' #输入你想要发送的短信的内容; number=[' destination number 1 ', ' Destination number 2 ', ' Destination number 3 ' ] #输入想要发送的手机号w =0r=0e=0q=0while r<1:q=len (number) print (Q) while E<q:print (Number[e]) U2.writ E (' at+cmgf=1\r\n ') pyb.delay (() if (U2.any () >0): _dataread=u2.readall () print (' 1: ', _dataread) 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 (U2.any () >0): _dataread=u2.readall () Print (' 2: ', _dataread) if (_dataread==b ' at+cscs= "GB2312" \r\n\r\nok\r\n '): U                            2.write (' at+cnmi=2,1\r\n ') Pyb.delay (U2.any () >0): _dataread=u2.readall () Print (' 3: ', _dataread) if (_dataread                                ==b ' at+cnmi=2,1\r\n\r\nok\r\n '): U2.write (' at+cmgs= ' ' +number[e]+ ' "\ r \ n ') Pyb.delay (U2.any () >0): _dataread=                                    U2.readall () Print (' 4: ', _dataread) #b ' at+cmgf=1\r\n\r\nok\r\n ' if (_dataread== B ' at+cmgs= "' +number[e]+ '" \r\n\r\n> '): u2.write (message+ ' \ r \ n ') #短信内容                                            Pyb.delay (U2.any () >0):                                            _dataread=u2.readall () Print (' 5: ', _dataread)                                            Print (len (_dataread)) W=len (_dataread) _DATAREAD=STR (_dataread) [2:w] Print (' 6: ', _dat Aread) if (_dataread==message): P Rint (' 7:ok ') e=e+1 lcd_5110. Lcd_write_string (' OK is: ' +str (E), 0,5) Pyb.delay (24000) r=10 e=0

  


  

micropython+ Beidou +gps+gprs:tpyboardv702 SMS Function usage Instructions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.