A modular ESP32-based SMS gateway that bridges SMS messages with MQTT communication using a SIM800L GSM module.
taratxt/
├── taratxt.ino # Main Arduino sketch
├── config.example.h # Example configuration file
├── wifi_handler.h # Wi-Fi connection management
├── gsm_handler.h # GSM/SIM800L module management
├── mqtt_handler.h # MQTT communication handling
├── sms_handler.h # SMS processing and parsing
├── README.md # This documentation
└── .gitignore # Git ignore rules
- Purpose: Central configuration file
- Contains:
- WiFi credentials
- MQTT server settings
- Device identification
- Pin definitions
- Timing constants
- Debug mode flag
- Purpose: Wi-Fi connection management
- Functions:
connectToWiFi()- Initial Wi-Fi connectionensureWiFiConnected()- Reconnection handling
- Purpose: GSM/SIM800L module management
- Functions:
initializeGSM()- Hardware initializationwaitForNetworkRegistration()- Network registration with retrysetupSMSMode()- Configure SMS text mode and storage
- Purpose: MQTT communication
- Functions:
connectToMQTT()- MQTT broker connectionmqttCallback()- Handle incoming MQTT messagespublishHeartbeat()- Send device status updatespublishStatus()- Publish SMS delivery status
- Purpose: SMS processing and management
- Functions:
checkUnreadSMS()- Query unread SMS messagesparseSMSResponse()- Parse AT command responsespublishSMStoMQTT()- Forward SMS to MQTTdeleteSMS()- Remove processed SMSescapeJsonString()- JSON string sanitization
ESP32 Pins:
- MODEM_RST: GPIO 5
- MODEM_PWKEY: GPIO 4
- MODEM_POWER_ON: GPIO 23
- MODEM_TX: GPIO 27
- MODEM_RX: GPIO 26| Direction | Topic Pattern | Purpose |
|---|---|---|
| Subscribe | outbound/[deviceKey] |
Receive SMS send commands |
| Publish | inbound/[deviceKey] |
Forward received SMS |
| Publish | status/[deviceKey] |
Device status and delivery reports |
{
"id": "msg123",
"number": "+1234567890",
"content": "Hello World!"
}{
"type": "inbound",
"from": "+9876543210",
"content": "Reply message",
"timestamp": "25/07/30,10:30:45+00",
"device": "TX67edf688995dc"
}{
"id": "msg123",
"status": "sent"
}- Each module handles specific functionality
- Easy to locate and fix issues
- Clear separation of concerns
- Modules can be reused in other projects
- Easy to swap implementations
- Individual modules can be tested separately
- Easier debugging and development
- Easy to add new features
- Simple to extend functionality
- Clean, organized code structure
- Self-documenting module names
- Reduced complexity in main file
Install these libraries in Arduino IDE:
- WiFi (ESP32 Core)
- PubSubClient by Nick O'Leary
- ArduinoJson by Benoit Blanchon
- TinyGSM by Volodymyr Shymanskyy
-
Copy
config.example.hand rename it toconfig.h. -
Update
config.hwith your:- Wi-Fi credentials
- MQTT server details
- Device key and secret
- Set
debugMode = falsefor production
-
Verify pin connections match your hardware setup
-
Upload to ESP32 and monitor serial output (if debug enabled)
- Network Issues: Check Wi-Fi credentials and GSM antenna
- MQTT Problems: Verify broker address and authentication
- SMS Issues: Ensure SIM card is inserted and has credit
- Debug Output: Enable
debugMode = truefor detailed logging
Note: The include errors shown in the IDE are normal for the development environment and won't affect compilation when all required libraries are properly installed.