33 ESP_LOGI(TAG,
"Connecting");
41 ESP_LOGI(TAG,
"Disconnecting");
56 buf_append_printf(delete_cmd,
sizeof(delete_cmd), 0,
"AT+CMGD=%d", this->
parse_index_);
64 ESP_LOGV(TAG,
"S: %s - %d",
message.c_str(), this->state_);
75 ESP_LOGV(TAG,
"R: %s - %d",
message.c_str(), this->state_);
78 if (message ==
"RING") {
82 }
else if (message ==
"NO CARRIER") {
87 }
else if (message.starts_with(
"+DTMF:")) {
89 size_t start =
message.find_first_not_of(
' ', 6);
90 if (start != std::string::npos) {
92 ESP_LOGD(TAG,
"DTMF received: %s",
key.c_str());
108 if (message !=
"ERROR" && !
message.starts_with(
"+CME ERROR:")) {
114 ESP_LOGW(TAG,
"DTMF detection not supported by the module: %s",
message.c_str());
116 ESP_LOGW(TAG,
"Not ack. %d %s", this->
state_, message.c_str());
123 ESP_LOGW(TAG,
"Received unexpected OK. Ignoring");
131 bool message_available =
message.starts_with(
"+CMTI:");
132 if (!message_available) {
136 }
else if (message ==
"NO CARRIER") {
141 }
else if (message.starts_with(
"+CUSD:")) {
186 ESP_LOGD(TAG,
"SendUssd2: '%s'",
message.c_str());
189 ESP_LOGD(TAG,
"Dialing ussd code: '%s' done.", this->
ussd_.c_str());
200 ESP_LOGD(TAG,
"Check ussd code: '%s'",
message.c_str());
201 if (
message.starts_with(
"+CUSD:")) {
207 this->
ussd_ = message.substr(start + 1,
end - start - 2);
230 ESP_LOGD(TAG,
"Registered OK");
235 ESP_LOGW(TAG,
"Registration Fail");
253 if (message.starts_with(
"+CSQ:")) {
254 size_t comma =
message.find(
',', 6);
262 ESP_LOGD(TAG,
"RSSI: %d", rssi);
265 ESP_LOGD(TAG,
"RSSI: %d", rssi);
273 if (message.starts_with(
"+CMGL:") && this->parse_index_ == 0) {
277 while (
end != start) {
285 this->
sender_ = message.substr(start + 1,
end - start - 2);
296 ESP_LOGD(TAG,
"Invalid message %d %s", this->
state_, message.c_str());
308 if (message.starts_with(
"+CLCC:") && this->parse_index_ == 0) {
313 while (
end != start) {
320 if (current_call_state == 4) {
321 ESP_LOGV(TAG,
"Premature call state '4'. Ignoring, waiting for RING");
324 ESP_LOGD(TAG,
"Call state is now: %d", current_call_state);
325 if (current_call_state == 0)
338 ESP_LOGD(TAG,
"Invalid message %d %s", this->
state_, message.c_str());
354 if (ok ||
message.starts_with(
"+CMGL:")) {
356 "Received SMS from: %s\n"
358 this->
sender_.c_str(), this->message_.c_str());
376 if (message ==
">") {
378 ESP_LOGI(TAG,
"Sending to %s message: '%s'", this->
recipient_.c_str(), this->outgoing_message_.c_str());
390 if (message.starts_with(
"+CMGS:")) {
391 ESP_LOGD(TAG,
"SMS Sent OK: %s",
message.c_str());
403 ESP_LOGI(TAG,
"Dialing: '%s'", this->
recipient_.c_str());
413 if (message.starts_with(
"+CLIP:")) {
414 std::string caller_id;
418 while (
end != start) {
422 caller_id =
message.substr(start + 1,
end - start - 2);
432 ESP_LOGI(TAG,
"Incoming call from %s", caller_id.c_str());
439 ESP_LOGI(TAG,
"Call connected");
447 ESP_LOGW(TAG,
"Unhandled: %s - %d",
message.c_str(), this->state_);
465 if (line !=
nullptr) {
485 ESP_LOGD(TAG,
"Sending USSD code: %s", ussd_code.c_str());
486 this->
ussd_ = ussd_code;
491 ESP_LOGCONFIG(TAG,
"SIM800L:");
492#ifdef USE_BINARY_SENSOR
508#ifdef USE_BINARY_SENSOR
const char * partial()
The partial line, NUL terminated, for prompts with no line end; the first N - 1 characters on the byt...
size_t length() const
Length of the partial line; 0 after a line is returned and while an overlong line is dropped.
char * feed(uint8_t c)
Feed one byte; returns the completed line (empty lines included), valid until the next call,...
void reset()
Forget the partial line and start a new one with the next byte.
void log_if_overflowed(const char *tag) const
Log the shared "line dropped" warning when the last feed() overflowed.
void publish_state(bool new_state)
Publish a new state to the front-end.
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * rssi_sensor_
CallbackManager< void(std::string)> ussd_received_callback_
void send_cmd_(const std::string &message)
CallbackManager< void(std::string, std::string)> sms_received_callback_
CallbackManager< void(std::string)> incoming_call_callback_
binary_sensor::BinarySensor * registered_binary_sensor_
CallbackManager< void()> call_connected_callback_
void dump_config() override
void set_registered_(bool registered)
void send_sms(const std::string &recipient, const std::string &message)
void update() override
Retrieve the latest sensor values. This operation takes approximately 16ms.
CallbackManager< void(std::string)> dtmf_received_callback_
void parse_cmd_(std::string message)
CallbackManager< void()> call_disconnected_callback_
void dial(const std::string &recipient)
LineReader< SIM800L_READ_BUFFER_LENGTH > line_reader_
std::string outgoing_message_
void send_ussd(const std::string &ussd_code)
void write_str(const char *str)
void write_byte(uint8_t data)
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
size_t write(uint8_t data)
const LogString * message
@ STATE_PARSE_SMS_RESPONSE
ESPHOME_LOG_TAG(TAG, "sim800l")
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.