iamgerwin / gsm-modem
Laravel package for GSM modem communication - Send SMS, make calls, USSD and more
Fund package maintenance!
:vendor_name
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.0||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^7.0||^8.0
- orchestra/testbench: ^8.0||^9.0||^10.0
- pestphp/pest: ^2.0||^3.0
- pestphp/pest-plugin-arch: ^2.0||^3.0
- pestphp/pest-plugin-laravel: ^2.0||^3.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-09-22 05:09:40 UTC
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.