-
Notifications
You must be signed in to change notification settings - Fork 215
Library Functions
Here I'll attempt to concisely describe all available Arduino functions provided by the library, categorized by function.
Some notes:
- The reason everything is still named "FONA" is because this library is based on Adafruit's FONA library and it makes everything easier for users of Adafruit's library to transition to this one without any issues.
- All the functions below can be modified in the Adafruit_FONA.cpp and Adafruit_FONA.h library files. The example snippets of code below may or may not be fully functional to be directly compiled and are only for reference. Relevant parts of code may need to be included and should be inferred from the example and comments provided.
- A function is assumed to work across all supported SIMCom modules unless otherwise specified.
- fona.begin()
- fona.setBaudrate()
- Stream functions: available(), write(), read(), peek(), flush()
- fona.type()
- fona.getIMEI()
- fona.setFunctionality()
- fona.setNetworkSettings()
- fona.setPreferredMode()
- fona.setPreferredLTEMode()
- fona.openWirelessConnection()
- fona.wirelessConnStatus()
- fona.setOperatingBand()
- fona.enableSleepMode()
- fona.set_eDRX()
- fona.enablePSM()
- fona.setNetLED()
- fona.enableRTC()
- fona.readRTC()
- fona.enableNTPTimeSync()
- fona.getTime()
- fona.powerDown()
- fona.getADCVoltage()
- fona.getBattPercent()
- fona.getBattVoltage()
- fona.unlockSIM()
- fona.getSIMCCID()
- fona.getNetworkStatus()
- fona.getRSSI()
- fona.getNetworkInfo()
- fona.setSMSInterrupt()
- fona.getSMSInterrupt()
- fona.getNumSMS()
- fona.readSMS()
- fona.sendSMS()
- fona.deleteSMS()
- fona.getSMSSender()
- fona.sendUSSD()
- fona.setAudio()
- fona.setVolume()
- fona.getVolume()
- fona.playToolkitTone()
- fona.setMicVolume()
- fona.playDTMF()
- fona.tuneFMradio()
- fona.FMradio()
- setFMVolume()
- fona.getFMVolume()
- fona.getFMSignalLevel()
- fona.enableGPRS()
- fona.GPRSstate()
- fona.getGSMLoc()
- fona.postData()
- fona.enableGPS()
- fona.GPSstatus()
- fona.getGPS()
- fona.enableGPSNMEA()
- fona.TCPconnect()
- fona.TCPclose()
- fona.TCPconnected()
- fona.TCPsend()
- fona.TCPavailable()
- fona.TCPread()
- fona.MQTTconnect()
- fona.MQTTdisconnect()
- fona.MQTTpublish()
- fona.MQTTsubscribe()
- fona.MQTTunsubscribe()
- fona.MQTTreceive()
- fona.FTP_Connect()
- fona.FTP_Quit()
- fona.FTP_Rename()
- fona.FTP_Delete()
- fona.FTP_MDTM()
- fona.FTP_GET()
- fona.FTP_PUT()
- fona.HTTP_init()
- fona.HTTP_term()
- fona.HTTP_para_start()
- fona.HTTP_para_end()
- fona.HTTP_para()
- fona.HTTP_data()
- fona.HTTP_action()
- fona.HTTP_readall()
- fona.HTTP_ssl()
- fona.HTTP_GET_start()
- fona.HTTP_GET_end()
- fona.HTTP_POST_start()
- fona.HTTP_POST_end()
- fona.setUserAgent()
- fona.setHTTPSRedirect()
- fona.setPWM()
- fona.callPhone()
- fona.getCallStatus()
- fona.hangUp()
- fona.pickUp()
- fona.callerIdNotification()
- fona.incomingCallNumber()
- fona.expectReply()
- fona.sendCheckReply()
This function begins serial (UART) communication with the module and works for all SIMCom modules. You must set up the serial context with the correct baud rate before using this command, whether software or hardware serial.
fona.begin(port)
port: This can either be a software serial or hardware serial port which is used for UART communication with the modem.
- True if initialization was successful
- False if initialization failed (timed out)
#include "Adafruit_FONA.h" // https://github.com/botletics/SIM7000-LTE-Shield/tree/master/Code
#include <SoftwareSerial.h>
#define FONA_TX 10 // Microcontroller RX, module TX
#define FONA_RX 11 // Microcontroller TX, module RX
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA_LTE fona = Adafruit_FONA_LTE(); // Instantiate FONA LTE class
void setup() {
fonaSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
fonaSS.println("AT+IPR=9600"); // Manually set baud rate regardless of whether or not modem is actually on 115200
delay(100); // Short pause to let the command run
fonaSS.begin(9600);
if (! fona.begin(fonaSS)) {
Serial.println(F("Couldn't find FONA"));
while (1); // Don't proceed if it couldn't find the device
}
}
void loop() {}
This switches the baud rate for communication with the modem over UART.
fona.setBaudrate(baud)
baud: The desired baud rate that you want the module to switch to. For example, 4800, 9600, 115200, etc. Please note that you must be on the correct baud rate to begin with in order to communicate with the module, otherwise sending this command won't do you any good! For example, if your module is currently on 115200 baud and you want to switch to 9600, you must first start UART communication at 115200 before you can use fona.setBaudRate(9600) to switch to 9600 baud.
NOTE: Software serial is not reliable on 115200 baud and therefore the example code changes it to a lower value. 9600 works well in almost all applications, but 115200 works great with hardware serial.
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
#include "Adafruit_FONA.h" // https://github.com/botletics/SIM7000-LTE-Shield/tree/master/Code
#include <SoftwareSerial.h>
#define FONA_TX 10 // Microcontroller RX, module TX
#define FONA_RX 11 // Microcontroller TX, module RX
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA_LTE fona = Adafruit_FONA_LTE();
void setup() {
fonaSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
fonaSS.println("AT+IPR=9600"); // Manually set baud rate regardless of whether or not modem is actually on 115200
delay(100); // Short pause to let the command run
fonaSS.begin(9600);
if (! fona.begin(fonaSS)) {
Serial.println(F("Couldn't find FONA"));
while (1); // Don't proceed if it couldn't find the device
}
Serial.println(F("Switching to 4800 baud"));
fona.setBaudrate(4800); // Must already have been able to communicate with modem before this!
}
void loop() {}
These functions pass the UART communication stream for the commands available(), write(), read(), peek(), and flush().
- fona.available()
- fona.write(uint8_t x)
- fona.read()
- fona.peek()
- fona.flush()
None. See Arduino stream documentation for more info.
Nothing
void loop() {
// Read and print out anything coming from the modem
Serial.print(F("FONA> "));
while (! Serial.available() ) {
if (fona.available()) {
Serial.write(fona.read());
}
}
// Read and print user command from serial monitor
// and perform an appropriate action depending on what it is
char command = Serial.read();
Serial.println(command);
// Check for the command
switch (command) {
case 'a': {
// Do something here
}
case 'b': {
// Do something else
}
}
}
Returns the modem type.
fona.type()
none
The type of the SIMCom modem, one of the following: SIM800L, SIM800H, SIM808_V1, SIM808_V2, SIM5320A, SIM5320E, SIM7000A, SIM7000C, SIM7000E, SIM7000G, SIM7500A, SIM7500E.
uint8_t type;
type = fona.type();
Serial.println(F("FONA is OK"));
Serial.print(F("Found "));
switch (type) {
case SIM800L:
Serial.println(F("SIM800L")); break;
case SIM800H:
Serial.println(F("SIM800H")); break;
case SIM808_V1:
Serial.println(F("SIM808 (v1)")); break;
case SIM808_V2:
Serial.println(F("SIM808 (v2)")); break;
case SIM5320A:
Serial.println(F("SIM5320A (American)")); break;
case SIM5320E:
Serial.println(F("SIM5320E (European)")); break;
case SIM7000A:
Serial.println(F("SIM7000A (American)")); break;
case SIM7000C:
Serial.println(F("SIM7000C (Chinese)")); break;
case SIM7000E:
Serial.println(F("SIM7000E (European)")); break;
case SIM7000G:
Serial.println(F("SIM7000G (Global)")); break;
case SIM7500A:
Serial.println(F("SIM7500A (American)")); break;
case SIM7500E:
Serial.println(F("SIM7500E (European)")); break;
default:
Serial.println(F("???")); break;
}
Reads the IMEI number length and stores the actual IMEI number to the supplied buffer. The IMEI number is a globally-unique, manufacturer-assigned ID and which can also be found printed on the sticker label of the modem. This is very useful for obtaining unique IDs for posting data in which multiple devices are involved, without having to generate and store IDs on your own.
fona.getIMEI(imei)
imei: Character array buffer for storing the IMEI number
- uint8_t: IMEI number length
char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
// Print module IMEI number
uint8_t imeiLen = fona.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("Module IMEI: "); Serial.println(imei);
}
// Can then use IMEI as device ID!
Sets the functionality mode of the module using the AT+CFUN command.
fona.setFunctionality(option)
option: Can choose from the list below:
- 0 - Minimum functionality
- 1 - Full functionality
- 4 - Disable RF
- 5 - Factory test mode
- 6 - Restarts module
- 7 - Offline mode
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
// Set modem to full functionality
fona.setFunctionality(1); // AT+CFUN=1
// Software restart module
fona.setFunctionality(6); // AT+CFUN=6
This function sets the cellular network's APN and username/password (if applicable) so that the modem can connect to the network. This is usually required to gain access to the network and these credentials are typically specific to the SIM card and type of network you're using.
fona.setNetworkSettings(APN, username, password)
- APN: The APN from the cellular provider
- username: The username, if applicable
- password: The password, if applicable
- True if parameters were saved successfully
- False if parameters were not saved successfully
// Configure an APN, username, and password.
// You might need to do this to access your network's GPRS/data
// network. Contact your provider for the exact APN, username,
// and password values. Username and password are optional and
// can be removed, but APN is required.
// fona.setNetworkSettings(F("your APN"), F("your username"), F("your password"));
// Examples (only use one of course!):
fona.setNetworkSettings(F("m2m.com.attz")); // For AT&T IoT SIM card
fona.setNetworkSettings(F("telstra.internet")); // For Telstra (Australia) SIM card - CAT-M1 (Band 28)
fona.setNetworkSettings(F("hologram")); // For Hologram SIM card
Sets the preferred mode of operation (connection type) using the AT+CNMP command.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
fona.setPreferredMode(mode)
mode: An integer that corresponds to the desired mode. Below are the acceptable inputs:
- 2 - Automatic
- 13 - GSM only
- 38 - LTE only
- 51 - GSM and LTE only
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setPreferredMode(38); // Use LTE only, not 2G
Sets the preferred mode of operation between LTE CAT-M and NB-IoT using the AT+CMNB command.
Note: This only works for the SIM7000 modem.
fona.setPreferredLTEMode(mode)
mode: An integer that corresponds to the desired mode. Below are the acceptable inputs:
- 1 - CAT-M
- 2 - NB-IoT
- 3 - CAT-M and NB-IoT
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT
Opens or closes the wireless connection using the AT+CNACT command. Set the APN with the setNetworkSettings() function before calling this function so that it will use the correct APN when called.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
fona.openWirelessConnection(onoff)
onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.openWirelessConnection(true); // Enable connection
Checks the wireless connection status using the AT+CNACT? command.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
fona.wirelessConnStatus()
None
- True if the device is connected (AT command responds with "+CNACT: 1")
- False if the command errors or times out, or if device is not connected ("+CNACT: 0")
bool isConnected = fona.wirelessConnStatus();
if (isConnected) Serial.println("Device is connected!");
Sets the LTE CAT-M or NB-IoT band to operate on using the AT+CBANDCFG command.
Note: Only works on the SIM7000 modem.
fona.setOperatingBand(mode, band)
- mode: A string, either "CAT-M" or "NB-IOT"
- band: An integer corresponding to the EUTRAN band number.
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
// Force the SIM7000 to use AT&T LTE CAT-M only
fona.setOperatingBand("CAT-M", 12); // AT&T uses band 12
// Force the SIM7000 to use Verizon LTE CAT-M only
fona.setOperatingBand("CAT-M", 13); // Verizon uses band 13
Enables or disables UART sleep mode using the AT+CSCLK command. Note that this command will not actually perform the sleep operation but is necessary for sleep to be enabled later. USB must be disconnected before sleep will take effect.
fona.enableSleepMode(onoff)
onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.enableSleepMode(true);
Sets the extended-DRX parameters using the AT+CEDRXS command. E-DRX mode significantly reduces power consumption by cutting down the sampling rate while still remaining connected to the network. Note that whatever e-DRX value you set there will be a delay time for receiving incoming messages (like SMS).
Note: Only works on SIM7000 modem.
fona.set_eDRX(mode, connType, eDRX_val)
-
mode: An integer, one of the following options:
- 0 - Disable the use of eDRX
- 1 - Enable the use of eDRX
- 2 - Enable the use of eDRX and auto report
- 3 - Disable the use of eDRX(Reserved)
-
connType: An integer, either of the following options:
- 4 - CAT-M
- 5 - NB-IoT
-
eDRX_val: A string of the requested eDRX value in 4-bit format ("0000"-"1111"). The eDRX value selects the "sampling rate" from the options below:
- 0 - 5.12s
- 1 - 10.24s
- 2 - 20.48s
- 3 - 40.96s
- 4 - 61.44s
- 5 - 81.92s
- 6 - 102.40s
- 7 - 122.88s
- 8 - 143.36s
- 9 - 163.84s
- 10 - 327.68s
- 11 - 655.36s
- 12 - 1310.72s
- 13 - 2621.44s
- 14 - 5242.88s
- 15 - 10485.76s
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.set_eDRX(1, 4, "0010"); // Enable eDRX on CAT-M with 20.48s sampling rate
Enables or disables power saving mode (PSM) using the AT+CPSMS command. PSM drastically reduces the power consumption while remaining connected to the network and can even wake up a host microcontroller from the ring indicator (RI) pin when incoming SMS messages are received (in theory, see below).
Note: This sounds good on paper but has yet to be confirmed on the SIM7000 in real life. Moreover, the fona.enableSleepMode(true) command must be used before this will work and USB port must be disconnected.
fona.enablePSM(onoff)
onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.enableSleepMode(true);
fona.enablePSM(true);
Sets the function of the network status LED (for the Botletics SIM7000 shield it's the blue LED labeled "NET").
Note: Only works on the SIM7000 modem.
fona.setNetLED(onoff, mode, timer_on, timer_off)
- onoff: True or false (enable or disable)
-
mode: Integer, one of the following options:
- 1 - Set the timer period of the net light when the modem is not registered to the network
- 2 - Set the timer period of the net light when the modem has already connected to the network
- 3 - Set the timer period of the net light when the modem is in PPP communication (data enabled basically)
- timer_on: Timer period of "LED ON" in decimal format which range is 0 or 40-65535(ms)
- timer_off: Timer period of "LED OFF" in decimal format which range is 0 or 40-65535(ms)
Default settings for ,<timer_on>,<timer_off> are the following:
- 1,64,800
- 2,64,3000
- 3,64,300
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
// Set the LED to periodically blink 64ms on and 3s off when connected to a network
fona.setNetLED(true, 2, 64, 3000); // on/off, mode, timer_on, timer_off
// We could also disable the LED altogether
fona.setNetLED(false); // Disable network status LED
Enable UTC network time sync and local time stamp with the AT+CLTS command.
fona.enableRTC(onoff)
onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.enableRTC(true);
Read and parse the current time.
fona.readRTC(&year, &month, &day, &hour, &minute, &second)
- year: uint8_t integer for storing the two-digit year (not four digits like 2018)
- month: uint8_t integer for storing the month
- day: uint8_t integer for storing the day
- hour: uint8_t integer for storing the hour
- minute: uint8_t integer for storing the minute
- second: uint8_t integer for storing the second
- True if the AT command ran successfully and time was parsed
- False if the AT command produced an error or timed out
uint8_t year, month, day, hour, minute, second;
fona.readRTC(&year, &month, &day, &hour, &minute, &second); // Parse the time
// Can also print out to serial for sanity check
Serial.print(F("Year: ")); Serial.println(year);
Serial.print(F("Month: ")); Serial.println(month);
Serial.print(F("Day: ")); Serial.println(day);
Serial.print(F("Hour: ")); Serial.println(hour);
Serial.print(F("Minute: ")); Serial.println(minute);
Serial.print(F("Second: ")); Serial.println(second);
Manage time syncing with an NTP server.
fona.enableNTPTimeSync(onoff, ntpserver)
- onoff: True or false (enable or disable)
- ntpserver: Flash string of the NTP server, F("pool.ntp.org") by default
- True if successful
- False if unsuccessful
// Enable NTP time sync
if (!fona.enableNTPTimeSync(true, F("pool.ntp.org")))
Serial.println(F("Failed to enable"));
break;
Get the current local time and store it in a buffer.
fona.getTime(buffer, maxlen)
- buffer: Char buffer for storing the time
- maxlen: Max length to read from the time
- True if reply/parsing was successful
- False if the AT command produced an error or timed out
// Read the time
char buffer[23];
fona.getTime(buffer, 23); // Make sure replybuffer is at least 23 bytes!
Serial.print(F("Time = ")); Serial.println(buffer);
Shut down the modem via software (lowest power consumption state). The module will no longer be able to do anything and will not wake up unless powered back on from the PWRKEY pin.
fona.powerDown()
None
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.powerDown(); // Shut off the module
Read the voltage of the modem's ADC pin. Note: Please be aware of the maximum allowable voltage on this pin as specified in the hardware design manual of the modem.
fona.getADCVoltage(&voltage)
- voltage: uint16_t for storing the voltage value in mV
- True if the voltage was read successfully
- False if the command produced an error or timed out
uint16_t adc;
if (! fona.getADCVoltage(&adc)) {
Serial.println(F("Failed to read ADC"));
}
else {
Serial.print(F("ADC = ")); Serial.print(adc); Serial.println(F(" mV"));
}
Returns the battery percentage of the 3.7V LiPo battery powering the modem.
fona.getBattPercent(&percent)
- percent: uint16_t for storing the battery percentage
- True if the percentage was read successfully
- False if the command produced an error or timed out
if (! fona.getBattPercent(&vbat)) {
Serial.println(F("Failed to read Batt"));
}
else {
Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%"));
}
Returns the supply voltage of the modem (which is the battery voltage if the modem is being powered by a battery).
fona.getBattVoltage(&voltage)
- voltage: uint16_t for storing the battery voltage
- True if the percentage was read successfully
- False if the command produced an error or timed out
if (! fona.getBattVoltage(&vbat)) {
Serial.println(F("Failed to read Batt"));
}
else {
Serial.print(F("VBat = ")); Serial.print(vbat); Serial.println(F(" mV"));
}
Unlock SIM card with PIN.
fona.unlockSIM(pin)
- pin: SIM card pin code
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
char PIN[5] = "1234"; // SIM card PIN
if (!fona.unlockSIM(PIN)) {
Serial.println(F("Failed to unlock SIM card"));
}
Get the SIM card's CCID number. This number is usually printed on the SIM card or the holder it came in.
fona.getSIMCCID(buffer)
- buffer: Buffer to hold the CCID
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
char buffer[21];
fona.getSIMCCID(buffer); // Make sure the buffer is at least 21 bytes!
Serial.print(F("SIM CCID = ")); Serial.println(buffer);
Gets the network registration status of the modem.
fona.getNetworkStatus()
None
uint8_t network status number
// Read the network/cellular status
uint8_t n = fona.getNetworkStatus();
Serial.print(F("Network status "));
Serial.print(n);
Serial.print(F(": "));
if (n == 0) Serial.println(F("Not registered"));
if (n == 1) Serial.println(F("Registered (home)"));
if (n == 2) Serial.println(F("Not registered (searching)"));
if (n == 3) Serial.println(F("Denied"));
if (n == 4) Serial.println(F("Unknown"));
if (n == 5) Serial.println(F("Registered roaming"));
Get the network connection signal strength.
fona.getRSSI()
None
uint8_t RSSI value
// Read the raw RSSI value
uint8_t n = fona.getRSSI();
int8_t r;
Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": ");
// Convert raw RSSI to dBm
if (n == 0) r = -115;
if (n == 1) r = -111;
if (n == 31) r = -52;
if ((n >= 2) && (n <= 30)) {
r = map(n, 2, 30, -110, -54);
}
Serial.print(r); Serial.println(F(" dBm"));
Get the network name, connection type, band, and other related information using AT+COPS? and AT+CPSI? commands.
fona.getNetworkInfo()
None
- True if successful
- False if unsuccessful
fona.getNetworkInfo();
Disable or enable the interrupt functionality to be triggered by incoming SMS and/or other things. This feature can be used to trigger the ring indicator (RI) pin to do things like wake up or alert the microcontroller when a certain even occurs.
fona.setSMSInterrupt(option)
-
option: Pick from the options below:
- 0 - Off
- 1 - On (TCPIP, FTP and URC control RI pin)
- 2 - On (only TCPIP control RI pin)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setSMSInterrupt(1); // Enable interrupt to be triggered by TCPIP, FTP and URC
Get the interrupt functionality option as described in the previous function.
fona.getSMSInterrupt()
None
uint8_t option number as described in the previous function.
uint8_t option = fona.getSMSInterrupt();
Get the number of stored SMS messages.
fona.getNumSMS()
None
int8_t number of SMS. Returns -1 if there was an error.
int8_t sms_num = fona.getNumSMS();
Read a stored SMS message based on its index.
fona.readSMS(sms_num, buffer, maxlen, &smslen)
- sms_num: uint8_t index of the SMS you want to read, starting from 0
- buffer: Character buffer to hold the contents of the SMS
- maxlen: uint16_t max length you want to read out from the SMS
- smslen: uint16_t length of the SMS message
- True if successful
- False if unsuccessful
uint8_t sms_num = 2;
char SMS_content[255];
uint16_t maxlen = 200; // Maybe we only want to read a max of 200
uint16_t smslen = 0;
if (!fona.readSMS(sms_num, SMS_content, maxlen, &smslen)) {
Serial.println(F("Failed to read SMS!"));
}
Send a text message (SMS) to a phone number.
fona.sendSMS(phoneNum, message)
- phoneNum: Char array with phone number with country code (only numbers, no "+" symbol or anything else!)
- message: Char array with SMS message content
- True if successful
- False if unsuccessful
const char * phone_number = "12223334567"; // Include country code, only numbers
const char * text_message = "All ur base ar belong 2 us!";
if (!fona.sendSMS(phoneNum, textMessage)) {
Serial.println(F("Failed to send"));
}
else {
Serial.println(F("Sent!"));
}
Delete a stored SMS based on its index.
fona.deleteSMS(index)
- index: The index of the stored SMS.
- True if deleted successfully
- False if otherwise
uint8_t sms_idx = 1;
if (fona.deleteSMS(sms_idx)) {
Serial.println(F("Deleted!"));
}
else {
Serial.println(F("Couldn't delete"));
}
Retrieve the sender of a specified SMS message and copy it as a string to the buffer.
fona.getSMSSender(sms_idx, sender, sender_len)
- sms_idx: uint8_t index of the SMS (SMS "slot")
- sender: char buffer holding the sender's info
- sender_len: int max number of characters to copy into the "sender" buffer
- True if successful
- False if no SMS was found in the slot specified by the SMS index
// Retrieve the SMS sender's phone number
uint8_t sms_idx = 3;
char senderBuff[16];
uint8_t maxlen = 30;
if (! fona.getSMSSender(sms_idx, senderBuff, maxlen)) {
Serial.println("Didn't find SMS message in the slot!");
}
Serial.print(F("FROM: ")); Serial.println(senderBuff);
Send a USSD message.
fona.sendUSSD(message, replybuffer, maxlen, &ussdlen)
- message: char array of the USSD message
- replybuffer: char buffer to hold the message reply
- maxlen: uint16_t max length of the reply that you want to read out
- ussdlen: uint16_t length of the reply message
- True if successful
- False if unsuccessful
uint16_t ussdlen;
const char * message = "All ur base ar belong 2 us!";
char replybuffer[255];
if (!fona.sendUSSD(message, replybuffer, 250, &ussdlen)) {
Serial.println(F("Failed"));
}
else {
Serial.println(F("Sent!"));
Serial.print(F("***** USSD Reply"));
Serial.print(" ("); Serial.print(ussdlen); Serial.println(F(") bytes *****"));
Serial.println(replybuffer);
Serial.println(F("*****"));
}
Set audio to headset or speaker phone (external). Works on voice-enabled modules only.
fona.setAudio(option)
-
option: One of the following options:
- 0 - Headset
- 1 - Speaker phone (external audio)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setAudio(1); // Set to speaker phone for SIM800
// OR, for different module:
fona.setAudio(3); // Set to speaker phone for SIM7500
Set the speaker volume. Works on voice-enabled modules only.
fona.setVolume(level)
-
level: uint8_t volume level (depends on the module):
- For SIM800 volume level ranges from 0-100 (softest-loudest)
- For SIM5320 volume level ranges from 0-8 (softest-loudest)
- For SIM7500 volume level ranges from 0-5 (softest-loudest) with 4 being the default
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setVolume(80); // Set volume to 80% on SIM800
// OR on a different module:
fona.setVolume(5); // Max out volume for SIM7500
Set the speaker volume. Works on voice-enabled modules only.
fona.getVolume()
None
uint8_t volume level as described in the previous function.
uint8_t volume = fona.getVolume();
Play toolkit tone (pre-defined tones unique to each module). Works on 2G and 3G voice-enabled modules only.
fona.playToolkitTone(tone, length)
- tone: See the corresponding AT command manual for a full list of the supported tones
-
length: uint16_t desired duration of the tone in milliseconds. The ranges differ between modules:
- SIM800: 10-15300000ms
- SIM5320: Up to 2^16 - 1 (uint16_t)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.playToolkitTone(8, 5000); // Play ringing tone for SIM800 for 5s
Set the microphone gain. Works on 2G voice-enabled modules only.
fona.setMicVolume(channel, level)
-
channel: One of the following integers corresponding to the audio channel:
- 0 - Main audio channel
- 1 - Aux audio channel
- 2 - Main audio channel hands free mode
- 3 - Aux audio channel hands free mode
- level: The gain level, from 0-15 for SIM800. Check AT command manual for full list of corresponding gain levels in decibels (dB).
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setMicVolume(1, 10); // Use aux audio channel and set mic gain to +15.0dB
Set the microphone gain. Works on 2G voice-enabled modules only.
fona.playDTMF(tone)
- tone: char tone to play (the "note" basically). It can be 0-9, A, B, C, D, E, F, *, or #
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.playDTMF('B'); // Play the note 'B'
Set the FM radio frequency.
fona.tuneFMradio(station)
- station: uint16_t ranging from 875-1080 (87.5MHz - 108.0MHz)
- True if the AT command ran successfully
- False if the station is outside the acceptable range or if AT command produced an error or timed out
fona.tuneFMradio(901); // Listen to WABE Atlanta (NPR's station)
Open or close FM radio.
fona.FMradio(onoff, channel)
- onoff: True or false (enable or disable)
- channel: Either 0 (main audio channel) or 1 (aux audio channel), 0 by default
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.FMradio(true, 1); // Enable FM radio on external headset
Set the FM radio volume.
fona.setFMVolume(volume)
- volume: Volume level, 0-6
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.setFMVolume(6); // Set the FM radio to max volume
Get the current FM radio volume.
fona.getFMVolume(volume)
None
int8_t FM volume as described in the previous function. Returns 0 if there was an error.
int8_t FM_vol = fona.getFMVolume();
Get the signal level of an FM station.
fona.getFMSignalLevel(station)
- station: uint16_t station frequency ranging from 875-1080 (87.5MHz - 108.0MHz)
int8_t signal level. Returns -1 if unsuccessful.
int8_t signal_level = getFMSignalLevel(901); // Get signal level of WABE Atlanta
Enable cellular data (2G, 3G, or 4G LTE depending on what module you're using).
fona.enableGPRS(onoff)
- onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
if (!fona.enableGPRS(true)) {
Serial.println(F("Failed to enable data"));
}
Read the current GPRS state (enabled or disabled) with the AT+CGATT? function.
fona.GPRSstate()
None
int8_t state. Returns -1 if there is an error.
int8_t state = fona.GPRSstate();
Get the GSM location based on cell tower triangulation. The first version of the function reads out the reply and the second one parses the reply for latitude and longitude.
Note: Only works on 2G and requires GPRS (data) to be enabled first.
- fona.getGSMLoc(&replycode, buff, maxlen)
- fona.getGSMLoc(&lat, &long)
- replycode: uint16_t to store the reply code
- buff: char buffer to store the GSM location response
- maxlen: unt16_t max length to read from the response
- lat: float for holding the latitude
- long: float for holding the longitude
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
// Enable GPRS first
fona.enableGPRS(true);
// Get GSM location
uint16_t returncode;
char replybuffer[255];
if (!fona.getGSMLoc(&returncode, replybuffer, 250))
Serial.println(F("Failed!"));
if (returncode == 0) {
Serial.println(replybuffer);
}
else {
Serial.print(F("Fail code #")); Serial.println(returncode);
}
// Can also get lat/long directly
float latitude, longitude;
if (! fona.getGSMLoc(&latitude, &longitude) {
Serial.println(F("Failed!"));
}
else {
Serial.print(F("Lat: ")); Serial.println(latitude, 6); // Print 6 decimal places
Serial.print(F("Long: ")); Serial.println(longitude, 6);
}
Post data via HTTP or HTTPS (depending on the module) GET or POST requests. The first method is for 2G and SIM7000 modules, whereas the second is for SIM5320 and SIM7500 (3G and 4G) modules.
- fona.postData(request_type, URL, body, token, bodylen)
- fona.postData(server, port, connType, URL, body)
For the first function usage (2G/SIM7000 modules):
- request_type: char array containing the type of request, either "GET", "POST", or "HEAD"
- URL: char array containing the URL for the GET or POST request. Ex: "dweet.io/dweet/for/myDevice123?temp=75.4"
- body: optional char array containing the JSON body of the POST request if applicable
- token: optional char array containing the HTTP basic authentication token
- bodylen: optional uint32_t length of the JSON body. Particularly useful if the body length is very long or passed to the function as a pointer (for example, posting an image)
For the second usage (SIM5320/SIM7500 modules):
- server: char array containing the server IP address or URL. Ex: "www.dweet.io" or "www.google.com"
- port: char array containing the connection port
- connType: char array containing the
- URL: char array containing the URL for the GET or POST request without the server address. Ex: "GET /dweet/for/myDevice123?temp=75.4"
- body: optional char array containing the JSON body of the POST request if applicable
- True if the server responds with an HTTP code of 200
- False if any AT command produced an error or if the HTTP code was not 200
Please see the "2" and "3" commands in the [LTE_Demo sketch](https://github.com/botletics/SIM7000-LTE-Shield/blob/master/Code/examples/LTE_Demo/LTE_Demo.ino) and the [IoT_Example sketch](https://github.com/botletics/SIM7000-LTE-Shield/blob/master/Code/examples/IoT_Example/IoT_Example.ino) for example usage of this function.
Enable or disable GPS. Only works on modules with GPS (SIM808, SIM5320, SIM7000, SIM7500).
fona.enableGPS(onoff)
- onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
fona.enableGPS(true); // Enable GPS
Check whether or not the GPS has a fix on location.
fona.GPSstatus()
None
int8_t status. Returns -1 if there was an error.
- 0 - GPS fix is unknown or if GPS is not even enabled
- 1 - No fix, but GPS is enabled (SIM808 V1 only)
- 2 - 2D fix (SIM808 V1 only)
- 3 - 3D fix
// Let's say we're using SIM808 V2 or SIM7000
int8_t GPS_status = fona.GPSstatus();
if (GPS_status == 0) {
Serial.println(F("GPS not even on!"));
}
else if (GPS_status == 3) {
Serial.println(F("Got a GPS fix!"));
}
Query the GPS location. Only works on modules with GPS (SIM808, SIM5320, SIM7000, SIM7500). There are two function definitions for different applications.
- fona.getGPS(arg, buffer, maxbuff)
- fona.getGPS(&lat, &lon, &speed_kph, &heading, &altitude, &year, &month, &day, &hour, &min, &sec)
For the first function usage:
- arg: uint8_t command argument (powers of 2, 0 by default) only for SIM808 V1. See SIM808 AT command manual for more details.
- buffer: char array for containing the module reply with the GPS info
- maxbuff: uint8_t maximum number of characters to read out into the buffer
For the second usage:
- lat: float for holding the latitude
- lon: float for holding the longitude
- speed_kph: float for holding the speed in kph
- heading: float for holding the heading (degrees)
- altitude: float for holding the altitude
- year: optional uint16_t year (4 digits) parsed from the GPS info
- month: optional uint8_t month parsed from the GPS info
- day: optional uint8_t day parsed from the GPS info
- hour: optional uint8_t hour parsed from the GPS info
- min: optional uint8_t minute parsed from the GPS info
- sec: optional float second parsed from the GPS info
- For the first function usage, returns uint8_t reply length
- For the second function usage, returns true or false based on whether everything ran OK
// Let's just read out the GPS info response and store it in the buffer
char replybuffer[255];
if (! fona.getGPS(0, replybuffer, 250)) {
Serial.println(F("Error!"));
}
else {
Serial.print(F("GPS Info: ")); Serial.println(replybuffer);
}
// Now let's actually parse the GPS info
float latitude, longitude, speed_kph, heading, altitude, second;
uint16_t year;
uint8_t month, day, hour, minute;
// Use the top line if you want to parse UTC time data as well, the line below it if you don't care
// if (fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude, &year, &month, &day, &hour, &minute, &second)) {
if (! fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude)) { // Use this line instead if you don't want UTC time
Serial.println(F("Error!"));
}
else {
Serial.print(F("Latitude: ")); Serial.println(latitude, 6); // Print out 6 decimal places
Serial.print(F("Longitude: ")); Serial.println(longitude, 6);
Serial.print(F("Speed: ")); Serial.println(speed_kph);
Serial.print(F("Heading: ")); Serial.println(heading);
Serial.print(F("Altitude: ")); Serial.println(altitude);
// Comment out the stuff below if you don't care about UTC time
/*
Serial.print(F("Year: ")); Serial.println(year);
Serial.print(F("Month: ")); Serial.println(month);
Serial.print(F("Day: ")); Serial.println(day);
Serial.print(F("Hour: ")); Serial.println(hour);
Serial.print(F("Minute: ")); Serial.println(minute);
Serial.print(F("Second: ")); Serial.println(second);
Serial.println(F("---------------------"));
*/
}
Enable NMEA output on USB's NMEA COM port. When you plug in the device via USB you should see this port.
Note: You must follow these instructions to install the drivers before you can see the COM port.
fona.enableGPSNMEA(option)
- option: For modules other than the SIM808 it can either be 0 to disable NMEA output or 1 to enable. For the SIM808 please reference the AT+CGPSOUT command in the AT command manual for all the available options.
- True if the AT commands ran successfully
- False if any AT command produced an error or timed out
fona.enableGPSNMEA(1); // Turn on NMEA output
Connect to a server via TCP. Does not work on SIM5320.
Note: Must enable GPRS/data before using TCP functions.
fona.TCPconnect(server, port)
- server: char array containing the server IP address or URL
- port: uint16_t port number
- True if connected to server successfully
- False otherwise
fona.enableGPRS(true); // Enable data first
if (! fona.TCPconnect("xxx.xxx.x.x", 80)) Serial.println(F("Failed to connect!")); // Connect to server via TCP
Close TCP connection.
Note: Must enable GPRS/data before using TCP functions.
fona.TCPclose()
None
- True if closed successfully
- False otherwise
fona.TCPclose(); // Close TCP connection
Check if currently connected to a TCP server.
Note: Must enable GPRS/data before using TCP functions.
fona.TCPconnected()
None
- True if it is connected
- False otherwise
bool isConnected = fona.TCPconnected();
Send data to the server over TCP connection. Must be already connected to a server to send data.
Note: Must enable GPRS/data before using TCP functions.
fona.TCPsend(packet, len)
- packet: char array containing the data being sent
- len: uint8_t packet length
- True if connected to server successfully
- False otherwise
fona.enableGPRS(true); // Enable data first
if (! fona.TCPconnect("xxx.xxx.x.x", 80)) Serial.println(F("Failed to connect!")); // Connect to server via TCP
// Now let's send data
char packet[] = "testing 123!!!";
if (! fona.TCPsend(packet, sizeof(packet))) Serial.println(F("Failed to send!"));
fona.TCPclose(); // Close TCP connection
Check how many bytes are available to read via TCP.
fona.TCPavailable()
None
uint16_t number of bytes available. Returns 0 if nothing is available.
uint16_t numBytes = fona.TCPavailable();
Read any available data via TCP.
fona.TCPread(buffer, len)
- buffer: char buffer to hold the contents
- len: max length to read into the buffer
uint16_t number of bytes read
fona.enableGPRS(true); // Enable data first
if (! fona.TCPconnect("xxx.xxx.x.x", 80)) Serial.println(F("Failed to connect!")); // Connect to server via TCP
// Now let's read data
char replybuffer[255];
uint16_t bytesRead = fona.TCPread(replybuffer, 250);
if (bytesRead == 0) {
Serial.println(F("Failed to read / nothing available!"));
}
else {
Serial.print(F("Read ")); Serial.print(bytesRead); Serial.print(F(" bytes!"));
}
fona.TCPclose(); // Close TCP connection
Send the connect packet to the MQTT broker.
Note: Must have data enabled and must connect to the server via TCP/UDP before using this command.
fona.MQTTconnect(protocol, clientID, username, password)
- protocol: string defining the MQTT protocol. Ex: "MQTT" or "MQIsdp" (for CloudMQTT specifically)
- clientID: string containing the client ID. This can be the device's IMEI number, custom name, etc.
- username: string containing the username
- password: string containing the password
- True if successfully connected
- False otherwise
Please see the IoT_Example sketch for examples on how to use the MQTT functions.
Send disconnect packet to the MQTT broker. NOTE: FUNCTION IS UNDER CONSTRUCTION!
Note: Must have data enabled and must be connected to MQTT broker before using this command.
fona.MQTTdisconnect()
None
- True if successfully disconnected
- False otherwise
Please see the IoT_Example sketch for examples on how to use the MQTT functions.
Publish data to an MQTT topic.
Note: Must have data enabled and must be connected to MQTT broker before using this command.
fona.MQTTpublish(topic, message)
- topic: string MQTT topic (or channel) to publish data to
- message: string packet content to send to the topic
- True if successfully published data
- False otherwise
Please see the IoT_Example sketch for examples on how to use the MQTT functions.
Subscribe to an MQTT topic.
Note: Must have data enabled and must be connected to MQTT broker before using this command.
fona.MQTTsubscribe(topic, QoS)
- topic: string MQTT topic (or channel) to publish data to
- QoS: byte MQTT quality of service number
- True if successfully subscribed to topic
- False otherwise
Please see the IoT_Example sketch for examples on how to use the MQTT functions.
Unsubscribe to an MQTT topic. NOTE: FUNCTION IS UNDER CONSTRUCTION!
Note: Must have data enabled and must be connected to MQTT broker before using this command.
fona.MQTTunsubscribe(topic)
- topic: string MQTT topic (or channel) to unsubscribe from
- True if successfully unsubscribed from topic
- False otherwise
Please see the IoT_Example sketch for examples on how to use the MQTT functions.
Unsubscribe to an MQTT topic. NOTE: FUNCTION IS UNDER CONSTRUCTION!
Note: Must have data enabled and must be subscribed to an MQTT topic before using this command.
fona.MQTTreceive(topic, buf, maxlen)
- topic: string MQTT topic (or channel) to receive data from
- buf: char buffer to hold the data content
- maxlen: uint8_t max number of characters to read
- True if successfully subscribed to topic
- False otherwise
Please see the IoT_Example sketch for examples on how to use the MQTT functions.
Connect to FTP server.
fona.FTP_connect(serverIP, port, username, password)
- serverIP: string of server IP address
- port: uint16_t port number
- username: FTP username
- password: FTP password
- True if connected to server successfully
- False otherwise
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Quit FTP.
fona.FTP_Quit()
None
- True if quit successfully
- False otherwise
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Rename a file on FTP server.
fona.FTP_Rename(filePath, oldName, newName)
- filePath: string with file path. Ex: "/" for root directory, "/photos/cats/" to get into another directory, etc.
- oldName: string with old name of file. Ex: "lame123"
- newName: string with new file name. Ex: "awesome123"
- True if file rename was successful
- False otherwise
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Delete a file from FTP server.
fona.FTP_Delete(fileName, filePath)
- fileName: string with name of the file to delete. Ex: "deleteMe.txt"
- filePath: string with file path. Ex: "/" for root directory, "/photos/cats/" to get into another directory, etc.
- True if file was deleted successfully
- False otherwise
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Get the last modification time (MDTM) of a file on the FTP server.
fona.FTP_MDTM(fileName, filePath, &year, &month, &day, &hour, &minute, &second)
- fileName: string with name of the file to get a timestamp of. Ex: "updated.txt"
- filePath: string with file path. Ex: "/" for root directory, "/photos/cats/" to get into another directory, etc.
- year: uint16_t year (4 digits)
- month: uint8_t month
- day: uint8_t day
- hour: uint8_t hour
- minute: uint8_t minute
- second: uint8_t second
- True if MDTM was obtained successfully
- False otherwise
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Perform an FTP GET request to read data from the server. Automatically uses extended GET when requested number of bytes exceeds 1024 bytes.
NOTE: Function not fully tested!
fona.FTP_GET(fileName, filePath, numBytes)
- fileName: string with name of the file to read data from. Ex: "plzdontread.txt"
- filePath: string with file path. Ex: "/" for root directory, "/confidential/" to get into another directory, etc.
- numBytes: uint16_t number of bytes to read from the file
char buffer containing the data read from the file.
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Perform an FTP PUT request to write data to a file on the server. Automatically uses extended PUT when number of bytes exceeds 1024 bytes.
NOTE: Function not fully tested!
fona.FTP_PUT(fileName, filePath, content, numBytes)
- fileName: string with name of the file to read data from. Ex: "plzdontread.txt"
- filePath: string with file path. Ex: "/" for root directory, "/confidential/" to get into another directory, etc.
- content: string with content to put in the file. Ex: "lorem ipsum dolor sit amet"
- numBytes: uint16_t number of bytes to read from the file
- True if the FTP PUT was successful
- False otherwise
Please see the FTP_Demo sketch for examples on how to use the FTP functions.
Initialize HTTP with AT+HTTPINIT command.
fona.HTTP_init()
None
- True if the AT command ran successfully
- False otherwise
fona.HTTP_init(); // Initialize HTTP
Terminate HTTP with AT+HTTPTERM command.
fona.HTTP_term()
None
- True if the AT command ran successfully
- False otherwise
fona.HTTP_term(); // Terminate HTTP
Start HTTP parameters with AT+HTTPPARA command. Note: this does not actually finish the AT command! See other HTTP functions for explanation.
fona.HTTP_para_start(parameter, quoted)
- parameter: flash string with parameter to set. Ex: F("URL") or F("CONTENT")
- quoted: bool true or false for parameter to be in quotes or not
Nothing
// The following line prints this: AT+HTTPPARA="URL","
fona.HTTP_para_start(F("URL"), true);
Low-level function to end the AT+HTTPPARA command based on quoted or not. Note: this is not a complete AT command! See next function for a function that runs a full command.
fona.HTTP_para_end(quoted)
- quoted: bool true or false for parameter to be in quotes or not
- True if the AT command ran successfully
- False otherwise
fona.HTTP_init(); // Begin HTTP
fona.HTTP_para_start(F("URL")); // Star the AT+HTTPPARA command
fonaSS.println("dweet.io/dweet/for/device123?foo=bar"); // Print the actual value using software/hardware serial
fona.HTTP_para_end(true); // Finish the AT command
// In total, this sends the command AT+HTTPPARA="URL","dweet.io/dweet/for/device123?foo=bar"
Set HTTP parameters with the AT+HTTPPARA command.
fona.HTTP_para(parameter, value)
- parameter: flash string with parameter to set. Ex: F("URL") or F("CONTENT")
- value: (string, flash string, or int32_t) value of the parameter. Ex: "dweet.io/dweet/for/device123?foo=bar"
- True if the AT command ran successfully
- False otherwise
fona.HTTP_para(F("URL"), "dweet.io/dweet/for/device123?foo=bar"); // Set HTTP URL
Input HTTP data with the AT+HTTPDATA command.
fona.HTTP_data(size, maxTime)
- size: uint32_t size of the data to input
- maxTime: uint32_t max time (in ms) before timing out, 10s by default
- True if it sees the response "DOWNLOAD" after sending the command
- False otherwise
fona.HTTP_data(120, 15000); // Run the command AT+HTTPDATA=32,15000
Use the AT+HTTPACTION command.
fona.HTTP_action(method, status, datalen, timeout)
- method: uint8_t desired method, 0 for HTTP GET request or 1 for HTTP POST request.
- status: uint16_t number to store the HTTP status code
- datalen: uint16_t length of the data for GET or POST
- timeout: int32_t timeout in milliseconds
- True if the AT command ran successfully
- False otherwise
See HTTP_GET_start() function in Adafruit_FONA.cpp library file.
Read the HTTP server response with the AT+HTTPREAD command.
fona.HTTP_readall(datalen)
- datalen: uint16_t expected length of the data to be read
- True if the data that is read has the length equal to the expected length
- False otherwise
fona.HTTP_readall(150); // Read server response, expecting to read exactly 150 bytes
Enable or disable SSL for HTTP using the AT+HTTPSSL command. Only works for SIM800.
fona.HTTP_ssl(onoff)
- onoff: True or false (enable or disable)
- True if the command ran successfully
- False otherwise
fona.HTTP_ssl(true); // Set up HTTP to use SSL
High-level function to perform an HTTP GET request.
fona.begin(url, status, datalen)
- url: char array containing the URL
- status: uint16_t for storing HTTP status code
- datalen: uint16_t length of the server response
- True if the AT command ran successfully
- False otherwise
See the "w" command in the LTE_Demo sketch
End HTTP. Calls the function HTTP_term() and written by Adafruit probably just for the sake of naming the function to match the HTTP_GET_start() command.
fona.HTTP_GET_end()
None
- True if the AT command ran successfully
- False otherwise
fona.HTTP_GET_end(); // Quit HTTP
High-level function to perform an HTTP POST request.
fona.HTTP_POST_start(url, contenttype, postdata, postdatalen, status, datalen)
- url: string containing the URL
- contenttype: flash string value of the HTTP Conten-Type header. Ex: F("text/plain")
- postdata: uint8_t data to post
- postdatalen: uint16_t length of the data to post
- status: uint16_t for storing HTTP status code
- datalen: uint16_t length of the server response
- True if the AT command ran successfully
- False otherwise
See the "W" command in the LTE_Demo sketch
End HTTP. Calls the function HTTP_term() and written by Adafruit probably just for the sake of naming the function to match the HTTP_POST_start() command.
fona.HTTP_POST_end()
None
- True if the AT command ran successfully
- False otherwise
fona.HTTP_POST_end(); // Quit HTTP
Set the user agent, "FONA" by default if not explicitly set.
fona.setUserAgent(useragent)
- useragent: flash string user agent
Nothing
fona.setUserAgent(F("myAmazingDevice"));
Enables redirects by setting the "REDIR" parameter to 1 in the AT+HTTPPARA command.
fona.setHTTPSRedirect(onoff)
- onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False otherwise
fona.setHTTPSRedirect(true); // Enable redirects
Generate pulse width modulation (PWM) for buzzer. Only works for SIM800 and SIM808.
fona.setPWM(freq, duty)
- freq: uint16_t frequency, 0-2000 Hz (0 turns it off)
- duty: uint8_t PWM duty cycle, 50% by default
- True if the AT command ran successfully
- False otherwise
fona.setPWM(1000); // Set to 1kHz
Call a phone!
fona.callPhone(phonenum)
- phonenum: string with the phone number, including country code but only digits (excluding "+" sign or dashes). Ex: if your phone number is +1 222-333-4444 then you should use "12223334444"
- True if the call was successful
- False otherwise
const char * phone_number = "12223334444"; // Include country code but only numbers!
if (!fona.callPhone(phone_number)) {
Serial.println(F("Call failed"));
}
else {
Serial.println(F("Sent!"));
}
Get the current call status.
fona.getCallStatus()
None
uint8_t call status, either one of the values below. Returns 1 if failed.
- 0 - Ready
- 2 - Unknown
- 3 - Ringing
- 4 - Call in progress
uint8_t callstat = fona.getCallStatus();
switch (callstat) {
case 0: Serial.println(F("Ready")); break;
case 1: Serial.println(F("Could not get status")); break;
case 3: Serial.println(F("Ringing (incoming)")); break;
case 4: Serial.println(F("Ringing/in progress (outgoing)")); break;
default: Serial.println(F("Unknown")); break;
}
Hang up from a call.
fona.hangUp()
None
- True if hang up successful
- False otherwise
if (! fona.hangUp()) {
Serial.println(F("Failed"));
}
else {
Serial.println(F("OK!"));
}
Pick up an incoming phone call.
fona.pickUp()
None
- True if successful
- False otherwise
if (! fona.pickUp()) {
Serial.println(F("Failed"));
}
else {
Serial.println(F("OK!"));
}
Set calling line identification presentation parameters. This feature allows you to set up an interrupt whenever the modem receives a phone call.
fona.callerIdNotification(onoff, interrupt)
- onoff: True or false (enable or disable)
- interrupt: uint8_t interrupt pin number. See the Arduino attachInterrupt() function for more details.
- True if the AT command ran successfully
- False otherwise
// Let's assume we're using an Arduino Uno
callerIdNotification(true, 0); // Enable interrupt on digital pin 2 (INT0)
Extract the number of the caller.
fona.incomingCallNumber(phonenum)
- phonenum: char buffer to hold the caller's number
- True if successful
- False if there's no incoming call to begin with
char callerNumber[12]; // Buffer to hold the phone number
if (! fona.incomingCallNumber() ) {
Serial.println(F("No incoming call!"));
}
else {
Serial.print(F("Caller number:"));
Serial.println(callerNumber);
}
Read available lines into the buffer and check for a specific reply from the module. Use this command after sending an AT command to the module.
fona.expectReply(reply, timeout)
- reply: flash string of the expected reply. Ex: F("OK") or F("DOWNLOAD")
- timeout: uint16_t timeout in milliseconds, 10s by default
- True if the reply matches the expected reply
- False otherwise
// Use software serial to send AT command
// Doing it this way is only really useful
// when constructing a command composed of
// several parts.
const char * APN = "hologram";
fonaSS.print("AT+CGDCONT=1,\"IP\",");
fonaSS.println(APN);
// Read the reply and see if it matches "OK"
if (! fona.expectReply(F("OK")) ) {
Serial.println(F("Command failed!"));
}
else {
Serial.println(F("Success!"));
}
Send a command and check the reply for a specific response.
fona.sendCheckReply(send, reply, timeout)
- send: string or flash string of the command being sent
- reply: string or flash string of the expected reply
- timeout: uint16_t timeout in milliseconds, 500ms by default
- True if the reply was as expected
- False if the reply was not as expected or timed out
// Send command "AT+CREG?" and expect "OK" reply with 1s timeout
if (! fona.sendCheckReply("AT+CREG?", "OK", 1000) ) {
Serial.println(F("Command failed!"));
}
else {
Serial.println(F("Success!"));
}