-
Notifications
You must be signed in to change notification settings - Fork 792
class_tiny_gsm_modem
Module: TinyGsmModem
The CRTP parent class for basic modem functions.
#include <src/TinyGsmModem.tpp>
| Name | |
|---|---|
| bool |
begin(const char * pin = nullptr) Sets up the GSM module. |
| bool |
init(const char * pin = nullptr) Sets up the GSM module. |
| template <typename... Args> void |
sendAT(Args... cmd) Recursive variadic template to send AT commands. |
| bool |
setBaud(uint32_t baud) Set the module baud rate. |
| bool |
setDefaultBaud(uint32_t baud) Set the default baud rate for the modem, ie, the baud rate that the modem will use after a reset or power cycle. |
| template bool |
forceModemBaud(StreamObject & at_serial, uint32_t targetBaud) Attempt to set the modem baud rate by trying set the command to change the baud rate to various common baud rates and seeing if the modem responds to AT commands at that baud rate. |
| bool |
testAT(uint32_t timeout_ms = 10000L) Test response to AT commands. |
| int8_t |
waitResponse(uint32_t timeout_ms, String & data, GsmConstStr r1 = ModemConfig::GSM_OK, GsmConstStr r2 = ModemConfig::GSM_ERROR, GsmConstStr r3 = nullptr, GsmConstStr r4 = nullptr, GsmConstStr r5 = nullptr, GsmConstStr r6 = nullptr, GsmConstStr r7 = nullptr, GsmConstStr r8 = nullptr) Listen for responses to commands and handle URCs. |
| int8_t |
waitResponse(uint32_t timeout_ms, GsmConstStr r1 = ModemConfig::GSM_OK, GsmConstStr r2 = ModemConfig::GSM_ERROR, GsmConstStr r3 = nullptr, GsmConstStr r4 = nullptr, GsmConstStr r5 = nullptr, GsmConstStr r6 = nullptr, GsmConstStr r7 = nullptr, GsmConstStr r8 = nullptr) Listen for responses to commands and handle URCs. |
| int8_t |
waitResponse(GsmConstStr r1 = ModemConfig::GSM_OK, GsmConstStr r2 = ModemConfig::GSM_ERROR, GsmConstStr r3 = nullptr, GsmConstStr r4 = nullptr, GsmConstStr r5 = nullptr, GsmConstStr r6 = nullptr, GsmConstStr r7 = nullptr, GsmConstStr r8 = nullptr) Listen for responses to commands and handle URCs; listening for 1 second. |
| String |
getConfiguredModem() Gets the configured modem manufacture and model based on the compile-time traits. |
| String |
getModemInfo() Asks for modem information via the 3GPP TS 27.007 standard ATI command. |
| String |
getModemName() Get the modem name - a combination of the manufacturer and model, as the modem calls itself. |
| String |
getModemManufacturer() Get the modem manufacturer. |
| String |
getModemModel() Get the modem model. |
| String |
getModemRevision() Get the modem revision information. |
| String |
getModemSerialNumber() Get the modem serial number. |
| bool |
factoryDefault() Reset the module to factory defaults. |
| Name | |
|---|---|
| bool |
restart(const char * pin = nullptr) Restart the module. |
| bool |
poweroff() Power off the module. |
| bool |
powerOff() Power off the module. |
| bool |
radioOff() Turn off the module radio. |
| bool |
sleepEnable(bool enable = true) Enable sleep on the module. |
| bool |
setPhoneFunctionality(uint8_t fun, bool reset = false) Set the phone functionality. |
| Name | |
|---|---|
| regStatusType |
getRegistrationStatus() Get the modem registration status on the network. |
| bool |
isNetworkConnected() Confirm whether the module is currently connected to the GSM/GPRS/LTE network. |
| bool |
waitForNetwork(uint32_t timeout_ms = 60000L, bool check_signal = false) Wait until the module has connected to the network. |
| int16_t |
getSignalQuality() Get the signal quality report. |
| String |
getLocalIP() Get the Local IP address assigned to the module by the network as a String. |
| IPAddress |
localIP() Get the Local IP address assigned to the module by the network as an IPAddress object. |
| Name | |
|---|---|
| template void |
streamWrite(T last) Write a value to the modem stream. |
| template <typename T, typename... Args> void |
streamWrite(T head, Args... tail) Recursively write multiple values to the modem stream. |
| void |
streamClear() Clear the modem stream attempting to parse any URC's in it. |
| void |
streamDump(int16_t expected_len) Dump the modem stream, completely discarding any data in it without attempting to parse any URC's in it. |
bool begin(const char * pin = nullptr)
-
Parameters:
- pin A pin code to unlock the SIM, if necessary
- Return: True if the module was set up as expected, false otherwise.
bool init(const char * pin = nullptr)
-
Parameters:
- pin A pin code to unlock the SIM, if necessary
- Return: True if the module was set up as expected, false otherwise.
template <typename... Args>void sendAT(Args... cmd)
-
Parameters:
- cmd The commands to send
-
Template Parameters:
- Args
bool setBaud(uint32_t baud)
Note
After setting and applying the new baud rate, you will have to end() and begin() the serial object.
-
Parameters:
- baud The baud rate to use
- Return: True if the baud rate was set successfully, false otherwise.
bool setDefaultBaud(uint32_t baud)
-
Parameters:
- baud The baud rate to set the modem to use after a reset or power cycle.
- Return: True if the command was successful, false otherwise.
template <class StreamObject>bool forceModemBaud(StreamObject & at_serial, uint32_t targetBaud)
Unlike TinyGsmAutoBaud, this function will try to set the baud rate on the modem and will attempt to communicate with the modem at the new baud rate whether or not it gets a response at the old baud rate. This is useful in cases where the modem is set to a baud rate that is just a little too fast for the processor, where you might get a response but it will be garbled and not recognized as a response, because in this case you still want to try to set the baud rate.
Note
After setting and applying the new baud rate, you will have to end() and begin() the serial object.
-
Parameters:
- at_serial The serial object to use for communicating with the modem
- targetBaud The final baud rate to try to set the modem to
-
Template Parameters:
- StreamObject The type of the serial object used for communicating with the modem
- Return: True if the modem responded after the baud rate was set, false otherwise.
bool testAT(uint32_t timeout_ms = 10000L)
-
Parameters:
- timeout_ms the amount of time to test for; optional with a default value of 10s.
- Return: True if the module responded to AT commands, false otherwise.
int8_t waitResponse(uint32_t timeout_ms, String & data, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r1 = ModemConfig::GSM_OK, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r2 = ModemConfig::GSM_ERROR, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r3 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r4 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r5 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r6 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r7 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r8 = nullptr)
-
Parameters:
- timeout_ms The time to wait for a response
- data A string of data to fill in with response results
- r1 The first output to test against, optional with a default value of "OK"
- r2 The second output to test against, optional with a default value of "ERROR"
- r3 The third output to test against, optional with a default value of nullptr
- r4 The fourth output to test against, optional with a default value of nullptr
- r5 The fifth output to test against, optional with a default value of nullptr
- r6 The sixth output to test against, optional with a default value of nullptr
- r7 The seventh output to test against, optional with a default value of nullptr
- r8 The eighth output to test against, optional with a default value of nullptr
- Return: the index of the response input
int8_t waitResponse(uint32_t timeout_ms, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r1 = ModemConfig::GSM_OK, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r2 = ModemConfig::GSM_ERROR, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r3 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r4 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r5 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r6 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r7 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r8 = nullptr)
-
Parameters:
- timeout_ms The time to wait for a response
- r1 The first output to test against, optional with a default value of "OK"
- r2 The second output to test against, optional with a default value of "ERROR"
- r3 The third output to test against, optional with a default value of nullptr
- r4 The fourth output to test against, optional with a default value of nullptr
- r5 The fifth output to test against, optional with a default value of nullptr
- r6 The sixth output to test against, optional with a default value of nullptr
- r7 The seventh output to test against, optional with a default value of nullptr
- r8 The eighth output to test against, optional with a default value of nullptr
- Return: the index of the response input
int8_t waitResponse([GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r1 = ModemConfig::GSM_OK, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r2 = ModemConfig::GSM_ERROR, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r3 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r4 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r5 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r6 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r7 = nullptr, [GsmConstStr](../files/_tiny_gsm_common_8h.md#a9c8c9c8249f99863e157f8fae76e7cab) r8 = nullptr)
-
Parameters:
- r1 The first output to test against, optional with a default value of "OK"
- r2 The second output to test against, optional with a default value of "ERROR"
- r3 The third output to test against, optional with a default value of nullptr
- r4 The fourth output to test against, optional with a default value of nullptr
- r5 The fifth output to test against, optional with a default value of nullptr
- r6 The sixth output to test against, optional with a default value of nullptr
- r7 The seventh output to test against, optional with a default value of nullptr
- r8 The eighth output to test against, optional with a default value of nullptr
- Return: the index of the response input
String getConfiguredModem()
Tip
This does not query the modem for its actual manufacture and model, but rather returns the values that were set at compile time.
- Return: The configured modem manufacture and model based on the compile-time traits.
String getModemInfo()
Note
The actual value and style of the response is quite varied
- Return: Some info about the GSM module.
String getModemName()
- Return: The modem name
String getModemManufacturer()
- Return: The modem manufacturer
String getModemModel()
- Return: The modem model, as it calls itself
String getModemRevision()
What is returned as the revision may be either a hardware or a firmware version or some combination of both.
- Return: The modem revision information
String getModemSerialNumber()
This is usually equivalent to the IMEI for cellular modems and the MAC address for WiFi modems.
- Return: The modem serial number
bool factoryDefault()
This generally restarts the module as well.
- Return: True if the module successfully reset to default, false otherwise.
bool restart(const char * pin = nullptr)
-
Parameters:
- pin A pin code to unlock the SIM, if necessary
- Return: True if the module was successfully restarted, false otherwise.
bool poweroff()
Deprecated: deprecated
- Deprecated: deprecated
- Return: True if the module was successfully powered down, false otherwise.
bool powerOff()
- Return: True if the module was successfully powered down, false otherwise.
bool radioOff()
- Return: True if the module radio was successfully turned off, false otherwise.
bool sleepEnable(bool enable = true)
For some modules this immediately puts the module to sleep, for others this sets them to be able to sleep based on pin levels.
-
Parameters:
- enable True to enable sleep, false to disable
- Return: True if sleep was successfully enabled or disabled, false otherwise.
bool setPhoneFunctionality(uint8_t fun, bool reset = false)
-
Parameters:
- fun The phone functionality setting. The value and meaning of this varies by module; check your documentation.
- reset True to reset the module before changing the functionality.
- Return: True if the phone functionality was successfully changed, false otherwise.
regStatusType getRegistrationStatus()
- Return: The modem-specific registration status value.
bool isNetworkConnected()
- Return: True if the module is connected to the network, false otherwise.
bool waitForNetwork(uint32_t timeout_ms = 60000L, bool check_signal = false)
-
Parameters:
- timeout_ms The time to wait for attachment in milliseconds. Optional with a default value of 1 minute.
- check_signal True to alternate between checking for connection and checking the signal strength.
- Return: True if the module is now connected to the network, false otherwise.
int16_t getSignalQuality()
This is often a "CSQ" value ranging from 0 to 32, but may be an RSSI or a percent.
- Return: The signal quality
String getLocalIP()
- Return: The local IP address
IPAddress localIP()
- Return: The local IP address
template <typename T>void streamWrite(T last)
-
Parameters:
- last The value to write.
-
Template Parameters:
- T The type of the value to write.
template <typename T, typename... Args>void streamWrite(T head, Args... tail)
-
Parameters:
- head The first value to write.
- tail The remaining values to write.
-
Template Parameters:
- T The type of the first value to write.
- Args The types of the remaining values to write.
void streamClear()
Warning
Never call this inside of a waitResponse() call or a URC parser!
Todo: todo
void streamDump(int16_t expected_len)
This is good for discarding an expected number of characters from the stream without waiting a full timeout for each character.
Todo: todo
-
Parameters:
- expected_len The number of characters to discard from the stream.
Generated by Doxygen and m.css with templates from doxybook2 Updated on 2026-09-11
If you like TinyGSM library - give it a star, or fork it and contribute!