Python library for Quectel EM05 cellular module SMS operations
Project description
EM05 SMS Library
A Python library for communicating with Quectel EM05 cellular modules via AT commands, specifically designed for SMS operations.
Features
- Send SMS messages via cellular network
- List and read SMS messages
- Delete SMS messages
- Support for UCS2 encoding for international characters
- Debug logging for troubleshooting
- Factory reset functionality
Requirements
- Python 3.7+
- pyserial
- Quectel EM05 module connected via USB/serial
Installation
pip install pyserial
Quick Start
import em05
# Initialize the EM05 module
dev = em05.EM05(port='/dev/ttyUSB2', debug=True)
# List all SMS messages
messages = dev.sms_list_all()
print(f"Found {len(messages)} SMS messages")
# Send an SMS
response = dev.sms_send(phone_number='10086', text='Hello World!')
print(f"SMS sent: {response.status}")
# Delete all SMS messages
dev.sms_delete_all()
# Close the connection
dev.close()
API Reference
EM05 Class
Constructor
EM05(port='/dev/ttyUSB2', baudrate=115200, timeout=1, debug=False)
port: Serial port path (default: '/dev/ttyUSB2')baudrate: Communication speed (default: 115200)timeout: Response timeout in seconds (default: 1)debug: Enable debug logging (default: False)
Methods
SMS Operations
-
sms_list_all()→List[SMSMessage]- Returns all SMS messages from the module
- Each message includes: store_index, status, sender, timestamp, text
-
sms_send(phone_number: str, text: str)→EM05Resp- Sends an SMS message
- Supports international characters via UCS2 encoding
-
sms_delete_all()→EM05Resp- Deletes all SMS messages from storage
AT Commands
-
at_write(command: str, params: list)→EM05Resp- Execute AT command with parameters
-
at_read(command: str)→EM05Resp- Query AT command value
-
at_exe(command: str)→EM05Resp- Execute AT command without parameters
Utility
-
info()→EM05Resp- Get module information
-
reset()→List[EM05Resp]- Reset module to factory defaults
-
close()- Close serial connection
Data Classes
SMSMessage
@dataclass
class SMSMessage:
store_index: int # Message index in storage
status: str # Message status (e.g., "REC UNREAD")
sender: str # Sender phone number
timestamp: datetime # Message timestamp with timezone
text: str # Message content
EM05Resp
@dataclass
class EM05Resp:
status: str # Response status ("OK", "ERROR", or "")
raw: str # Raw response from module
lines: list[str] # Parsed response lines
AT Commands Reference
This library uses standard AT commands for SMS operations:
AT+CMGF=1- Set SMS text modeAT+CSCS="UCS2"- Set character set to UCS2AT+CMGL="ALL"- List all SMS messagesAT+CMGS- Send SMS messageAT+CMGD- Delete SMS messages
For detailed AT command documentation, refer to the Quectel EM05 AT Commands Manual.
Configuration
The module automatically configures itself on initialization:
- Sets factory defaults (
AT&F) - Enables text mode (
AT+CMGF=1) - Disables echo (
ATE0) - Sets UCS2 character encoding (
AT+CSCS="UCS2")
Error Handling
The library includes comprehensive error handling:
- Serial communication timeouts
- UCS2 encoding/decoding errors
- AT command response parsing
- Debug logging for troubleshooting
Example Usage
See main.py for a complete example of listing and sending SMS messages.
License
This project is open source. Please refer to the license file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file em05-0.1.0.tar.gz.
File metadata
- Download URL: em05-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5eb6df9e7bbbcaaefb4864b1686b9d5c1975fb467331e62678879064f513296
|
|
| MD5 |
dd40dbd82dfcc272e9c1fbe103f0234c
|
|
| BLAKE2b-256 |
45c9a8088f7e0b3287a145792ed055822c05fb0a70fbde6ecf4c25752c24326f
|
File details
Details for the file em05-0.1.0-py3-none-any.whl.
File metadata
- Download URL: em05-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97f7d87e72c343cf3e76868ccda6872f4d16a3e2ac07061b986dae6d2aa2d71d
|
|
| MD5 |
7d91b4028695744e97f9473eb5b63a57
|
|
| BLAKE2b-256 |
d2a16d5046bfd5ea9874a47f4ff8116c1416169a47d828b15249495cd417f6cb
|