ESPHome 2026.11.0
Loading...
Searching...
No Matches
esphome::modem Namespace Reference

Data Structures

class  ModemComponent
 

Typedefs

using DceFactory
 

Enumerations

enum class  ReplyEnd : uint8_t { REPLY_END_NONE , REPLY_END_OK , REPLY_END_ERROR }
 
enum class  ModemState : uint8_t {
  MODEM_STATE_DISABLED , MODEM_STATE_ENABLING , MODEM_STATE_SYNCED , MODEM_STATE_CONNECTING ,
  MODEM_STATE_WAIT_IP , MODEM_STATE_CONNECTED , MODEM_STATE_DISCONNECTING
}
 
enum class  ConnectStep : uint8_t { CONNECT_STEP_START , CONNECT_STEP_RADIO_ON , CONNECT_STEP_ATTACH_REQUESTED }
 
enum class  SimResult : uint8_t { SIM_RESULT_READY , SIM_RESULT_RETRY , SIM_RESULT_LOCKED , SIM_RESULT_HALT }
 
enum class  ModemFault : uint8_t {
  MODEM_FAULT_NONE , MODEM_FAULT_NO_RESPONSE , MODEM_FAULT_BAUD , MODEM_FAULT_INIT_AT ,
  MODEM_FAULT_SIM_NOT_READY , MODEM_FAULT_SIM_LOCKED , MODEM_FAULT_PIN_NOT_SENT , MODEM_FAULT_PIN_RECORD ,
  MODEM_FAULT_SETUP , MODEM_FAULT_NOT_ATTACHED , MODEM_FAULT_REGISTRATION_DENIED , MODEM_FAULT_PPP ,
  MODEM_FAULT_TEARDOWN
}
 
enum class  PinStep : uint8_t { PIN_STEP_IDLE , PIN_STEP_SAVING , PIN_STEP_SENT }
 
enum class  PinSave : uint8_t { PIN_SAVE_DONE , PIN_SAVE_PENDING , PIN_SAVE_FAILED }
 

Functions

bool collect_reply (char *buf, size_t size, size_t &len, const char *data, size_t data_len, bool whole)
 Add data to the reply in buf (size includes the terminator, len is the current length).
 
ReplyEnd reply_end (const char *data, size_t len, bool skip_first)
 How the reply ends.
 
size_t flatten_reply (char *reply, size_t len)
 Puts a raw reply on one line for the log and drops the final OK; returns the new length.
 
int registration_from_reply (const char *reply, const char *prefix)
 The <stat> after the first comma of the "<n>,<stat>" line starting with prefix (+CREG: and friends), or REGISTRATION_UNKNOWN; a one-field line is an unsolicited notification and is skipped.
 
int merge_registration (int lte, int legacy)
 The state that tells most from the AT+CEREG? (LTE) and AT+CREG? (2G and 3G) results.
 
bool reply_names_unsupported (const char *reply)
 Whether an error reply says the command is not supported (+CME ERROR: 4 or its verbose text)
 
const char * sim_status (char *reply)
 The SIM status in a flattened AT+CPIN? reply, cut before any following line, or nullptr.
 
bool is_registered (int registration)
 Registered on a network, so the data attach can be requested.
 
 ESPHOME_LOG_TAG (TAG, "modem")
 
 PROGMEM_STRING_TABLE (ModemStateStrings, "DISABLED", "ENABLING", "SYNCED", "CONNECTING", "WAIT_IP", "CONNECTED", "DISCONNECTING", "UNKNOWN")
 
 PROGMEM_STRING_TABLE (ModemFaultStrings, "", "Modem not responding", "Configured baud rate failed", "init_at command failed", "SIM not ready", "SIM locked", "SIM PIN not sent; check pin_code", "PIN record not saved", "APN or radio setup failed", "No network attachment", "Network registration denied", "PPP link failed", "Modem teardown failed")
 
 PROGMEM_STRING_TABLE (RegistrationStrings, "not searching", "registered", "searching", "denied", "unknown", "roaming", "registered for SMS only", "roaming for SMS only", "emergency only", "registered, CSFB not preferred", "roaming, CSFB not preferred", "other")
 
 PROGMEM_STRING_TABLE (CommandResultStrings, "OK", "FAIL", "TIMEOUT")
 
 PROGMEM_STRING_TABLE (NetworkModeStrings, "No service", "GSM", "GPRS", "EDGE", "WCDMA", "HSDPA", "HSUPA", "HSPA", "LTE", "Unknown")
 

Variables

ModemComponent * global_modem_component = nullptr
 

Typedef Documentation

◆ DceFactory

Initial value:
std::unique_ptr<esp_modem::DCE> (*)(const esp_modem::dce_config *, std::shared_ptr<esp_modem::DTE>,
struct esp_netif_obj esp_netif_t

Definition at line 86 of file modem_component.h.

Enumeration Type Documentation

◆ ConnectStep

enum class esphome::modem::ConnectStep : uint8_t
strong
Enumerator
CONNECT_STEP_START 
CONNECT_STEP_RADIO_ON 
CONNECT_STEP_ATTACH_REQUESTED 

Definition at line 40 of file modem_component.h.

◆ ModemFault

enum class esphome::modem::ModemFault : uint8_t
strong
Enumerator
MODEM_FAULT_NONE 
MODEM_FAULT_NO_RESPONSE 
MODEM_FAULT_BAUD 
MODEM_FAULT_INIT_AT 
MODEM_FAULT_SIM_NOT_READY 
MODEM_FAULT_SIM_LOCKED 
MODEM_FAULT_PIN_NOT_SENT 
MODEM_FAULT_PIN_RECORD 
MODEM_FAULT_SETUP 
MODEM_FAULT_NOT_ATTACHED 
MODEM_FAULT_REGISTRATION_DENIED 
MODEM_FAULT_PPP 
MODEM_FAULT_TEARDOWN 

Definition at line 54 of file modem_component.h.

◆ ModemState

enum class esphome::modem::ModemState : uint8_t
strong
Enumerator
MODEM_STATE_DISABLED 
MODEM_STATE_ENABLING 
MODEM_STATE_SYNCED 
MODEM_STATE_CONNECTING 
MODEM_STATE_WAIT_IP 
MODEM_STATE_CONNECTED 
MODEM_STATE_DISCONNECTING 

Definition at line 29 of file modem_component.h.

◆ PinSave

enum class esphome::modem::PinSave : uint8_t
strong
Enumerator
PIN_SAVE_DONE 
PIN_SAVE_PENDING 
PIN_SAVE_FAILED 

Definition at line 78 of file modem_component.h.

◆ PinStep

enum class esphome::modem::PinStep : uint8_t
strong
Enumerator
PIN_STEP_IDLE 
PIN_STEP_SAVING 
PIN_STEP_SENT 

Definition at line 71 of file modem_component.h.

◆ ReplyEnd

enum class esphome::modem::ReplyEnd : uint8_t
strong
Enumerator
REPLY_END_NONE 
REPLY_END_OK 
REPLY_END_ERROR 

Definition at line 9 of file at_reply.h.

◆ SimResult

enum class esphome::modem::SimResult : uint8_t
strong
Enumerator
SIM_RESULT_READY 
SIM_RESULT_RETRY 
SIM_RESULT_LOCKED 
SIM_RESULT_HALT 

Definition at line 46 of file modem_component.h.

Function Documentation

◆ collect_reply()

bool esphome::modem::collect_reply ( char * buf,
size_t size,
size_t & len,
const char * data,
size_t data_len,
bool whole )

Add data to the reply in buf (size includes the terminator, len is the current length).

With whole, data is everything received so far (UART) and replaces the reply; otherwise it is one new CMUX frame and is appended. A reply longer than the buffer keeps its newest bytes, where the final line is. Returns true when bytes were dropped.

Definition at line 10 of file at_reply.cpp.

◆ ESPHOME_LOG_TAG()

esphome::modem::ESPHOME_LOG_TAG ( TAG ,
"modem"  )

◆ flatten_reply()

size_t esphome::modem::flatten_reply ( char * reply,
size_t len )

Puts a raw reply on one line for the log and drops the final OK; returns the new length.

Definition at line 63 of file at_reply.cpp.

◆ is_registered()

bool esphome::modem::is_registered ( int registration)
inline

Registered on a network, so the data attach can be requested.

SMS only and "CSFB not preferred" limit the circuit switched side, not the packet data attach; emergency only (8) is not a registration.

Definition at line 34 of file at_reply.h.

◆ merge_registration()

int esphome::modem::merge_registration ( int lte,
int legacy )

The state that tells most from the AT+CEREG? (LTE) and AT+CREG? (2G and 3G) results.

Definition at line 106 of file at_reply.cpp.

◆ PROGMEM_STRING_TABLE() [1/5]

esphome::modem::PROGMEM_STRING_TABLE ( CommandResultStrings ,
"OK" ,
"FAIL" ,
"TIMEOUT"  )

◆ PROGMEM_STRING_TABLE() [2/5]

esphome::modem::PROGMEM_STRING_TABLE ( ModemFaultStrings ,
"" ,
"Modem not responding" ,
"Configured baud rate failed" ,
"init_at command failed" ,
"SIM not ready" ,
"SIM locked" ,
"SIM PIN not sent; check pin_code" ,
"PIN record not saved" ,
"APN or radio setup failed" ,
"No network attachment" ,
"Network registration denied" ,
"PPP link failed" ,
"Modem teardown failed"  )

◆ PROGMEM_STRING_TABLE() [3/5]

esphome::modem::PROGMEM_STRING_TABLE ( ModemStateStrings ,
"DISABLED" ,
"ENABLING" ,
"SYNCED" ,
"CONNECTING" ,
"WAIT_IP" ,
"CONNECTED" ,
"DISCONNECTING" ,
"UNKNOWN"  )

◆ PROGMEM_STRING_TABLE() [4/5]

esphome::modem::PROGMEM_STRING_TABLE ( NetworkModeStrings ,
"No service" ,
"GSM" ,
"GPRS" ,
"EDGE" ,
"WCDMA" ,
"HSDPA" ,
"HSUPA" ,
"HSPA" ,
"LTE" ,
"Unknown"  )

◆ PROGMEM_STRING_TABLE() [5/5]

esphome::modem::PROGMEM_STRING_TABLE ( RegistrationStrings ,
"not searching" ,
"registered" ,
"searching" ,
"denied" ,
"unknown" ,
"roaming" ,
"registered for SMS only" ,
"roaming for SMS only" ,
"emergency only" ,
" registered,
CSFB not preferred" ,
" roaming,
CSFB not preferred" ,
"other"  )

◆ registration_from_reply()

int esphome::modem::registration_from_reply ( const char * reply,
const char * prefix )

The <stat> after the first comma of the "<n>,<stat>" line starting with prefix (+CREG: and friends), or REGISTRATION_UNKNOWN; a one-field line is an unsolicited notification and is skipped.

Definition at line 88 of file at_reply.cpp.

◆ reply_end()

ReplyEnd esphome::modem::reply_end ( const char * data,
size_t len,
bool skip_first )

How the reply ends.

Only a complete final result line counts, so ERROR inside a payload line does not; a +CME ERROR line counts even without its reason, which a dropped CMUX frame can take away. With skip_first, the first line is a cut-off fragment and is ignored.

Definition at line 34 of file at_reply.cpp.

◆ reply_names_unsupported()

bool esphome::modem::reply_names_unsupported ( const char * reply)

Whether an error reply says the command is not supported (+CME ERROR: 4 or its verbose text)

Definition at line 133 of file at_reply.cpp.

◆ sim_status()

const char * esphome::modem::sim_status ( char * reply)

The SIM status in a flattened AT+CPIN? reply, cut before any following line, or nullptr.

Definition at line 147 of file at_reply.cpp.

Variable Documentation

◆ global_modem_component

ModemComponent * esphome::modem::global_modem_component = nullptr

Definition at line 39 of file modem_component.cpp.