iamgerwin/gsm-modem
Composer 安装命令:
composer require iamgerwin/gsm-modem
包简介
Laravel package for GSM modem communication - Send SMS, make calls, USSD and more
README 文档
README
A comprehensive Laravel package for GSM modem communication. Send SMS, make calls, handle USSD codes and more through AT commands. Perfect for IoT applications, SMS gateways, and telecommunication solutions.
Features
- 📱 SMS Management: Send, receive, and delete SMS messages in both TEXT and PDU modes
- 📞 Call Handling: Make calls, answer incoming calls, and hangup
- 💬 USSD Support: Send and receive USSD codes
- 📡 Network Information: Get signal strength, network operator, and modem details
- 🔐 SIM Management: Check SIM status, unlock with PIN
- ⚡ Serial Communication: Robust serial port handling with configurable parameters
- 🎯 Event System: Listen for incoming messages and calls
- 🛠️ Artisan Commands: Test connection, send SMS, and monitor modem via CLI
- 🧪 Well Tested: Comprehensive test suite included
Requirements
- PHP 8.3 or higher
- Laravel 11.0 or higher
- Access to serial/USB port for GSM modem connection
Installation
You can install the package via composer:
composer require iamgerwin/gsm-modem
Configuration
Publish the configuration file:
php artisan vendor:publish --tag="gsm-modem-config"
This will create a config/gsm-modem.php configuration file. Configure your modem connection:
return [ 'default' => env('GSM_MODEM_CONNECTION', 'default'), 'connections' => [ 'default' => [ 'port' => env('GSM_MODEM_PORT', '/dev/ttyUSB0'), 'baud_rate' => env('GSM_MODEM_BAUD_RATE', 115200), 'data_bits' => env('GSM_MODEM_DATA_BITS', 8), 'parity' => env('GSM_MODEM_PARITY', 'none'), 'stop_bits' => env('GSM_MODEM_STOP_BITS', 1), 'flow_control' => env('GSM_MODEM_FLOW_CONTROL', 'none'), ], ], 'sms_mode' => env('GSM_MODEM_SMS_MODE', 'TEXT'), // TEXT or PDU 'pin' => env('GSM_MODEM_PIN', null), 'auto_connect' => env('GSM_MODEM_AUTO_CONNECT', false), 'debug' => env('GSM_MODEM_DEBUG', false), ];
Usage
Basic Usage
use Iamgerwin\GsmModem\GsmModem; $modem = new GsmModem(); // Connect to modem $modem->open('/dev/ttyUSB0', ['baudRate' => 115200]); // Send SMS $modem->sendSms('+1234567890', 'Hello from Laravel!'); // Get inbox messages $messages = $modem->getInbox(); foreach ($messages as $message) { echo "From: {$message->sender}\n"; echo "Message: {$message->message}\n"; echo "Time: {$message->timestamp->format('Y-m-d H:i:s')}\n"; } // Get signal strength $signal = $modem->getSignalStrength(); // Returns percentage (0-100) // Make a call $modem->makeCall('+1234567890'); // Send USSD $response = $modem->sendUssd('*123#'); // Close connection $modem->close();
Using the Facade
use Iamgerwin\GsmModem\Facades\GsmModem; // Send SMS GsmModem::sendSms('+1234567890', 'Hello!'); // Get network info $network = GsmModem::getNetworkInfo(); // Returns: ['operator' => 'Vodafone', 'mode' => '4G'] // Get modem info $info = GsmModem::getModemInfo(); // Returns: ['manufacturer' => 'Huawei', 'model' => 'E3531', 'imei' => '...']
Event Listeners
$modem = new GsmModem(); // Listen for new messages $modem->on('new_message', function($message) { Log::info("New SMS from {$message->sender}: {$message->message}"); }); // Listen for incoming calls $modem->on('incoming_call', function($number) { Log::info("Incoming call from: {$number}"); });
Artisan Commands
Test your modem connection:
php artisan gsm-modem:test /dev/ttyUSB0 --baudrate=115200
Send SMS via CLI:
php artisan gsm-modem:send-sms +1234567890 "Your message here"
Monitor modem for incoming messages:
php artisan gsm-modem:monitor --interval=5
Advanced Features
PDU Mode
For broader modem compatibility, use PDU mode:
use Iamgerwin\GsmModem\Enums\SmsMode; $modem = new GsmModem(['sms_mode' => 'PDU']); $modem->setSmsMode(SmsMode::PDU); $modem->sendSms('+1234567890', 'Unicode message: 你好');
SIM Management
// Check SIM status $simInfo = $modem->getSimInfo(); if ($simInfo['status'] === 'PIN_REQUIRED') { $modem->unlockSim('1234'); } // Get own number $myNumber = $modem->getOwnNumber();
Message Management
// Delete single message $modem->deleteMessage(1); // Delete message at index 1 // Delete all messages $modem->deleteAllMessages(); // Get messages by status use Iamgerwin\GsmModem\Enums\MessageStatus; $modem->executeCommand('AT+CMGL=' . MessageStatus::UNREAD->getAtCommand());
Custom AT Commands
Execute any AT command directly:
$response = $modem->executeCommand('AT+COPS?', 10000);
Serial Port Configuration
The package supports various serial port configurations:
- Baud rates: 9600, 19200, 38400, 57600, 115200, etc.
- Data bits: 5, 6, 7, 8
- Parity: none, even, odd
- Stop bits: 1, 2
- Flow control: none, hardware, software
Supported Modems
This package works with most GSM modems that support standard AT commands, including:
- Huawei E-series (E3531, E3372, etc.)
- ZTE modems
- Sierra Wireless modems
- Simcom modules (SIM800, SIM900, etc.)
- Quectel modules
- Any Hayes AT command compatible modem
Testing
Run the test suite:
composer test
Run tests with coverage:
composer test-coverage
Troubleshooting
Common Issues
-
Permission denied on serial port
sudo chmod 666 /dev/ttyUSB0 # Or add your user to the dialout group sudo usermod -a -G dialout $USER
-
Port not found
- Check connected devices:
ls /dev/tty* - Verify modem is connected:
lsusb
- Check connected devices:
-
Commands timeout
- Increase timeout in config
- Check baud rate matches your modem
- Verify modem is powered on
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security related issues, please email iamgerwin@live.com instead of using the issue tracker.
Credits
- Gerwin
- Inspired by serialport-gsm Node.js package
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG for more information on what has changed recently.
iamgerwin/gsm-modem 适用场景与选型建议
iamgerwin/gsm-modem 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「serial」 「sms」 「laravel」 「modem」 「gsm」 「ussd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iamgerwin/gsm-modem 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iamgerwin/gsm-modem 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iamgerwin/gsm-modem 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Serial Shipping Container Code Generator
Generate serial number or random string that is very easy.
"Serial number generator for web aplication"
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-22