[tpyboard-micropython] five minutes to learn to use TPYBOARD-GPS to make a mass message machine

Source: Internet
Author: User


Reprint please specify: @ Xiao Wu Yi Http://www.cnblogs.com/xiaowuyi

Welcome to join the discussion group64770604first, What isTpyboard-gps

Tpyboard-gps also called Tpyboard V702 is the only Micropython Development Board in the market that supports the function of communication positioning: support Python3.0 and the above version 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. Physical such as:

second, the use ofTpyboard-gpscomplete a single SMS sending function1. Specific requirements

use Tpyboard-gps to complete the sending of a single text message

2, the required devices

TPYBOARD-GPS Development Board Piece

GSM Mobile Card One Piece

3. Principle of message sending

Mobile phone signal frequency is very high, generally around 900Mhz, by the ionospheric reflection spread, call the cell phone signal to the nearest base station, that is, mobile or connected signal tower, and then by the base station to reduce the frequency of high frequency signal, from the base station and the base station communication between, the signal is a straight line transmission, encountered high buildings will be blocked, So the towers are tall, spread to the base station near the phone, and then turn into a high-frequency signal to send to the PHONE.

The implementation of the short messaging service (sms-short message Service) 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 Said: The base station is always in the transmission signal, which is an important part of the broadcast message, the broadcast message is a kind of paging messages (including phone numbers), 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.

4. Code
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 () #使用程序把引脚Y6拉低两秒以上, start-up Letter function Pyb.delay (n1.high) pyb.delay (10000) #高Y6, delay 10 seconds, This is to ensure that the communication module normal boot U2 = UART (4, 115200) #定义串口4, The baud rate is set to 115200message= ' Tpyboard_gps ' #输入你想要发送的短信的内容; number= ' 1********** ' #输入想要发送的手机号w =0r=0while r<1:u2.write (' at +cmgf=1\r\n ') #发送AT +cmgf=1\r\n, set the module to send SMS mode pyb.delay () if (u2.any () >0): _dataread=u2.readall () prin T (' 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 (5                0) if (u2.any () >0): _dataread=u2.readall () print (' 2: ', _dataread) If (_dataread==b ' at+cscs= "GB2312" \r\n\r\nok\r\n '): #发送AT +cscs= "GB2312" \ r \ n, Format the text u2.write (' at+cnmi=2                        , 1\r\n ') #发送AT +cnmi=2,1\r\n, Set the new short interest mode Pyb.delay (() if (u2.any () >0): _dataread=u2.readall () print (' 3: ', _dataread) if (_dataread==b ' AT+CN mi=2,1\r\n\r\nok\r\n '): u2.write (' at+cmgs= "' +number+ '" \ r \ n ') #发送AT +cmgs= "' +number[e]+ '" \ r \ n, handle                                The machine number is sent in 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+ '" \r\n\r\n> '): #返回手机号码正确的提示 u2.write (message+ ' \ r \ n ') #短信 Content Pyb.delay () #发送Message + ' \ r \ n ', send the set-up content and delay the IF (u2.any () >0): _dataread=u2.readall () prin T (' 5: ', _dataread) print (len (_DATAREAD)) w=le n (_dataread) _dataread=str (_dataread) [2:w] p                                            Rint (' 6: ', _dataread) if (_dataread==message): #返回发送的文本内容及相应的发送成功的提示后, end Program Print (' 7:ok ') lcd_5110.lcd_write_string (' has been sent ', 0,5) r=10
5. Effect

Use the mobile phone number to the number corresponding to the mobile phone numbers to send text messages, the content is tpyboard_gps.

third, the production of bulk SMS machine 1, the main mechanism

(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 telephone number is fully entered;

(4) Let's find out how many telephone numbers are in this array;

(5) then we call the data in this array sequentially;

(6) and carry out the process of sending text messages to this data;

(7) 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;

2, specific code

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 () #使用程序把引脚Y6拉低两秒以上, Start communication function Pyb.delay (n1.high) pyb.delay (10000) #高Y6, delay 10 seconds, This is to ensure that the communication module normal boot U2 = UART (4, 115200) #定义串口4, The baud rate is set to 115200message= ' 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.write (' at+cmgf=1\r\n ') #发送AT +cmgf=1\ r\n, set module for SMS send mode 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 ') #发送AT +cscs= "GB2312" \r\                    n, format Text pyb.delay if (u2.any () >0): _dataread=u2.readall ()                        Print (' 2: ', _dataread) if (_dataread==b ' at+cscs= "GB2312" \r\n\r\nok\r\n '): U2.write (' at+cnmi=2,1\r\n ') #发送AT +cnmi=2,1\r\n, Set the new short interest mode 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= "' +numbe                                r[e]+ ' \ r \ n ') #发送AT +cmgs= "' +number[e]+ '" \ r \ n, Send the cell phone number in Pyb.delay (50) If (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> '): #返回手机号码正 The prompt u2.write (message+ ' \ r \ n ')
Pyb.delay #发送Message + ' \ r \ n ', send the set-up content and delay if (u2.any () >0): _dataread=u2.readall () print (' 5: ', _dataread) Print (len (_DATAREAD)) W=len (_dataread) _dataread=str (_dataread) [2:w] print (' 6: ', _dataread) if (_dataread==message): #返回发送的文本内容及相应的发送成功的提示后, end Program Print (' 7:ok ') e=e+1 lcd_5110.lcd_write_string (' OK is: ' +str (E), 0,5) pyb.de Lay (24000) r=10 e=0

3. Effect

send a text message to all the mobile numbers listed in number, with the content tpyboard_gps.

Here you can control the delay time, such as adding a random number, I will not write more, their own play it.

[tpyboard-micropython] five minutes to learn to use TPYBOARD-GPS to make a mass message machine

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.