In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to use the AT command to operate the SIM card to send text messages, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
Recently, he devoted himself to the software rewriting of the electricity information collection terminal of an electronics company, which is mainly responsible for writing the communication function between the terminal and the master station. This week we used the AT command to operate the SIM card to send text messages. I hope it will be helpful to children's shoes with similar needs.
Note: due to the C language source code, and I know very little about the hardware, many of the operation steps are rewritten according to the original logic (especially the initialization of the SMS module). If there are any errors, please add, delete or modify as appropriate.
1. Initialization of hardware
The hardware initialization is carried out in the existing code logic as follows: open serial port → restart SIM hardware module → send AT command to check the running status of the SIM card.
A) Open serial port
Serial port operation already has a very mature code, so I won't repeat it here.
B) restart the SIM hardware module
Definition of magic numbers used:
Static const unsigned char RESET_CTL = 0
Static const unsigned char POWER_CTL = 1
Static const unsigned char IGT_CTL = 2
Restart step
Hardware operation
TurnOffModel ()
Int fd = open ("/ dev/gprs_io", O_RDWR | O_NONBLOCK)
Ioctl (fd, 0, POWER_CTL)
Sleep (3)
:: close (fd)
StartModel ()
Int fd = open ("/ dev/gprs_io", O_RDWR | O_NONBLOCK)
Ioctl (fd, 0, IGT_CTL)
Ioctl (fd, 1, POWER_CTL)
Ioctl (fd, 1, RESET_CTL)
Usleep (500000)
Ioctl (fd, 0, RESET_CTL)
Usleep (500000)
Ioctl (fd, 1, RESET_CTL)
Sleep (2)
Ioctl (fd, 1, IGT_CTL)
Sleep (3)
Ioctl (fd, 0, IGT_CTL)
:: close (fd)
Sleep (5)
C) send the AT command to check the running status of the SIM card
Operation steps
AT command sent (C++ transfer format)
The result of the reply when the module is normal
Result meaning
Check whether the module is normal or not
"AT\ n"
AT
OK
OK indicates that the module is normal.
ERROR indicates module exception
Query the international mobile station label of mobile terminal
"AT+CIMI\ n"
AT+CIMI
460000973136668
The second line of digits is the international mobile station label of the mobile terminal.
This is used to record the operation of the system, but the result can be ignored.
Detect if SIM is registered to the network
"AT+CREG?\ n"
AT+CREG?
+ CREG: 0Pol 2
OK
All agreed that the results were correct.
+ CREG: mode,state
Mode:
0: prohibit network registration from actively providing the result code (default setting)
1: allow network registration to actively provide the result code in the format:
State:
0: not registered, and the module is not currently searching for new operators
1: registered local network
2: unregistered, terminal is searching for base station
4: registration is denied
5: registered and roaming
View signal valu
"AT+CSQ\ n"
AT+CSQ
+ CSQ: 13pr 5
OK
The first number (that is, the received signal strength) is considered available when it is greater than 6.
+ CSQ:
:
Valid value is 0-31. The higher the value, the better the signal. Below 16, the call may fail.
The signal strength of the module ranges from-75 to-125DB, and the conversion formula to the effective value is
31 × (125-| DB |) / 50
:
Channel frame error rate.
Set the format of SMS messages
"AT+CMGF=0\ n"
AT+CMGF=0
OK
0:PDU mode.
1: text mode.
2. Receive SMS messages
The steps are as follows:
Operation steps
AT command sent (C++ transfer format)
The result of the reply when the module is normal
Result meaning
Get the number of SMS messages
"AT+CPMS=\" SM\ ",\" SM\ ",\" SM\ "\ r"
+ CPMS: 4, 50, 50, 4, 50, 50, 50.
OK
Take the first two digits here:
4 indicates the number of SMS messages currently stored
50 represents the total number of SMS messages that can be stored on the SIM card.
Get SMS 1 information
"AT+CMGR=1\ r"
+ CMGR: 1 Jing Ji 38
0891683108200845F7240D91683121436587F9
0000617072917253231
474747A0E4ACF416110BD3CA783C66F72D905
Returns when an error occurs:
AT+CMGR=1
+ CMS ERROR:
Delete SMS messages
"AT+CMGD=1\ r"
OK
Return on error
AT+CMGD=1
+ CMGD ERROR:
PDU stream parsing of SMS messages:
0891683108200845F7240D91683121436587F90000617072917253231474747A0E4ACF416110BD3CA783C66F72D905
08
The number of bytes occupied by the SMS center number (including type code)
08 means that the next 8 bytes (that is, 16 hexadecimal digits) are SMS center numbers (including type codes)
ninety-one
SMS center number type
91 represents the international code
A1 means domestic code.
68 31 08 20 08 45 F7
SMS center number
The BCD code is used, and in this case the SMS center number is "8613800280547". That is, all bytes are swapped high and low. F is the filling code.
twenty-four
Basic parameters (TP-MTI/MMS/RP)
The meaning is unknown
0D
Sender phone number length (number, number of non-bytes, excluding type code)
In this case, 13 digits
ninety-one
Sender phone number type
91 represents the international code
A1 means domestic code.
68 31 21 43 65 87 F9
Sender phone number
In this example, the sender's phone number is "8613123456789" (please forgive me for modifying this stream to protect my privacy)
00
Parameters show how SMSC handles SM (such as FAX, Voice, etc.)
00 indicates a normal GSM type, point-to-point mode
00
User data (UD) coding scheme
00 is 7-bit code, 08 is UCS2 code
61 70 72 91 72 53 23
BCD coding, timestamp
This example is the 19:27:35 + 8: 00 zone on July 27th, 16.
fourteen
The actual length of the message.
This example is 20 bytes.
74 74 7A 0E 4A CF 41 61 10 BD 3C A7 83 C6 6F 72 D9 05
User data "this is a test code." The 7-bit code of.
The number of bytes of user data varies depending on the "encoding scheme".
The actual number of bytes of user data (1 byte is 2 hexadecimal digits) is calculated:
7-bit encoding: the actual length of the SMS message is * 7max 8, and add 1 if there is any remainder.
UCS2 coding: the actual length of the SMS.
Other ways (not recommended, only to ensure the robustness of the program): the data between the actual length of the text message and "/ rzone".
3. Send SMS messages
The steps are as follows
Operation steps
AT command sent (C++ transfer format)
The result of the reply when the module is normal
Result meaning
Send a text message
"AT+CMGS=33\ r"
>
Waiting for SMS PDU code to be entered
"0891683108100005F011000D91683121436587F90000AA
1474747A0E4ACF416110BD3CA783C66F72D905 "+ 0xA1
OK
Sent successfully.
Failed to return:
+ CMS ERROR::
The symbol number of 0xa1, which indicates the end of PDU stream transmission.
33 in "AT+CMGS=33\ r" indicates the number of bytes of information other than the SMS center number ("0891683108100005F0") in the PDU code sent (excluding 0xA1). In this case, the length of the stream "11000D91683121436587F90000AA1474747A0E4ACF416110BD3CA783C66F72D905" is divided by 2.
PDU stream parsing of SMS messages:
0891683108100005F011000D91683121436587F90000AA1474747A0E4ACF416110BD3CA783C66F72D905
08
The number of bytes occupied by the SMS center number (including type code)
08 means that the next 8 bytes (that is, 16 hexadecimal digits) are SMS center numbers (including type codes)
ninety-one
SMS center number type
91 represents the international code
A1 means domestic code.
68 31 08 10 00 05 F0
SMS center number
The BCD code is used, and in this case the SMS center number is "8613800100500". That is, all bytes are swapped high and low. F is the filling code.
eleven
Pdu Typ
SMS messages with 160 English characters / 70 Chinese characters, no SMS report
SMS messages with 160 English characters or less than 70 Chinese characters, with SMS report
51: long SMS messages (multiple merging), no SMS reports
71: long SMS messages (multiple merging), with SMS reports
00
Message Base value (TP-MR)
0D
Sender phone number length (number, number of non-bytes, excluding type code)
In this case, 13 digits
ninety-one
Sender phone number type
91 represents the international code
A1 means domestic code.
68 31 21 43 65 87 F9
Sender phone number
In this example, the sender's phone number is "8613123456789" (please forgive me for modifying this stream to protect my privacy)
00
Parameters show how SMSC handles SM (such as FAX, Voice, etc.)
00 indicates a normal GSM type, point-to-point mode
00
User data (UD) coding scheme
00 is 7-bit code, 08 is UCS2 code
Note: it should correspond to the actual length of SMS and user data, otherwise a 531 error will be returned.
AA
Validity of SMS messages (TP-VP)
00 means 5 minutes.
AA stands for longest
Other unknown
fourteen
The actual length of the message.
20 bytes. Corresponding to the coding scheme and user data.
74 74 7A 0E 4A CF 41 61 10 BD 3C A7 83 C6 6F 72 D9 05
User data "this is a test code." The 7-bit code of.
The number of bytes of user data varies depending on the "encoding scheme".
4. Close the module
TurnOffModel (), close the serial port.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.