Raspberry pie GPRS. SMS receiver

cause

Once used the SMS cat from Siemens. The advantage is that there is an SDK development kit directly, and it can be used directly without hardware development

The disadvantage is also obvious, that is, it only supports the windows system. In addition, it works very unstable under windows. The problem of not receiving SMS will occur every few days. It is necessary to power off and restart the equipment before it has the opportunity to recover (not necessarily)

Later, I found a new product "gravity: UART A6 GSM & GPRS wireless communication module" in dfrobot. I bought it and tried it. I found it available (but I don't know how the A6 of dfrobot is different from the common sim800 series and sim900 series outside). In addition, I can write my own driver and support the operation under Linux. It is perfect

I also encountered some small pits during the period. Record it.

Demand list

-Automatic initialization of GPRS module

-Receive SMS and analyze important elements (including incoming number / time / SMS content)

-Upload the parsed SMS content to the server for saving

-Clear read SMS

-Support Linux system

-Development language: Java

Hardware list

-Raspberry pie 2nd generation B (the 3rd generation serial port is different in use and needs to be handled in another way) - gravity: UART A6 GSM & GPRS wireless communication module - USB wireless network card (optional) - two USB power adapters (important, why two? It will be explained later) - one 16GB TF card - one mobile phone card that can receive SMS (it must be a card of China Mobile or China Unicom, which is not supported by China Telecom)

wiring method

(raspberry pie 40pin pin pin diagram)

(A6 pin description)

Raspberry pie A6--------------------------------------

GPIO15    RX

GPIO16    TX

GND      GND

Important: the power supply of A6 module needs separate power supply!!!

A6 module cannot be powered directly from GPIO 5V pin on raspberry pie because of insufficient current!

At first, I took electricity from raspberry pie to supply A6. As a result, the serial port couldn't communicate. At first, I thought it was a baud rate problem. As a result, I tossed for half a day, I noticed that there is a blue light (sleep is written on it) on the A6, which changes in light and shade and is unstable. It feels like the voltage is unstable. I decisively tried to connect the A6 to the external power supply, and then the A6 works normally! It can be seen from the blue light that the brightness is high and stable (not flashing)

Data preparation

-Raspberry pie system (noobs or raspbian can be used)

-Pi4j (Java support package)

-At instruction knowledge

The installation method of raspberry pie system can be searched by yourself or read my previous articles

After the system is installed, it also involves how to enable gpio15 (TX) and gpio16 (Rx). See this article: "two raspberry pies communicate through serial port"

Pi4j is a support package that allows java to access 40 gpios of raspberry pie. You can download and install it on the official website, portal > > >

The most important and easy to fall is the at command part about receiving SMS, which will be explained in detail below

The function to be done here is to use A6 to receive short messages, involving the following instructions

*Step 1: initialize GPRS modular

*At handshake / SIM card detection * at + cpin? Check whether the SIM card * at + CSQ signal quality test is detected. A value of 0-31,31 indicates that it is best to read the SIM CCID (20 digits on the back of the SIM card) by * at + CCID. You can check whether there is a SIM card or whether it is in good contact * at + CREG? Check whether the network is registered

------The above instructions are used to initialize the module. Generally, if the wiring is OK and the baud rate setting is OK, it is relatively easy to adjust

*Step 2: initialize GPRS Set SMS mode and SMS receiving parameters

*At + cmgf = 1 0-pdu, 1-text format * at + CSDH = 1 * at + CPMS = "SM", "SM", "SM" saves the information in the SIM card, SM - indicates that it exists on the SIM card * at + CNMI = 2,1,1 receives the notification and exists in the specified location (related to at + CPMS setting)

Easy to fall pit series, explain one by one:

Set SMS format instruction: at + cmgf = 1

There are two SMS formats: 0-pdu and 1-text format

If the PDU mode is set, the SMS you receive is like this:

+CIEV: "MESSAGE",1

+CMT:,32 0891683110200005F0040BA18126601728F00000710102610272230E74747A0E4ACF416110BD3CA703

If you don't use the SMS function here, it is recommended not to use the PDU format

The advantage of PDU format is that you can send Chinese text messages!

OK, if the setting is text format, the received SMS is similar to the following:

+CIEV: "MESSAGE",1

+CMT: "test again, try Chinese too

You can directly see the SMS content, and Chinese can also be displayed (note that it can be encoded in GB2312 or GBK)

Then there is a problem. When a new message comes, it is in the above format. The content of the message can be obtained, but why can't you see who sent it (mobile phone number)? Here is the time to enter the pit:

If you can't see the mobile phone number, you can try this command:

AT+CMGL="ALL"

It can read the SMS stored on the SIM card (including the read and unread SMS, and the SMS stored when sending out). The content received after execution is about this:

+Cmgl: 2, "REC read", "106907931100", "2017 / 06 / 02,10:15:21 + 08", 160134 [Xiaomi] [Xiaomi mobile] you spent 0.75 yuan in May 2017, and the current balance is 99.05 yuan. Including: data flow fee: 0.05 yuan; Voice communication fee: 0.7 yuan; SMS / MMS fee + cmgl: 3, "2017 / 07 / 02,10:15:19 + 08", 54. Query bill http://10046.mi.com 。+ Cmgl: 4134 [Xiaomi] [Xiaomi mobile] you spent 1.32 yuan in June 2017, and the current balance is 97.88 yuan. Including: data flow fee of 1.32 yuan; Voice communication fee: 0 yuan; SMS / MMS fee 0 yuan + cmgl: 5, "106908761100", "2017 / 08 / 02,10:15:30 + 08", 54. Query bill http://10046.mi.com 。+ Cmgl: 6134 [Xiaomi] [Xiaomi mobile] you spent 0.81 yuan in July 2017, and the current balance is 97.01 yuan. Including: data flow fee: 0.81 yuan; Voice communication fee: 0 yuan; SMS / MMS fee 0 yuan at + CMGD = 2

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>