ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
sim800l.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
7#ifdef USE_BINARY_SENSOR
9#endif
10#ifdef USE_SENSOR
12#endif
16
17namespace esphome::sim800l {
18
19const uint16_t SIM800L_READ_BUFFER_LENGTH = 1024;
20
51
53 public:
55 void update() override;
56 void loop() override;
57 void dump_config() override;
58#ifdef USE_BINARY_SENSOR
60 registered_binary_sensor_ = registered_binary_sensor;
61 }
62#endif
63#ifdef USE_SENSOR
64 void set_rssi_sensor(sensor::Sensor *rssi_sensor) { rssi_sensor_ = rssi_sensor; }
65#endif
66 template<typename F> void add_on_sms_received_callback(F &&callback) {
67 this->sms_received_callback_.add(std::forward<F>(callback));
68 }
69 template<typename F> void add_on_incoming_call_callback(F &&callback) {
70 this->incoming_call_callback_.add(std::forward<F>(callback));
71 }
72 template<typename F> void add_on_call_connected_callback(F &&callback) {
73 this->call_connected_callback_.add(std::forward<F>(callback));
74 }
75 template<typename F> void add_on_call_disconnected_callback(F &&callback) {
76 this->call_disconnected_callback_.add(std::forward<F>(callback));
77 }
78 template<typename F> void add_on_ussd_received_callback(F &&callback) {
79 this->ussd_received_callback_.add(std::forward<F>(callback));
80 }
81 template<typename F> void add_on_dtmf_received_callback(F &&callback) {
82 // DTMF detection is only enabled on the module when someone listens for it
83 this->dtmf_enabled_ = true;
84 this->dtmf_received_callback_.add(std::forward<F>(callback));
85 }
86 void send_sms(const std::string &recipient, const std::string &message);
87 void send_ussd(const std::string &ussd_code);
88 void dial(const std::string &recipient);
89 void connect();
90 void disconnect();
91
92 protected:
93 void send_cmd_(const std::string &message);
94 void parse_cmd_(std::string message);
95 void set_registered_(bool registered);
96
97#ifdef USE_BINARY_SENSOR
99#endif
100
101#ifdef USE_SENSOR
103#endif
104 std::string sender_;
105 std::string message_;
107 uint8_t parse_index_{0};
108 uint8_t watch_dog_{0};
109 bool expect_ack_{false};
111 bool registered_{false};
112
113 std::string recipient_;
114 std::string outgoing_message_;
115 std::string ussd_;
116 bool send_pending_{false};
117 bool dial_pending_{false};
118 bool connect_pending_{false};
121 bool dtmf_enabled_{false};
122 bool dtmf_ready_{false};
123 uint8_t call_state_{6};
124
125 CallbackManager<void(std::string, std::string)> sms_received_callback_;
131};
132
133} // namespace esphome::sim800l
Collects bytes into NUL terminated lines of up to N - 1 characters; IGNORE_CHAR bytes are skipped and...
Definition line_reader.h:15
This class simplifies creating components that periodically check a state.
Definition component.h:519
Base class for all binary_sensor-type classes.
Base-class for all sensors.
Definition sensor.h:47
void add_on_call_disconnected_callback(F &&callback)
Definition sim800l.h:75
CallbackManager< void(std::string)> ussd_received_callback_
Definition sim800l.h:129
void add_on_sms_received_callback(F &&callback)
Definition sim800l.h:66
void send_cmd_(const std::string &message)
Definition sim800l.cpp:63
CallbackManager< void(std::string, std::string)> sms_received_callback_
Definition sim800l.h:125
void add_on_dtmf_received_callback(F &&callback)
Definition sim800l.h:81
void add_on_ussd_received_callback(F &&callback)
Definition sim800l.h:78
CallbackManager< void(std::string)> incoming_call_callback_
Definition sim800l.h:126
binary_sensor::BinarySensor * registered_binary_sensor_
Definition sim800l.h:98
CallbackManager< void()> call_connected_callback_
Definition sim800l.h:127
void set_registered_(bool registered)
Definition sim800l.cpp:506
void add_on_incoming_call_callback(F &&callback)
Definition sim800l.h:69
void send_sms(const std::string &recipient, const std::string &message)
Definition sim800l.cpp:478
void update() override
Retrieve the latest sensor values. This operation takes approximately 16ms.
Definition sim800l.cpp:13
CallbackManager< void(std::string)> dtmf_received_callback_
Definition sim800l.h:130
void add_on_call_connected_callback(F &&callback)
Definition sim800l.h:72
void set_rssi_sensor(sensor::Sensor *rssi_sensor)
Definition sim800l.h:64
void parse_cmd_(std::string message)
Definition sim800l.cpp:71
CallbackManager< void()> call_disconnected_callback_
Definition sim800l.h:128
void dial(const std::string &recipient)
Definition sim800l.cpp:499
LineReader< SIM800L_READ_BUFFER_LENGTH > line_reader_
Definition sim800l.h:106
void send_ussd(const std::string &ussd_code)
Definition sim800l.cpp:484
void set_registered_binary_sensor(binary_sensor::BinarySensor *registered_binary_sensor)
Definition sim800l.h:59
const LogString * message
Definition component.cpp:35
@ STATE_PARSE_SMS_RESPONSE
Definition sim800l.h:34
const uint16_t SIM800L_READ_BUFFER_LENGTH
Definition sim800l.h:19