Simple A6Smslib Librairy for sending sms with an A6 module

To simplify the code from my previous post “Send SMS with an ESP8266 and an A6 GSM module“, I created a small library to send SMS and get feedback on the state.

You can find it on github : https://github.com/davidtw/a6SmsLib

An example of code :

#include "A6SmsLib.h"

const String NUMBER = "00336XXXXXXXX";
const String MESSAGE = "whoop whoop!";

const int rx = D1;
const int tx = D2;
const int resetPin = D0;

A6SmsLib a6Sms(rx, tx, resetPin);

void statusUpdate(String state, String message)
{
  Serial.println("[statusUpdate] " + state + " : " + message);
}

void smsUpdate(String state, String message)
{
    Serial.println("[smsUpdate] " + state + " : " + message);
}

void setup()
{
    Serial.begin(9600);
    a6Sms.debug();
    a6Sms.begin();
    a6Sms.setStatusCallback(statusUpdate);
    a6Sms.setSmsCallback(smsUpdate);
    a6Sms.waitUntilReady();

    a6Sms.sms(NUMBER, MESSAGE);
}

void loop()
{
    a6Sms.loop();
}

Setup

In this example, i configured the pins according to my protoboard circuit (D1 pour RX, D2 pour TX et D0 pour le redémarrer le module)

const int rx = D1;
const int tx = D2;
const int resetPin = D0;

A6SmsLib a6Sms(rx, tx, resetPin);

Activate Debug mode

Call the debug method to allow debug messages to the serial output :

a6Sms.debug();

Callbacks

  • setStatusCallback specifies the function to be called when the module’s state updates
  • setSmsCallback specifies the function to be called when an sms has been sent, or attempted.

The loop

the loop function allows the library to update it’s internal states, it should be called on each loop.

Sending

Sending an sms is done with the sms function, you just need to give a number and a message to be sent.