--- title: TinyGsmModem --- # TinyGsmModem (class) **Module:** **[TinyGsmModem](class_tiny_gsm_modem.html)** The CRTP parent class for basic modem functions. `#include ` ## Basic functions ### Public Functions | | Name | | -------------- | -------------- | | bool | **[begin](#ae4397a65939a770e478e29c718d13e59)**(const char * pin = nullptr)
Sets up the GSM module. | | bool | **[init](#a27f7f71fb1a2008dc57f6d454564022c)**(const char * pin = nullptr)
Sets up the GSM module. | | template
void | **[sendAT](#afa190e606feb7831c86094577064d2e6)**(Args... cmd)
Recursive variadic template to send AT commands. | | bool | **[setBaud](#a279bffb4e905f1150dadab726e8482f2)**(uint32_t baud)
Set the module baud rate. | | bool | **[setDefaultBaud](#ac0a4b1d359f20a7bf54667858141b591)**(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](#a0ff68001b77fed375db7e048bc5ab5f4)**(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](#a5bfedec6b19edfbcbc0a5832fff7d603)**(uint32_t timeout_ms = 10000L)
Test response to AT commands. | | int8_t | **[waitResponse](#a4416426fc61492fcb761139b85f1535b)**(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)
Listen for responses to commands and handle URCs. | | int8_t | **[waitResponse](#a5d04ca30762417cd04f0df3b620b6df7)**(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)
Listen for responses to commands and handle URCs. | | int8_t | **[waitResponse](#ac8849ac15a91800244750682561c3938)**([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)
Listen for responses to commands and handle URCs; listening for 1 second. | | String | **[getConfiguredModem](#a2f9a76aa8ef51867e560196a8261c170)**()
Gets the configured modem manufacture and model based on the compile-time traits. | | String | **[getModemInfo](#a587c942eefa8b4905da4cfaf79d04c53)**()
Asks for modem information via the 3GPP TS 27.007 standard ATI command. | | String | **[getModemName](#a500246b8d736f654ffd91db17664e42a)**()
Get the modem name - a combination of the manufacturer and model, as the modem calls itself. | | String | **[getModemManufacturer](#a3bf0eb3d18cefc70a0277103719873aa)**()
Get the modem manufacturer. | | String | **[getModemModel](#ae0ca787c0bb16776f3b326a899c39d4e)**()
Get the modem model. | | String | **[getModemRevision](#a748dce8b32f1a5d4ca0f9bf9a5ea55a2)**()
Get the modem revision information. | | String | **[getModemSerialNumber](#a3a13f308ec6beb7e2a270d1ece67978e)**()
Get the modem serial number. | | bool | **[factoryDefault](#a229a18e6a1226a51301ba3a41f75947d)**()
Reset the module to factory defaults. | ## Power functions ### Public Functions | | Name | | -------------- | -------------- | | bool | **[restart](#a986567555e19bc82fc3f4f154f89de40)**(const char * pin = nullptr)
Restart the module. | | bool | **[poweroff](#ab46d127fe8c4352aa21925e429c799d0)**()
Power off the module. | | bool | **[powerOff](#ac6d0ce36377992e00b0d38c5cb1a9126)**()
Power off the module. | | bool | **[radioOff](#a084efec47f33f71933c2084bf4c3fead)**()
Turn off the module radio. | | bool | **[sleepEnable](#ae293a3c9ef0c55ce7dbc05a29dd5c3a7)**(bool enable = true)
Enable sleep on the module. | | bool | **[setPhoneFunctionality](#a496f2e6fb026bea432f2f3d31b50d2be)**(uint8_t fun, bool reset = false)
Set the phone functionality. | ## Generic network functions ### Public Functions | | Name | | -------------- | -------------- | | regStatusType | **[getRegistrationStatus](#a75286fdda3bb1672f1c88a06d010c04d)**()
Get the modem registration status on the network. | | bool | **[isNetworkConnected](#ac6923f6667d67ec47e88a15d34d365fe)**()
Confirm whether the module is currently connected to the GSM/GPRS/LTE network. | | bool | **[waitForNetwork](#a8cdad3a71c520124dd1d5aed16ee726b)**(uint32_t timeout_ms = 60000L, bool check_signal = false)
Wait until the module has connected to the network. | | int16_t | **[getSignalQuality](#a714c21a155a823bb32a7be87fde815bd)**()
Get the signal quality report. | | String | **[getLocalIP](#a69cbe284005cf8831b0155f5ba721d87)**()
Get the Local IP address assigned to the module by the network as a String. | | IPAddress | **[localIP](#ab6aae9d6513ea9496f79704367eeff44)**()
Get the Local IP address assigned to the module by the network as an IPAddress object. | ## Utilities ### Public Functions | | Name | | -------------- | -------------- | | template
void | **[streamWrite](#aa03b38efd4eb8437c9e5ed92aac89742)**(T last)
Write a value to the modem stream. | | template
void | **[streamWrite](#a6f0a60b7020372ab7e7605f90d5eb2a5)**(T head, Args... tail)
Recursively write multiple values to the modem stream. | | void | **[streamClear](#a7879aad8a0f9def7cd8d7450800b2d64)**()
Clear the modem stream attempting to parse any URC's in it. | | void | **[streamDump](#a20ccc061bab4e038a8800c244e761ecd)**(int16_t expected_len)
Dump the modem stream, completely discarding any data in it without attempting to parse any URC's in it. | ## Public Functions Documentation ### Basic functions #### functionbegin ```cpp 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. #### functioninit ```cpp 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. #### functionsendAT ```cpp template void sendAT(Args... cmd) ``` - **Parameters**: - **cmd** The commands to send - **Template Parameters**: - **Args** #### functionsetBaud ```cpp 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. #### functionsetDefaultBaud ```cpp 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. #### functionforceModemBaud ```cpp template 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()](class_tiny_gsm_modem.md#ae4397a65939a770e478e29c718d13e59) 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. #### functiontestAT ```cpp 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. #### functionwaitResponse ```cpp 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 #### functionwaitResponse ```cpp 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 #### functionwaitResponse ```cpp 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 #### functiongetConfiguredModem ```cpp 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. #### functiongetModemInfo ```cpp String getModemInfo() ``` > [!NOTE] > The actual value and style of the response is quite varied - **Return**: Some info about the GSM module. #### functiongetModemName ```cpp String getModemName() ``` - **Return**: The modem name #### functiongetModemManufacturer ```cpp String getModemManufacturer() ``` - **Return**: The modem manufacturer #### functiongetModemModel ```cpp String getModemModel() ``` - **Return**: The modem model, as it calls itself #### functiongetModemRevision ```cpp 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 #### functiongetModemSerialNumber ```cpp String getModemSerialNumber() ``` This is usually equivalent to the IMEI for cellular modems and the MAC address for WiFi modems. - **Return**: The modem serial number #### functionfactoryDefault ```cpp bool factoryDefault() ``` This generally restarts the module as well. - **Return**: True if the module successfully reset to default, false otherwise. ### Power functions #### functionrestart ```cpp 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. #### functionpoweroff ```cpp bool poweroff() ``` **Deprecated**: [deprecated](deprecated.html#_deprecated000001) - **Deprecated**: deprecated - **Return**: True if the module was successfully powered down, false otherwise. #### functionpowerOff ```cpp bool powerOff() ``` - **Return**: True if the module was successfully powered down, false otherwise. #### functionradioOff ```cpp bool radioOff() ``` - **Return**: True if the module radio was successfully turned off, false otherwise. #### functionsleepEnable ```cpp 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. #### functionsetPhoneFunctionality ```cpp 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. ### Generic network functions #### functiongetRegistrationStatus ```cpp regStatusType getRegistrationStatus() ``` - **Return**: The modem-specific registration status value. #### functionisNetworkConnected ```cpp bool isNetworkConnected() ``` - **Return**: True if the module is connected to the network, false otherwise. #### functionwaitForNetwork ```cpp 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. #### functiongetSignalQuality ```cpp 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 #### functiongetLocalIP ```cpp String getLocalIP() ``` - **Return**: The local IP address #### functionlocalIP ```cpp IPAddress localIP() ``` - **Return**: The local IP address ### Utilities #### functionstreamWrite ```cpp template void streamWrite(T last) ``` - **Parameters**: - **last** The value to write. - **Template Parameters**: - **T** The type of the value to write. #### functionstreamWrite ```cpp template 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. #### functionstreamClear ```cpp void streamClear() ``` > [!WARNING] > Never call this inside of a [waitResponse()](class_tiny_gsm_modem.md#a4416426fc61492fcb761139b85f1535b) call or a URC parser! **Todo**: [todo](todo.html#_todo000022) #### functionstreamDump ```cpp 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](todo.html#_todo000023) - **Parameters**: - **expected_len** The number of characters to discard from the stream. ------------------------------- Generated by [Doxygen](https://www.doxygen.nl) and [m.css](https://mcss.mosra.cz/) with templates from [doxybook2](https://github.com/matusnovak/doxybook2) Updated on 2026-09-11