A lightweight Arduino library for controlling the AiThinker A9G module, which provides GPRS, GPS, and SMS functionality. It offers two core classes:
-
A9G
Handles low-level AT commands (e.g., sending SMS, GPRS/APN setup, enabling GPS, simple MQTT commands). -
A9Gmod
A higher-level interface that simplifies MQTT usage, similar to other Arduino MQTT clients.
-
Initialization & Basic Checks
- Ensure module responsiveness (send
ATcommand). - Check device IMEI, signal quality, and SIM CCID.
- Wait for the module to report a
READYstatus.
- Ensure module responsiveness (send
-
GPRS & APN Configuration
- Attach/detach GPRS connectivity.
- Set APN parameters.
- Activate/deactivate PDP context for data usage.
-
GPS
- Enable/disable onboard GPS and AGPS.
- Fetch raw GPS NMEA sentences for parsing.
-
SMS
- Send, read, and delete SMS in text mode.
- Configure SMS storage.
-
MQTT
- Connect to MQTT brokers with optional username/password credentials.
- Publish and subscribe to topics with customizable QoS settings.
- Register callbacks to receive incoming MQTT messages.
-
Place Library
Copy the library files into a folder namedA9Gmodunder your Arduinolibrariesdirectory. -
Include in Sketch
Add an include statement for the library in your Arduino code. -
Compile & Upload
Verify that your board and port settings are correct, then compile and upload your sketch.
- Create an
A9Ginstance for sending AT commands to the A9G module. - Initialize the module by pointing to a serial interface.
- Set APN & GPRS if network connectivity is required.
- Use
A9Gmodif you want a high-level approach for MQTT. - Poll the modem in your main loop to handle events and incoming data.
Manages direct AT command communication, exposing methods to:
- Configure GPRS and APN.
- Enable/disable GPS and read GPS data.
- Send and receive SMS.
- Connect to an MQTT broker at a lower level.
Provides a simplified MQTT client interface:
- Define the broker address and port.
- Connect using client ID, username, and password if needed.
- Publish, subscribe, unsubscribe, and disconnect easily.
- Register a callback to handle incoming messages.
- SMS Example
Demonstrates how to send and read text messages. - GPS Example
Shows how to enable GPS and retrieve NMEA sentences. - MQTT Example
Illustrates connecting to a public broker and handling publish/subscribe operations.
Contributions are welcome! Feel free to open issues for bug reports or feature requests, and submit pull requests with improvements or examples.
Check the License file for in-depth idea of usage.
Author:
@MD. Touhiduzzaman Turja (Zaman Turja)
For questions, suggestions, or any help, please reach out or create an issue in the repository.