-
Notifications
You must be signed in to change notification settings - Fork 72
GSMExtras Library
This library complements the Arduino GSM library by providing additional commands for controlling the Quectel M10 GSM module found on the Arduino GSM shield, DIY Cellphone, and Cellphone Module.
Classes: GSM3VolumeService, GSM3ClockService, GSM3DTMF
Set and get the volume of the speaker, as used for voice calls. To use: #include <GSM3VolumeService.h>
Set the volume, from 0 to 100.
Query the GSM module for the current volume. Use ready() to check if the module has responded and getVolume() to retrieve the current volume.
volume.checkVolume(); // query the GSM module for the current volume
while (!volume.ready()); // wait for it to respond
// if the response was successful, get the volume and print it
if (volume.ready() == 1) {
Serial.print("volume: ");
Serial.println(volume.getVolume());
}
Returns the current volume, either the last volume set with setVolume() or the last volume returned by the module through a call to checkVolume().
Check the status of the latest query of the GSM module (with checkVolume()). Returns 0 if the command is still pending, 1 on success, and greater than 1 on error.
#include <GSM.h>
#include <GSM3VolumeService.h>
GSM gsm(true);
GSMVoiceCall vcs;
GSM3VolumeService volume;
int potval;
void setup()
{
pinMode(31, INPUT_PULLUP);
pinMode(19, OUTPUT);
digitalWrite(19, LOW);
delay(12000);
digitalWrite(19, HIGH);
while (gsm.begin(0, false) != GSM_READY);
}
void loop()
{
if (vcs.getvoiceCallStatus() == RECEIVINGCALL && digitalRead(31) == LOW) { vcs.answerCall(); delay(500); }
if (vcs.getvoiceCallStatus() == TALKING && digitalRead(31) == LOW) { vcs.hangCall(); delay(500); }
// if the reading from the analog input has changed by some small amount, set the volume
if (abs(analogRead(A0) - potval) > 10) {
// analogRead() returns values from 0 to 1023, map that to 0 to 100 (the range for setVolume).
potval = analogRead(A0);
volume.setVolume(map(potval, 0, 1023, 0, 100));
}
}
Get and set the time on the GSM module. To use #include <GSM3ClockService.h>
Set the time on the GSM module.
Parameters:
- year: the current year, two digits (0 to 99)
- month: the current month (1 to 12)
- day: the day of the month (1 to 31)
- hour: the hour of the day (0 to 23)
- minute: the minute of the hour (0 to 59)
- second: the second of the minute (0 to 59)
Ask the GSM module for the current time. After calling, checkTime(), use ready() to check if the module has responded and the getXXX() functions to retrieve the current time. If you don't call checkTime(), the getXXX() functions will use the last value passed to setTime().
Use to check if the module has responded to the query initiated by checkTime(). Returns 0 if the module hasn't responded yet, 1 on a successful response, or greater than 1 on an unsuccessful one.
Returns the current year, two digits (0 to 99). (Call checkTime() first.)
Returns the current month (1 to 12). (Call checkTime() first.)
Returns the current day of the month (1 to 31). (Call checkTime() first.)
Returns the current hour of the day (0 to 59). (Call checkTime() first.)
Returns the current minute of the hour (0 to 59). (Call checkTime() first.)
Returns the current second of the minute (0 to 59). (Call checkTime() first.)
#include <GSM.h>
#include <GSM3ClockService.h>
GSM gsm(true); // Main gsm object. Pass true to the constructor to enable serial debugging output.
GSM3ClockService clock;
void setup()
{
Serial.begin(9600);
pinMode(19, OUTPUT);
digitalWrite(19, LOW);
delay(12000);
digitalWrite(19, HIGH);
while(gsm.begin(0, false) != GSM_READY);
// set the time to 10 am on January 11, 2014
clock.setTime(14, 1, 11, 10, 0, 0);
}
void loop()
{
clock.checkTime();
while (!clock.ready());
Serial.print(clock.getMonth());
Serial.print("/");
Serial.print(clock.getDay());
Serial.print("/20");
Serial.print(clock.getYear());
Serial.print(" ");
Serial.print(clock.getHour());
Serial.print(":");
if (clock.getMinute() < 10) Serial.print("0");
Serial.print(clock.getMinute());
Serial.print(":");
if (clock.getSecond() < 10) Serial.print("0");
Serial.print(clock.getSecond());
Serial.println();
delay(1000);
}