-
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. The source code has moved from this repo to another repo to meet Arduino's library manager specifications.
Some notes:
- All the functions below can be modified in the BotleticsSIM7000.cpp and BotleticsSIM7000.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.
- modem.begin()
- modem.setBaudrate()
- Stream functions: available(), write(), read(), peek(), flush()
- modem.type()
- modem.getIMEI()
- modem.setFunctionality()
- modem.setNetworkSettings()
- modem.setPreferredMode()
- modem.setPreferredLTEMode()
- modem.openWirelessConnection()
- modem.wirelessConnStatus()
- modem.setOperatingBand()
- modem.enableSleepMode()
- modem.set_eDRX()
- modem.enablePSM()
- modem.setNetLED()
- modem.enableRTC()
- modem.readRTC()
- modem.enableNTPTimeSync()
- modem.getTime()
- modem.powerOn()
- modem.powerDown()
- modem.getADCVoltage()
- modem.getBattPercent()
- modem.getBattVoltage()
- modem.unlockSIM()
- modem.getSIMCCID()
- modem.getNetworkStatus()
- modem.getRSSI()
- modem.getNetworkInfo()
- modem.setSMSInterrupt()
- modem.getSMSInterrupt()
- modem.getNumSMS()
- modem.readSMS()
- modem.sendSMS()
- modem.deleteSMS()
- modem.getSMSSender()
- modem.sendUSSD()
- modem.setAudio()
- modem.setVolume()
- modem.getVolume()
- modem.playToolkitTone()
- modem.setMicVolume()
- modem.playDTMF()
- modem.tuneFMradio()
- modem.FMradio()
- setFMVolume()
- modem.getFMVolume()
- modem.getFMSignalLevel()
- modem.enableGPRS()
- modem.GPRSstate()
- modem.getGSMLoc()
- modem.postData()
- modem.enableGPS()
- modem.GPSstatus()
- modem.getGPS()
- modem.enableGPSNMEA()
- modem.TCPconnect()
- modem.TCPclose()
- modem.TCPconnected()
- modem.TCPsend()
- modem.TCPavailable()
- modem.TCPread()
- modem.addRootCA()
- modem.MQTTconnect()
- modem.MQTTdisconnect()
- modem.MQTTpublish()
- modem.MQTTsubscribe()
- modem.MQTTunsubscribe()
- modem.MQTTreceive()
- modem.MQTT_setParameter()
- modem.MQTT_connect()
- modem.MQTT_connectionStatus()
- modem.MQTT_subscribe()
- modem.MQTT_unsubscribe()
- modem.MQTT_publish()
- modem.MQTT_dataFormatHex()
- modem.FTP_Connect()
- modem.FTP_Quit()
- modem.FTP_Rename()
- modem.FTP_Delete()
- modem.FTP_MDTM()
- modem.FTP_GET()
- modem.FTP_PUT()
- modem.HTTP_init()
- modem.HTTP_term()
- modem.HTTP_para_start()
- modem.HTTP_para_end()
- modem.HTTP_para()
- modem.HTTP_data()
- modem.HTTP_action()
- modem.HTTP_readall()
- modem.HTTP_ssl()
- modem.HTTP_GET_start()
- modem.HTTP_GET_end()
- modem.HTTP_POST_start()
- modem.HTTP_POST_end()
- modem.setUserAgent()
- modem.setHTTPSRedirect()
- modem.HTTP_connect()
- modem.HTTP_addHeader()
- modem.HTTP_addPara()
- modem.HTTP_GET()
- modem.HTTP_POST()
- modem.setPWM()
- modem.callPhone()
- modem.getCallStatus()
- modem.hangUp()
- modem.pickUp()
- modem.callerIdNotification()
- modem.incomingCallNumber()
- modem.expectReply()
- modem.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.
modem.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 "BotleticsSIM7000.h" // https://github.com/botletics/Botletics-SIM7000/tree/main/src
#include <SoftwareSerial.h>
#define TX 10 // Microcontroller RX, module TX
#define RX 11 // Microcontroller TX, module RX
SoftwareSerial modemSS = SoftwareSerial(TX, RX);
SoftwareSerial *modemSerial = &modemSS;
Botletics_modem_LTE modem = Botletics_modem_LTE(); // Instantiate modem LTE class
void setup() {
modemSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
modemSS.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
modemSS.begin(9600);
if (! modem.begin(modemSS)) {
Serial.println(F("Couldn't find modem"));
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.
modem.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 modem.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 "BotleticsSIM7000.h" // https://github.com/botletics/Botletics-SIM7000/tree/main/src
#include <SoftwareSerial.h>
#define TX 10 // Microcontroller RX, module TX
#define RX 11 // Microcontroller TX, module RX
SoftwareSerial modemSS = SoftwareSerial(TX, RX);
SoftwareSerial *modemSerial = &modemSS;
Botletics_modem_LTE modem = Botletics_modem_LTE();
void setup() {
modemSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
modemSS.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
modemSS.begin(9600);
if (! modem.begin(modemSS)) {
Serial.println(F("Couldn't find modem"));
while (1); // Don't proceed if it couldn't find the device
}
Serial.println(F("Switching to 4800 baud"));
modem.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().
- modem.available()
- modem.write(uint8_t x)
- modem.read()
- modem.peek()
- modem.flush()
None. See Arduino stream documentation for more info.
Nothing
void loop() {
// Read and print out anything coming from the modem
Serial.print(F("modem> "));
while (! Serial.available() ) {
if (modem.available()) {
Serial.write(modem.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.
modem.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 = modem.type();
Serial.println(F("modem 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.
modem.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 = modem.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.
modem.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
modem.setFunctionality(1); // AT+CFUN=1
// Software restart module
modem.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.
modem.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.
// modem.setNetworkSettings(F("your APN"), F("your username"), F("your password"));
// Examples (only use one of course!):
modem.setNetworkSettings(F("m2m.com.attz")); // For AT&T IoT SIM card
modem.setNetworkSettings(F("telstra.internet")); // For Telstra (Australia) SIM card - CAT-M1 (Band 28)
modem.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.
modem.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
modem.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.
modem.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
modem.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.
modem.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
modem.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.
modem.wirelessConnStatus()
None
- True if the device is connected
- False if the command errors or times out, or if device is not connected
bool isConnected = modem.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.
modem.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
modem.setOperatingBand("CAT-M", 12); // AT&T uses band 12
// Force the SIM7000 to use Verizon LTE CAT-M only
modem.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.
modem.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
modem.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.
modem.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
modem.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 modem.enableSleepMode(true) command must be used before this will work and USB port must be disconnected.
modem.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
modem.enableSleepMode(true);
modem.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.
modem.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
modem.setNetLED(true, 2, 64, 3000); // on/off, mode, timer_on, timer_off
// We could also disable the LED altogether
modem.setNetLED(false); // Disable network status LED
Enable UTC network time sync and local time stamp with the AT+CLTS command.
modem.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
modem.enableRTC(true);
Read and parse the current time.
modem.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;
modem.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.
modem.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 (!modem.enableNTPTimeSync(true, F("pool.ntp.org")))
Serial.println(F("Failed to enable"));
break;
Get the current local time and store it in a buffer.
modem.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];
modem.getTime(buffer, 23); // Make sure replybuffer is at least 23 bytes!
Serial.print(F("Time = ")); Serial.println(buffer);
Power on the modem by pulsing the PWRKEY pin LOW for a certain duration (dependent on the module). Initializes the PWRKEY pin as a digital OUTPUT.
modem.powerOn(modem_PWRKEY)
- modem_PWRKEY: uint8_t PWRKEY pin number
Nothing
const uint8_t modem_PWRKEY = 6; // for botletics SIM7000 shield
modem.powerOn(modem_PWRKEY); // Power on the module
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.
modem.powerDown()
None
- True if the AT command ran successfully
- False if the AT command produced an error or timed out
modem.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.
modem.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 (! modem.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.
modem.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 (! modem.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).
modem.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 (! modem.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.
modem.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 (!modem.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.
modem.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];
modem.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.
modem.getNetworkStatus()
None
uint8_t network status number
// Read the network/cellular status
uint8_t n = modem.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.
modem.getRSSI()
None
uint8_t RSSI value
// Read the raw RSSI value
uint8_t n = modem.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.
modem.getNetworkInfo()
None
- True if successful
- False if unsuccessful
modem.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.
modem.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
modem.setSMSInterrupt(1); // Enable interrupt to be triggered by TCPIP, FTP and URC
Get the interrupt functionality option as described in the previous function.
modem.getSMSInterrupt()
None
uint8_t option number as described in the previous function.
uint8_t option = modem.getSMSInterrupt();
Get the number of stored SMS messages.
modem.getNumSMS()
None
int8_t number of SMS. Returns -1 if there was an error.
int8_t sms_num = modem.getNumSMS();
Read a stored SMS message based on its index.
modem.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 (!modem.readSMS(sms_num, SMS_content, maxlen, &smslen)) {
Serial.println(F("Failed to read SMS!"));
}
Send a text message (SMS) to a phone number.
modem.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 = "0012223334567"; // Include 3-digit country code, only numbers
const char * text_message = "All ur base ar belong 2 us!";
if (!modem.sendSMS(phoneNum, textMessage)) {
Serial.println(F("Failed to send"));
}
else {
Serial.println(F("Sent!"));
}
Delete a stored SMS based on its index.
modem.deleteSMS(index)
- index: The index of the stored SMS.
- True if deleted successfully
- False if otherwise
uint8_t sms_idx = 1;
if (modem.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.
modem.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 (! modem.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.
modem.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 (!modem.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.
modem.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
modem.setAudio(1); // Set to speaker phone for SIM800
// OR, for different module:
modem.setAudio(3); // Set to speaker phone for SIM7500
Set the speaker volume. Works on voice-enabled modules only.
modem.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
modem.setVolume(80); // Set volume to 80% on SIM800
// OR on a different module:
modem.setVolume(5); // Max out volume for SIM7500
Set the speaker volume. Works on voice-enabled modules only.
modem.getVolume()
None
uint8_t volume level as described in the previous function.
uint8_t volume = modem.getVolume();
Play toolkit tone (pre-defined tones unique to each module). Works on 2G and 3G voice-enabled modules only.
modem.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
modem.playToolkitTone(8, 5000); // Play ringing tone for SIM800 for 5s
Set the microphone gain. Works on 2G voice-enabled modules only.
modem.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
modem.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.
modem.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
modem.playDTMF('B'); // Play the note 'B'
Set the FM radio frequency.
modem.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
modem.tuneFMradio(901); // Listen to WABE Atlanta (NPR's station)
Open or close FM radio.
modem.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
modem.FMradio(true, 1); // Enable FM radio on external headset
Set the FM radio volume.
modem.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
modem.setFMVolume(6); // Set the FM radio to max volume
Get the current FM radio volume.
modem.getFMVolume(volume)
None
int8_t FM volume as described in the previous function. Returns 0 if there was an error.
int8_t FM_vol = modem.getFMVolume();
Get the signal level of an FM station.
modem.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).
modem.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 (!modem.enableGPRS(true)) {
Serial.println(F("Failed to enable data"));
}
Read the current GPRS state (enabled or disabled) with the AT+CGATT? function.
modem.GPRSstate()
None
int8_t state. Returns -1 if there is an error.
int8_t state = modem.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.
- modem.getGSMLoc(&replycode, buff, maxlen)
- modem.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
modem.enableGPRS(true);
// Get GSM location
uint16_t returncode;
char replybuffer[255];
if (!modem.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 (! modem.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.
- modem.postData(request_type, URL, body, token, bodylen)
- modem.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 and the IoT_Example sketch for example usage of this function.
Enable or disable GPS. Only works on modules with GPS (SIM808, SIM5320, SIM7000, SIM7500).
modem.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
modem.enableGPS(true); // Enable GPS
Check whether or not the GPS has a fix on location.
modem.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 = modem.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.
- modem.getGPS(arg, buffer, maxbuff)
- modem.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 (! modem.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 (! modem.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude, &year, &month, &day, &hour, &minute, &second)) {
if (! modem.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.
modem.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
modem.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.
modem.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
modem.enableGPRS(true); // Enable data first
if (! modem.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.
modem.TCPclose()
None
- True if closed successfully
- False otherwise
modem.TCPclose(); // Close TCP connection
Check if currently connected to a TCP server.
Note: Must enable GPRS/data before using TCP functions.
modem.TCPconnected()
None
- True if it is connected
- False otherwise
bool isConnected = modem.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.
modem.TCPsend(packet, len)
- packet: char array containing the data being sent
- len: uint8_t packet length
- True if connected to server successfully
- False otherwise
modem.enableGPRS(true); // Enable data first
if (! modem.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 (! modem.TCPsend(packet, sizeof(packet))) Serial.println(F("Failed to send!"));
modem.TCPclose(); // Close TCP connection
Check how many bytes are available to read via TCP.
modem.TCPavailable()
None
uint16_t number of bytes available. Returns 0 if nothing is available.
uint16_t numBytes = modem.TCPavailable();
Read any available data via TCP.
modem.TCPread(buffer, len)
- buffer: char buffer to hold the contents
- len: max length to read into the buffer
uint16_t number of bytes read
modem.enableGPRS(true); // Enable data first
if (! modem.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 = modem.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!"));
}
modem.TCPclose(); // Close TCP connection
Add a root CA certificate for SSL to be used in TCP commands. To use it, set #define BOTLETICS_SSL 1
in BotleticsSIM7000.h. In Chrome, you can find a site's root CA by clicking on the padlock next to the URL / Certificate / Details / Copy to File / Base-64 encoded
modem.addRootCA(root_cert)
- root_cert: char array of the root CA certificate
- True if the root CA was added successfully
- False otherwise
// Let's use dweet.io's root CA:
const char root_ca = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIFZDCCBEygAwIBAgIQC5GYuhxBWRXWg9AR7lHB1TANBgkqhkiG9w0BAQsFADBG\n" \
"MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRUwEwYDVQQLEwxTZXJ2ZXIg\n" \
"Q0EgMUIxDzANBgNVBAMTBkFtYXpvbjAeFw0yMDA1MjkwMDAwMDBaFw0yMTA2Mjkx\n" \
"MjAwMDBaMBMxETAPBgNVBAMTCGR3ZWV0LmlvMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \
"AQ8AMIIBCgKCAQEAly3JdZAj2PlUfNXzvNA1BeBGcKJPgS6hXIu6EClQ+Do4Yc/V\n" \
"bdg2dddGFxskay6yRqRC+DC6QVRDE9IIfyD8AOtufdremQh9t8+BLrdjWmpDtCCI\n" \
"775v2IapmWlOx+4o0qAGYuC4n+1OyT/4oT5nvU1fSdX1vCZx0PJ0wlz0aOe4zXdr\n" \
"3MIRc5T+FG9FUrr/PlkrxiOHY8NVJbQAjfHH/7yTGiq0+Q2IHy6AMB7xn/em4ACY\n" \
"V5fDuXNbdNP6SI0j/2me02sfZ3dr9ksPpLWjM603P4yQem+3RE/UEDgSc0zuCdos\n" \
"1RLGsMO2HOeIwLYn1s9Ut8/5SxLjGcLuyVhW0QIDAQABo4ICfzCCAnswHwYDVR0j\n" \
"BBgwFoAUWaRmBlKge5WSPKOUByeWdFv5PdAwHQYDVR0OBBYEFJ3fV4tJ19MGiB2J\n" \
"7OQR6UPFUAVdMB8GA1UdEQQYMBaCCGR3ZWV0LmlvggoqLmR3ZWV0LmlvMA4GA1Ud\n" \
"DwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwOwYDVR0f\n" \
"BDQwMjAwoC6gLIYqaHR0cDovL2NybC5zY2ExYi5hbWF6b250cnVzdC5jb20vc2Nh\n" \
"MWIuY3JsMCAGA1UdIAQZMBcwCwYJYIZIAYb9bAECMAgGBmeBDAECATB1BggrBgEF\n" \
"BQcBAQRpMGcwLQYIKwYBBQUHMAGGIWh0dHA6Ly9vY3NwLnNjYTFiLmFtYXpvbnRy\n" \
"dXN0LmNvbTA2BggrBgEFBQcwAoYqaHR0cDovL2NydC5zY2ExYi5hbWF6b250cnVz\n" \
"dC5jb20vc2NhMWIuY3J0MAwGA1UdEwEB/wQCMAAwggEDBgorBgEEAdZ5AgQCBIH0\n" \
"BIHxAO8AdgD2XJQv0XcwIhRUGAgwlFaO400TGTO/3wwvIAvMTvFk4wAAAXJeSgSG\n" \
"AAAEAwBHMEUCIQD53CmIkykPjB+pBYEPJJ2lQ9Hq3sdLy3NRGc7oM6808AIgZykt\n" \
"SufDG1B64bn/61NgHoV4paBBGCVLkAIgei63oAQAdQBc3EOS/uarRUSxXprUVuYQ\n" \
"N/vV+kfcoXOUsl7m9scOygAAAXJeSgSlAAAEAwBGMEQCIA6O+1frH2C0e6WG13Vz\n" \
"99ry7EbVn4+PS0FXOC3THYyjAiA7jjMhO4pbTkBbvrsCAuiKPyfY7EyrmMu3EVtr\n" \
"71i9qTANBgkqhkiG9w0BAQsFAAOCAQEATMyRMgkty9dTe0+RQlc5H5XNPIe4gGtF\n" \
"vhZYWlDRUcmashIHfv39MhHhRcyfj1bgaji0a7aZv0qgwSj5NGI45WaCeS7Ug8K9\n" \
"PZ2NrifoJQEYSMP0+ml+SomlvYIV2L/KVCMIaumMYKej95yVuE6xeZ8JjNXRYPJf\n" \
"mIp1jZ/lf0jHKp5Ccr1q/rMwoMX1pGJWbsFUXTnuk6hCDiZ5ajjv0P+xRhZ+RHp0\n" \
"nfumXhDcWf3/1Af/GW4Xe0nNb1P484pVbf5y9CeQwvuiluEdQDfDS2uIW0hu0bjn\n" \
"5DbjjjMwjAEy0ez47HL/FXZqJ5dzNc4PXPvL3ICMsQ/G/vYIFmqNXg==\n" \
"-----END CERTIFICATE-----\n";
modem.addRootCA(root_ca);
modem.TCPconnect("dweet.io", 8883); // Connect with SSL
modem.TCPsend("test", 5);
modem.TCPclose();
// etc...
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.
modem.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.
modem.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.
modem.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.
modem.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.
modem.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.
modem.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.
Sets the MQTT parameters (see MQTT app note for more details on parameter values). One must use the modem.MQTT_connect(true) command to actually invoke the MQTT connection.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_setParameter(parameterTag, parameterValue, serverPort)
- parameterTag: string parameter tag. Can be "CLIENTID", "URL", "KEEPTIME", "CLEANSS", "USERNAME", "PASSWORD", "QOS", "TOPIC", "MESSAGE", or "RETAIN"
- parameterValue: string parameter value corresponding to the parameter tag
- serverPort: uint16_t server port (optional, 0 by default to indicate no port number was assigned if not applicable to to the parameter tag)
- True if successfully set MQTT parameter
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Connects to or disconnects from the MQTT server with the AT+SMCONN or AT+SMDISC commands after setting MQTT parameters with the modem.MQTT_setParameter() function.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_connect(yesno)
- yesno: bool true or false for connect or disconnect
- True if command was successful
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Gets the current MQTT connection status.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_connectionStatus()
None
- True if currently connected
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Subscribes to a specified MQTT topic with quality of service (QoS) setting.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_subscribe(topic, QoS)
- topic: string MQTT topic name to subscribe to
- QoS: byte quality of service, from 0-2
- True if successfully subscribed to MQTT topic
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Unsubscribe from MQTT topic.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_unsubscribe(topic)
- topic: string MQTT topic name to unsubscribe from
- True if successfully unsubscribed from MQTT topic
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Publish a message to an MQTT topic.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_publish(topic, message, contentLength, QoS, retain)
- topic: string MQTT topic name to send message to
- message: string message to send to the topic, up to 512 bytes long
- contentLength: uint16_t length of the message in bytes
- QoS: byte quality of service, from 0-2
- retain: byte server retain flag, 0 or 1
- True if successfully sent message to MQTT topic
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Change MQTT data format to hex or back to normal.
Note: This is only for the SIM7000 and will not work on 2G or 3G modules.
modem.MQTT_dataFormatHex(yesno)
- yesno: bool true or false (hex or normal)
- True if successfully set data format
- False otherwise
Please see the SIM7000_MQTT_Demo sketch for how to use the MQTT functions.
Connect to FTP server.
modem.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.
modem.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.
modem.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.
modem.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.
modem.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!
modem.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!
modem.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.
modem.HTTP_init()
None
- True if the AT command ran successfully
- False otherwise
modem.HTTP_init(); // Initialize HTTP
Terminate HTTP with AT+HTTPTERM command.
modem.HTTP_term()
None
- True if the AT command ran successfully
- False otherwise
modem.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.
modem.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","
modem.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.
modem.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
modem.HTTP_init(); // Begin HTTP
modem.HTTP_para_start(F("URL")); // Star the AT+HTTPPARA command
modemSS.println("dweet.io/dweet/for/device123?foo=bar"); // Print the actual value using software/hardware serial
modem.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.
modem.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
modem.HTTP_para(F("URL"), "dweet.io/dweet/for/device123?foo=bar"); // Set HTTP URL
Input HTTP data with the AT+HTTPDATA command.
modem.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
modem.HTTP_data(120, 15000); // Run the command AT+HTTPDATA=32,15000
Use the AT+HTTPACTION command.
modem.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 BotleticsSIM7000.cpp library file.
Read the HTTP server response with the AT+HTTPREAD command.
modem.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
modem.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.
modem.HTTP_ssl(onoff)
- onoff: True or false (enable or disable)
- True if the command ran successfully
- False otherwise
modem.HTTP_ssl(true); // Set up HTTP to use SSL
High-level function to perform an HTTP GET request.
modem.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.
modem.HTTP_GET_end()
None
- True if the AT command ran successfully
- False otherwise
modem.HTTP_GET_end(); // Quit HTTP
High-level function to perform an HTTP POST request.
modem.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.
modem.HTTP_POST_end()
None
- True if the AT command ran successfully
- False otherwise
modem.HTTP_POST_end(); // Quit HTTP
Set the user agent, "modem" by default if not explicitly set.
modem.setUserAgent(useragent)
- useragent: flash string user agent
Nothing
modem.setUserAgent(F("myAmazingDevice"));
Enables redirects by setting the "REDIR" parameter to 1 in the AT+HTTPPARA command.
modem.setHTTPSRedirect(onoff)
- onoff: True or false (enable or disable)
- True if the AT command ran successfully
- False otherwise
modem.setHTTPSRedirect(true); // Enable redirects
Connects to a server via HTTP
Note: This is only for the LTE class and will not work on 2G or 3G modules. By default, sets max body length to 1024 bytes and max header length to 350 bytes
modem.HTTP_connect(server)
- server: char array containing the server IP address or URL. Ex: "http://dweet.io" or "http://httpbin.org"
- True if connected to server successfully
- False otherwise
modem.HTTP_connect("http://httpbin.org");
Add HTTP header.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
modem.HTTP_addHeader(type, value, maxlen)
- type: string with the HTTP header. Ex: "User-Agent", "Connection", etc.
- value: string with the value corresponding to the header
- maxlen: max length of the tag or the value in bytes, whiever is larger
- True if the AT command ran successfully
- False otherwise
modem.HTTP_addHeader("User-Agent", "SIM7070", 7);
modem.HTTP_addHeader("Cache-control", "no-cache", 8);
modem.HTTP_addHeader("Connection", "keep-alive", 10);
modem.HTTP_addHeader("Accept", "*\"*", 3);
Add HTTP parameter.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
modem.HTTP_addPara(key, value, maxlen)
- key: string with the HTTP parameter
- value: string with the value corresponding to the parameter
- maxlen: max length of the key or the value in bytes, whiever is larger
- True if the AT command ran successfully
- False otherwise
// Add JSON body parameters for HTTP POST
modem.HTTP_addPara("temperature", "21.8", 11);
modem.HTTP_addPara("humidity", "57.5", 8);
Perform HTTP GET request.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
modem.HTTP_GET(URI)
- URI: query string with name/value pairs
- True if the GET request was successful
- False otherwise
modem.HTTP_connect("http://dweet.io");
modem.HTTP_GET("/dweet/for/{device_ID}?temperature=21.3&humidity=56.7");
Perform HTTP POST request.
Note: This is only for the LTE class and will not work on 2G or 3G modules.
modem.HTTP_POST(URI, body, bodylen)
- URI: string with the URI
- body: string with the JSON body
- bodylen: length of the JSON body in bytes
- True if the POST request was successful
- False otherwise
modem.HTTP_connect("http://dweet.io"); // Connect to server
modem.HTTP_addHeader("Content-Type", "application/json", 16); // Add header if needed
char body[100] = "{\"temp\":21.3,\"humidity\":56.7}"; // Format JSON body
modem.HTTP_POST("/dweet/for/{device_ID}", body, strlen(body)); // HTTP POST
Generate pulse width modulation (PWM) for buzzer. Only works for SIM800 and SIM808.
modem.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
modem.setPWM(1000); // Set to 1kHz
Call a phone!
modem.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 (!modem.callPhone(phone_number)) {
Serial.println(F("Call failed"));
}
else {
Serial.println(F("Sent!"));
}
Get the current call status.
modem.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 = modem.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.
modem.hangUp()
None
- True if hang up successful
- False otherwise
if (! modem.hangUp()) {
Serial.println(F("Failed"));
}
else {
Serial.println(F("OK!"));
}
Pick up an incoming phone call.
modem.pickUp()
None
- True if successful
- False otherwise
if (! modem.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.
modem.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.
modem.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 (! modem.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.
modem.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";
modemSS.print("AT+CGDCONT=1,\"IP\",");
modemSS.println(APN);
// Read the reply and see if it matches "OK"
if (! modem.expectReply(F("OK")) ) {
Serial.println(F("Command failed!"));
}
else {
Serial.println(F("Success!"));
}
Send a command and check the reply for a specific response.
modem.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 (! modem.sendCheckReply("AT+CREG?", "OK", 1000) ) {
Serial.println(F("Command failed!"));
}
else {
Serial.println(F("Success!"));
}