9static const char *
const TAG =
"sim800l";
32 ESP_LOGI(TAG,
"Connecting");
40 ESP_LOGI(TAG,
"Disconnecting");
55 buf_append_printf(delete_cmd,
sizeof(delete_cmd), 0,
"AT+CMGD=%d", this->
parse_index_);
63 ESP_LOGV(TAG,
"S: %s - %d",
message.c_str(), this->state_);
74 ESP_LOGV(TAG,
"R: %s - %d",
message.c_str(), this->state_);
77 if (message ==
"RING") {
81 }
else if (message ==
"NO CARRIER") {
98 ESP_LOGW(TAG,
"Not ack. %d %s", this->
state_, message.c_str());
105 ESP_LOGW(TAG,
"Received unexpected OK. Ignoring");
113 bool message_available =
message.compare(0, 6,
"+CMTI:") == 0;
114 if (!message_available) {
118 }
else if (message ==
"NO CARRIER") {
123 }
else if (message.compare(0, 6,
"+CUSD:") == 0) {
163 ESP_LOGD(TAG,
"SendUssd2: '%s'",
message.c_str());
166 ESP_LOGD(TAG,
"Dialing ussd code: '%s' done.", this->
ussd_.c_str());
177 ESP_LOGD(TAG,
"Check ussd code: '%s'",
message.c_str());
178 if (
message.compare(0, 6,
"+CUSD:") == 0) {
184 this->
ussd_ = message.substr(start + 1,
end - start - 2);
202 ESP_LOGD(TAG,
"Registered OK");
207 ESP_LOGW(TAG,
"Registration Fail");
225 if (message.compare(0, 5,
"+CSQ:") == 0) {
226 size_t comma =
message.find(
',', 6);
234 ESP_LOGD(TAG,
"RSSI: %d", rssi);
237 ESP_LOGD(TAG,
"RSSI: %d", rssi);
245 if (message.compare(0, 6,
"+CMGL:") == 0 && this->parse_index_ == 0) {
249 while (
end != start) {
257 this->
sender_ = message.substr(start + 1,
end - start - 2);
268 ESP_LOGD(TAG,
"Invalid message %d %s", this->
state_, message.c_str());
280 if (message.compare(0, 6,
"+CLCC:") == 0 && this->parse_index_ == 0) {
285 while (
end != start) {
292 if (current_call_state == 4) {
293 ESP_LOGV(TAG,
"Premature call state '4'. Ignoring, waiting for RING");
296 ESP_LOGD(TAG,
"Call state is now: %d", current_call_state);
297 if (current_call_state == 0)
310 ESP_LOGD(TAG,
"Invalid message %d %s", this->
state_, message.c_str());
326 if (ok ||
message.compare(0, 6,
"+CMGL:") == 0) {
328 "Received SMS from: %s\n"
330 this->
sender_.c_str(), this->message_.c_str());
348 if (message ==
">") {
350 ESP_LOGI(TAG,
"Sending to %s message: '%s'", this->
recipient_.c_str(), this->outgoing_message_.c_str());
362 if (message.compare(0, 6,
"+CMGS:") == 0) {
363 ESP_LOGD(TAG,
"SMS Sent OK: %s",
message.c_str());
375 ESP_LOGI(TAG,
"Dialing: '%s'", this->
recipient_.c_str());
385 if (message.compare(0, 6,
"+CLIP:") == 0) {
386 std::string caller_id;
390 while (
end != start) {
394 caller_id =
message.substr(start + 1,
end - start - 2);
404 ESP_LOGI(TAG,
"Incoming call from %s", caller_id.c_str());
411 ESP_LOGI(TAG,
"Call connected");
419 ESP_LOGW(TAG,
"Unhandled: %s - %d",
message.c_str(), this->state_);
433 ESP_LOGVV(TAG,
"Buffer pos: %u %d", this->
read_pos_,
byte);
435 if (
byte == ASCII_CR)
466 ESP_LOGD(TAG,
"Sending USSD code: %s", ussd_code.c_str());
467 this->
ussd_ = ussd_code;
472 ESP_LOGCONFIG(TAG,
"SIM800L:");
473#ifdef USE_BINARY_SENSOR
489#ifdef USE_BINARY_SENSOR
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_
char read_buffer_[SIM800L_READ_BUFFER_LENGTH]
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.
void parse_cmd_(std::string message)
CallbackManager< void()> call_disconnected_callback_
void dial(const std::string &recipient)
std::string outgoing_message_
void send_ussd(const std::string &ussd_code)
void write_str(const char *str)
bool read_byte(uint8_t *data)
void write_byte(uint8_t data)
size_t write(uint8_t data)
@ STATE_PARSE_SMS_RESPONSE
const uint16_t SIM800L_READ_BUFFER_LENGTH
Providing packet encoding functions for exchanging data with a remote host.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.