ESPHome 2026.10.2
Loading...
Searching...
No Matches
nextion.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <vector>
5
11#include "esphome/core/time.h"
12
13#ifdef USE_NEXTION_WAVEFORM
15#endif // USE_NEXTION_WAVEFORM
16
17#include "nextion_base.h"
18#include "nextion_component.h"
19
20#ifdef USE_NEXTION_TFT_UPLOAD
21#ifdef USE_ESP32
22#include <esp_http_client.h>
23#elif defined(USE_ESP8266)
24#include <ESP8266HTTPClient.h>
25#include <WiFiClientSecure.h>
26#elif defined(USE_LIBRETINY)
27#include <HTTPClient.h>
28#endif // USE_ESP32 vs USE_ESP8266 vs USE_LIBRETINY
29#endif // USE_NEXTION_TFT_UPLOAD
30
31namespace esphome::nextion {
32
33class Nextion;
34class NextionComponentBase;
35
37
38#ifdef USE_NEXTION_COMMAND_SPACING
40 public:
45 explicit NextionCommandPacer(uint8_t initial_spacing = 0) : spacing_ms_(initial_spacing) {}
46
51 void set_spacing(uint8_t spacing_ms) { spacing_ms_ = spacing_ms; }
52
57 uint8_t get_spacing() const { return spacing_ms_; }
58
65 bool can_send(uint32_t now) const { return (now - last_command_time_) >= spacing_ms_; }
66
73 void mark_sent(uint32_t now) { last_command_time_ = now; }
74
75 private:
76 uint8_t spacing_ms_;
77 uint32_t last_command_time_{0};
78};
79#endif // USE_NEXTION_COMMAND_SPACING
80
81class Nextion final : public NextionBase, public PollingComponent, public uart::UARTDevice {
82 public:
83#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
91 inline void set_max_commands_per_loop(uint16_t value) { this->max_commands_per_loop_ = value; }
92
97 inline uint16_t get_max_commands_per_loop() const { return this->max_commands_per_loop_; }
98#endif // USE_NEXTION_MAX_COMMANDS_PER_LOOP
99#ifdef USE_NEXTION_MAX_QUEUE_SIZE
104 inline void set_max_queue_size(size_t size) { this->max_queue_size_ = size; }
105
110 inline size_t get_max_queue_size() const { return this->max_queue_size_; }
111#endif // USE_NEXTION_MAX_QUEUE_SIZE
112
113#ifdef USE_NEXTION_COMMAND_SPACING
118 void set_command_spacing(uint32_t spacing_ms) { this->command_pacer_.set_spacing(spacing_ms); }
119#endif // USE_NEXTION_COMMAND_SPACING
120
133 void set_component_text(const char *component, const char *text);
134
150 void set_component_text_printf(const char *component, const char *format, ...) __attribute__((format(printf, 3, 4)));
151
164 void set_component_value(const char *component, int32_t value);
165
178 void set_component_picture(const char *component, uint8_t picture_id) { set_component_picc(component, picture_id); };
179
194 void set_component_background_color(const char *component, uint16_t color);
195
209 void set_component_background_color(const char *component, const char *color);
210
224 void set_component_background_color(const char *component, Color color) override;
225
241 void set_component_pressed_background_color(const char *component, uint16_t color);
242
257 void set_component_pressed_background_color(const char *component, const char *color);
258
273 void set_component_pressed_background_color(const char *component, Color color) override;
274
289 void set_component_foreground_color(const char *component, uint16_t color);
290
304 void set_component_foreground_color(const char *component, const char *color);
305
318 void set_component_foreground_color(const char *component, Color color) override;
319
335 void set_component_pressed_foreground_color(const char *component, uint16_t color);
336
351 void set_component_pressed_foreground_color(const char *component, const char *color);
352
367 void set_component_pressed_foreground_color(const char *component, Color color) override;
368
381 void set_component_pic(const char *component, uint16_t pic_id);
382
395 void set_component_picc(const char *component, uint16_t pic_id);
396
411 void set_component_font_color(const char *component, uint16_t color);
412
426 void set_component_font_color(const char *component, const char *color);
427
440 void set_component_font_color(const char *component, Color color) override;
441
456 void set_component_pressed_font_color(const char *component, uint16_t color);
457
471 void set_component_pressed_font_color(const char *component, const char *color);
472
485 void set_component_pressed_font_color(const char *component, Color color) override;
486
500 void set_component_coordinates(const char *component, uint16_t x, uint16_t y);
501
514 void set_component_font(const char *component, uint8_t font_id) override;
515
520 void set_nextion_rtc_time(ESPTime time);
521
533 void goto_page(const char *page);
534
546 void goto_page(uint8_t page);
547
563 void set_component_visibility(const char *component, bool show) override;
564
576 void hide_component(const char *component) override;
577
589 void show_component(const char *component) override;
590
602 void enable_component_touch(const char *component);
603
615 void disable_component_touch(const char *component);
616
623 void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value);
624
625 void open_waveform_channel(uint8_t component_id, uint8_t channel_number, uint8_t value);
626
640 void display_picture(uint16_t picture_id, uint16_t x_start, uint16_t y_start);
641
660 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
661
679 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, const char *color);
680
698 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, Color color);
699
718 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
719
737 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, const char *color);
738
756 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, Color color);
757
776 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
777
795 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, const char *color);
796
814 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, Color color);
815
825 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
826
835 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, const char *color);
836
844 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, Color color);
845
862 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
863
879 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, const char *color);
880
896 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, Color color);
897
916 void qrcode(uint16_t x1, uint16_t y1, const char *content, uint16_t size = 200, uint16_t background_color = 65535,
917 uint16_t foreground_color = 0, int32_t logo_pic = -1, uint8_t border_width = 8);
918
940 void qrcode(uint16_t x1, uint16_t y1, const char *content, uint16_t size,
941 Color background_color = Color(255, 255, 255), Color foreground_color = Color(0, 0, 0),
942 int32_t logo_pic = -1, uint8_t border_width = 8);
943
955 void set_backlight_brightness(float brightness);
956
961 void sleep(bool sleep);
962
982
983 // ======== Nextion Intelligent Series ========
984
999 void set_component_vid(const char *component, uint8_t vid_id);
1000
1015 void set_component_drag(const char *component, bool drag);
1016
1031 void set_component_aph(const char *component, uint8_t aph);
1032
1049
1050 // ========== INTERNAL METHODS ==========
1051 // (In most use cases you won't need these)
1052 void register_touch_component(NextionComponentBase *obj) { this->touch_.push_back(obj); }
1057
1058 void setup() override;
1059 void set_brightness(float brightness) { this->brightness_ = brightness; }
1060 void update() override;
1061 void loop() override;
1062 void set_writer(const nextion_writer_t &writer);
1063
1064 // This function has been deprecated
1065 void set_wait_for_ack(bool wait_for_ack);
1066
1072 bool send_command(const char *command);
1073
1080 bool send_command_printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
1081
1082#ifdef USE_NEXTION_TFT_UPLOAD
1087 void set_tft_upload_http_timeout(uint16_t timeout_ms) { this->tft_upload_http_timeout_ = timeout_ms; }
1088
1089#ifdef USE_ESP32
1102#endif // USE_ESP32
1103
1108 void set_tft_upload_http_retries(uint8_t retries) { this->tft_upload_http_retries_ = retries; }
1109
1113 void set_tft_url(const std::string &tft_url) { this->tft_url_ = tft_url; }
1114
1135 bool upload_tft(uint32_t baud_rate = 0, bool exit_reparse = true);
1136
1137#endif // USE_NEXTION_TFT_UPLOAD
1138
1139 void dump_config() override;
1140
1144 void soft_reset();
1145
1150 template<typename F> void add_sleep_state_callback(F &&callback) {
1151 this->sleep_callback_.add(std::forward<F>(callback));
1152 }
1153
1158 template<typename F> void add_wake_state_callback(F &&callback) {
1159 this->wake_callback_.add(std::forward<F>(callback));
1160 }
1161
1166 template<typename F> void add_setup_state_callback(F &&callback) {
1167 this->setup_callback_.add(std::forward<F>(callback));
1168 }
1169
1174 template<typename F> void add_new_page_callback(F &&callback) { this->page_callback_.add(std::forward<F>(callback)); }
1175
1180 template<typename F> void add_touch_event_callback(F &&callback) {
1181 this->touch_callback_.add(std::forward<F>(callback));
1182 }
1183
1188 template<typename F> void add_buffer_overflow_event_callback(F &&callback) {
1189 this->buffer_overflow_callback_.add(std::forward<F>(callback));
1190 }
1191
1192 // Callbacks for Nextion "custom protocol" frames (0x90..0x93)
1193#ifdef USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1201 template<typename F> void add_custom_binary_sensor_callback(F &&callback) {
1202 this->custom_binary_sensor_callback_.add(std::forward<F>(callback));
1203 }
1204#endif // USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1205
1206#ifdef USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1214 template<typename F> void add_custom_sensor_callback(F &&callback) {
1215 this->custom_sensor_callback_.add(std::forward<F>(callback));
1216 }
1217#endif // USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1218
1219#ifdef USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1227 template<typename F> void add_custom_switch_callback(F &&callback) {
1228 this->custom_switch_callback_.add(std::forward<F>(callback));
1229 }
1230#endif // USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1231
1232#ifdef USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1240 template<typename F> void add_custom_text_sensor_callback(F &&callback) {
1241 this->custom_text_sensor_callback_.add(std::forward<F>(callback));
1242 }
1243#endif // USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1244
1246
1259 void set_nextion_sensor_state(int queue_type, const std::string &name, float state);
1260 void set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state);
1261 void set_nextion_text_state(const std::string &name, const std::string &state);
1262
1264 void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send,
1265 int32_t state_value) override;
1266
1267 void add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) override;
1268 void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send,
1269 const std::string &state_value) override;
1270
1272
1273#ifdef USE_NEXTION_WAVEFORM
1275#endif // USE_NEXTION_WAVEFORM
1276
1277 void update_components_by_prefix(const std::string &prefix);
1278
1312 void set_touch_sleep_timeout(uint16_t touch_sleep_timeout = 0);
1313
1326 void set_wake_up_page(uint8_t wake_up_page = 255);
1327
1328#ifdef USE_NEXTION_CONF_START_UP_PAGE
1341 void set_start_up_page(uint8_t start_up_page = 255) { this->start_up_page_ = start_up_page; }
1342#endif // USE_NEXTION_CONF_START_UP_PAGE
1343
1356 void set_auto_wake_on_touch(bool auto_wake_on_touch);
1357
1371 size_t queue_size() { return this->nextion_queue_.size(); }
1372
1391 bool is_updating() override;
1392
1410 bool is_connected() { return this->connection_state_.is_connected_; }
1411
1416 inline void set_max_queue_age(uint16_t age_ms) { this->max_q_age_ms_ = age_ms; }
1417
1422 inline uint16_t get_max_queue_age() const { return this->max_q_age_ms_; }
1423
1428 inline void set_startup_override_ms(uint16_t timeout_ms) { this->startup_override_ms_ = timeout_ms; }
1429
1434 inline uint16_t get_startup_override_ms() const { return this->startup_override_ms_; }
1435
1436 protected:
1437#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
1439#endif // USE_NEXTION_MAX_COMMANDS_PER_LOOP
1440#ifdef USE_NEXTION_MAX_QUEUE_SIZE
1442#endif // USE_NEXTION_MAX_QUEUE_SIZE
1443
1444#ifdef USE_NEXTION_COMMAND_SPACING
1446
1458#endif // USE_NEXTION_COMMAND_SPACING
1459
1460 std::list<NextionQueue *> nextion_queue_;
1461#ifdef USE_NEXTION_WAVEFORM
1465#endif // USE_NEXTION_WAVEFORM
1466 uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag);
1467 void all_components_send_state_(bool force_update = false);
1469 bool remove_from_q_(bool report_empty = true);
1471 NextionQueue *make_no_result_entry_(const std::string &variable_name);
1472
1479 struct {
1480 uint8_t is_connected_ : 1;
1482 uint8_t ignore_is_setup_ : 1;
1484 uint8_t is_updating_ : 1;
1486 uint8_t reserved_ : 2;
1488
1496 uint8_t wake_up_page_ = 255;
1497#ifdef USE_NEXTION_CONF_START_UP_PAGE
1498 uint8_t start_up_page_ = 255;
1499#endif // USE_NEXTION_CONF_START_UP_PAGE
1501
1506 bool send_command_(const std::string &command);
1507 void add_no_result_to_queue_(const std::string &variable_name);
1508 bool add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format, ...)
1509 __attribute__((format(printf, 3, 4)));
1510 void add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command);
1511
1512#ifdef USE_NEXTION_COMMAND_SPACING
1526 void add_no_result_to_queue_with_pending_command_(const std::string &variable_name, const std::string &command);
1527#endif // USE_NEXTION_COMMAND_SPACING
1528
1529 bool add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format, ...)
1530 __attribute__((format(printf, 3, 4)));
1531
1532 void add_no_result_to_queue_with_set_internal_(const std::string &variable_name,
1533 const std::string &variable_name_to_send, int32_t state_value,
1534 bool is_sleep_safe = false);
1535
1536 void add_no_result_to_queue_with_set_internal_(const std::string &variable_name,
1537 const std::string &variable_name_to_send,
1538 const std::string &state_value, bool is_sleep_safe = false);
1539
1540#ifdef USE_NEXTION_WAVEFORM
1542#endif // USE_NEXTION_WAVEFORM
1543
1544#ifdef USE_NEXTION_TFT_UPLOAD
1545#ifdef USE_ESP8266
1546 WiFiClient *wifi_client_{nullptr};
1547 BearSSL::WiFiClientSecure *wifi_client_secure_{nullptr};
1548 WiFiClient *get_wifi_client_();
1549#endif // USE_ESP8266
1550 std::string tft_url_;
1552 int tft_size_ = 0;
1557
1558#ifdef USE_ESP32
1560
1568 int upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &range_start);
1569#elif defined(USE_ESP8266) || defined(USE_LIBRETINY)
1577 int upload_by_chunks_(HTTPClient &http_client, uint32_t &range_start);
1578#endif // USE_ESP32 vs USE_ESP8266/USE_LIBRETINY
1579
1586 bool upload_end_(bool successful);
1587
1588#endif // USE_NEXTION_TFT_UPLOAD
1589
1591
1592 std::vector<NextionComponentBase *> touch_;
1593 std::vector<NextionComponentBase *> switchtype_;
1594 std::vector<NextionComponentBase *> sensortype_;
1595 std::vector<NextionComponentBase *> textsensortype_;
1596 std::vector<NextionComponentBase *> binarysensortype_;
1601 CallbackManager<void(uint8_t, uint8_t, bool)> touch_callback_{};
1603#ifdef USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1605#endif // USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1606#ifdef USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1608#endif // USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1609#ifdef USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1611#endif // USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1612#ifdef USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1614#endif // USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1615
1617 optional<float> brightness_;
1618
1619 // Device info populated from comok response (fixed-size, no heap allocation).
1620 // Sizes derived from Nextion Upload Protocol documentation and observed hardware.
1621 static constexpr size_t NEXTION_MODEL_MAX = 24;
1622 static constexpr size_t NEXTION_FW_MAX = 7;
1623 static constexpr size_t NEXTION_SERIAL_MAX = 20;
1628
1630
1631#ifdef NEXTION_PROTOCOL_LOG
1633#endif // NEXTION_PROTOCOL_LOG
1634 void reset_(bool reset_nextion = true);
1635
1636 std::string command_data_;
1638
1639 uint16_t startup_override_ms_ = 8000;
1640 uint16_t max_q_age_ms_ = 8000;
1641};
1642
1643} // namespace esphome::nextion
This class simplifies creating components that periodically check a state.
Definition component.h:510
Fixed-size circular buffer with FIFO semantics and iteration support.
Definition helpers.h:395
StringRef is a reference to a string owned by something else.
Definition string_ref.h:30
void set_spacing(uint8_t spacing_ms)
Set the minimum time between commands.
Definition nextion.h:51
uint8_t get_spacing() const
Get current command spacing.
Definition nextion.h:57
bool can_send(uint32_t now) const
Check if enough time has passed to send the next command.
Definition nextion.h:65
NextionCommandPacer(uint8_t initial_spacing=0)
Creates command pacer with initial spacing.
Definition nextion.h:45
void mark_sent(uint32_t now)
Record the transmit timestamp for the most recently sent command.
Definition nextion.h:73
void add_sleep_state_callback(F &&callback)
Add a callback to be notified of sleep state changes.
Definition nextion.h:1150
void set_component_font_color(const char *component, uint16_t color)
Set the font color of a component.
std::vector< NextionComponentBase * > touch_
Definition nextion.h:1592
void open_waveform_channel(uint8_t component_id, uint8_t channel_number, uint8_t value)
void set_component_visibility(const char *component, bool show) override
Set the visibility of a component.
std::vector< NextionComponentBase * > switchtype_
Definition nextion.h:1593
void set_component_drag(const char *component, bool drag)
Set the drag availability of a component.
std::vector< NextionComponentBase * > binarysensortype_
Definition nextion.h:1596
int upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &range_start)
will request 4096 bytes chunks from the web server and send each to Nextion
void set_component_foreground_color(const char *component, uint16_t color)
Set the foreground color of a component.
void set_component_font(const char *component, uint8_t font_id) override
Set the font id for a component.
StaticRingBuffer< NextionQueue *, 4 > waveform_queue_
Fixed-size ring buffer for waveform queue.
Definition nextion.h:1464
uint16_t max_q_age_ms_
Maximum age for queue items in ms.
Definition nextion.h:1640
bool send_command_(const std::string &command)
Manually send a raw command to the display and don't wait for an acknowledgement packet.
size_t get_max_queue_size() const
Get the maximum allowed queue size.
Definition nextion.h:110
uint8_t tft_upload_http_retries_
HTTP retry count (default: 5)
Definition nextion.h:1556
static constexpr size_t NEXTION_MODEL_MAX
Max observed ~18 chars from product numbering rules.
Definition nextion.h:1621
void set_max_queue_size(size_t size)
Set the maximum allowed queue size.
Definition nextion.h:104
std::vector< NextionComponentBase * > textsensortype_
Definition nextion.h:1595
void set_max_commands_per_loop(uint16_t value)
Set the maximum number of commands to process in each loop iteration.
Definition nextion.h:91
uint8_t auto_wake_on_touch_
Display should wake automatically on touch (default: true)
Definition nextion.h:1485
char firmware_version_[NEXTION_FW_MAX+1]
Definition nextion.h:1625
void purge_stale_queue_entries_()
Drop queue entries older than max_q_age_ms_.
CallbackManager< void(uint8_t)> page_callback_
Definition nextion.h:1600
void add_custom_text_sensor_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom text sensor protocol frame (0x92).
Definition nextion.h:1240
void set_component_text_printf(const char *component, const char *format,...) __attribute__((format(printf
Set the text of a component to a formatted string.
void set_brightness(float brightness)
Definition nextion.h:1059
void set_component_text(const char *component, const char *text)
Set the text of a component to a static string.
void set_tft_upload_http_retries(uint8_t retries)
Set the number of HTTP retries for TFT upload requests.
Definition nextion.h:1108
CallbackManager< void(StringRef, int32_t)> custom_sensor_callback_
Definition nextion.h:1607
void set_wake_up_page(uint8_t wake_up_page=255)
Sets which page Nextion loads when exiting sleep mode.
NextionQueue * make_no_result_entry_(const std::string &variable_name)
void set_nextion_rtc_time(ESPTime time)
Send the current time to the nextion display.
void all_components_send_state_(bool force_update=false)
void set_start_up_page(uint8_t start_up_page=255)
Sets which page Nextion loads when connecting to ESPHome.
Definition nextion.h:1341
void set_component_pressed_foreground_color(const char *component, uint16_t color)
Set the pressed foreground color of a component.
void set_nextion_sensor_state(int queue_type, const std::string &name, float state)
Set the nextion sensor state object.
char serial_number_[NEXTION_SERIAL_MAX+1]
Definition nextion.h:1626
void add_addt_command_to_queue(NextionComponentBase *component) override
uint16_t get_startup_override_ms() const
Get the startup override timeout.
Definition nextion.h:1434
void soft_reset()
Softreset the Nextion.
void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color)
Draw a filled circled.
uint32_t flash_size_
Flash size in bytes — plain integer, no string needed.
Definition nextion.h:1627
void register_textsensor_component(NextionComponentBase *obj)
Definition nextion.h:1056
void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color)
Draw a circle outline.
uint16_t max_commands_per_loop_
Definition nextion.h:1438
void enable_component_touch(const char *component)
Enable touch for a component.
void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color)
Draw a rectangle outline.
void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send, const std::string &state_value) override
nextion_writer_t writer_
Definition nextion.h:1616
uint16_t startup_override_ms_
Timeout before forcing setup complete.
Definition nextion.h:1639
void add_to_get_queue(NextionComponentBase *component) override
void void set_component_value(const char *component, int32_t value)
Set the integer value of a component.
uint8_t is_updating_
TFT firmware update is currently in progress.
Definition nextion.h:1484
bool send_command_printf(const char *format,...) __attribute__((format(printf
Manually send a raw formatted command to the display.
void set_max_queue_age(uint16_t age_ms)
Set the maximum age for queue items.
Definition nextion.h:1416
WiFiClient * wifi_client_
Definition nextion.h:1546
std::list< NextionQueue * > nextion_queue_
Definition nextion.h:1460
void set_component_picture(const char *component, uint8_t picture_id)
Set the picture of an image component.
Definition nextion.h:178
bool void set_tft_upload_http_timeout(uint16_t timeout_ms)
Set the HTTP timeout for TFT upload requests.
Definition nextion.h:1087
void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send, int32_t state_value) override
void set_auto_wake_on_touch(bool auto_wake_on_touch)
Sets if Nextion should auto-wake from sleep when touch press occurs.
bool remove_from_q_(bool report_empty=true)
bool upload_tft(uint32_t baud_rate=0, bool exit_reparse=true)
Uploads the TFT file to the Nextion display.
uint16_t tft_upload_http_timeout_
HTTP timeout in ms (default: 4.5s)
Definition nextion.h:1555
void add_setup_state_callback(F &&callback)
Add a callback to be notified when the nextion completes its initialize setup.
Definition nextion.h:1166
void set_component_pic(const char *component, uint16_t pic_id)
Set the picture id of a component.
bool set_protocol_reparse_mode(bool active_mode)
Sets the Nextion display's protocol reparse mode.
std::vector< NextionComponentBase * > sensortype_
Definition nextion.h:1594
bool upload_end_(bool successful)
Ends the upload process, restart Nextion and, if successful, restarts ESP.
BearSSL::WiFiClientSecure * wifi_client_secure_
Definition nextion.h:1547
void set_component_coordinates(const char *component, uint16_t x, uint16_t y)
Set the coordinates of a component on screen.
void add_new_page_callback(F &&callback)
Add a callback to be notified when the nextion changes pages.
Definition nextion.h:1174
uint8_t sent_setup_commands_
Initial setup commands have been sent.
Definition nextion.h:1481
void add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) override
void set_component_picc(const char *component, uint16_t pic_id)
Set the background picture id of component.
void sleep(bool sleep)
Sets Nextion mode between sleep and awake.
bool add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
void set_touch_sleep_timeout(uint16_t touch_sleep_timeout=0)
Set the touch sleep timeout of the display using the thsp command.
CallbackManager< void()> setup_callback_
Definition nextion.h:1597
void hide_component(const char *component) override
Hide a component.
std::string command_data_
Definition nextion.h:1636
void set_component_position(const char *component, uint32_t x, uint32_t y)
Set the position of a component.
uint16_t get_max_queue_age() const
Get the maximum age for queue items.
Definition nextion.h:1422
optional< float > brightness_
Definition nextion.h:1617
CallbackManager< void()> wake_callback_
Definition nextion.h:1599
void release_queue_entry_(NextionQueue *nb)
void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value)
Add waveform data to a waveform component.
void disable_component_touch(const char *component)
Disable touch for a component.
bool is_updating() override
Check if the TFT update process is currently running.
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag)
void set_component_pressed_font_color(const char *component, uint16_t color)
Set the pressed font color of a component.
void register_touch_component(NextionComponentBase *obj)
Definition nextion.h:1052
void set_startup_override_ms(uint16_t timeout_ms)
Set the startup override timeout.
Definition nextion.h:1428
void goto_page(const char *page)
Show the page with a given name.
void add_buffer_overflow_event_callback(F &&callback)
Add a callback to be notified when the nextion reports a buffer overflow.
Definition nextion.h:1188
void add_custom_binary_sensor_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom binary sensor protocol frame (0x93).
Definition nextion.h:1201
bool void add_no_result_to_queue_with_set_internal_(const std::string &variable_name, const std::string &variable_name_to_send, int32_t state_value, bool is_sleep_safe=false)
uint8_t reserved_
Reserved bits for future flag additions.
Definition nextion.h:1486
bool void add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command)
void add_touch_event_callback(F &&callback)
Add a callback to be notified when Nextion has a touch event.
Definition nextion.h:1180
CallbackManager< void(StringRef, bool)> custom_binary_sensor_callback_
Definition nextion.h:1604
void set_wait_for_ack(bool wait_for_ack)
void set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state)
void register_switch_component(NextionComponentBase *obj)
Definition nextion.h:1053
void set_tft_upload_watchdog_timeout(uint32_t timeout_ms)
Set the watchdog timeout during TFT upload.
Definition nextion.h:1101
size_t queue_size()
Retrieves the number of commands pending in the Nextion command queue.
Definition nextion.h:1371
bool send_command(const char *command)
Manually send a raw command to the display.
CallbackManager< void()> sleep_callback_
Definition nextion.h:1598
void add_custom_sensor_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom sensor protocol frame (0x91).
Definition nextion.h:1214
void set_tft_url(const std::string &tft_url)
Set the tft file URL.
Definition nextion.h:1113
void set_component_pressed_background_color(const char *component, uint16_t color)
Set the pressed background color of a component.
uint8_t ignore_is_setup_
Temporarily ignore setup state for special operations.
Definition nextion.h:1482
void set_component_vid(const char *component, uint8_t vid_id)
Set the video id of a component.
void set_component_background_color(const char *component, uint16_t color)
Set the background color of a component.
bool is_connected()
Check if the Nextion display is successfully connected.
Definition nextion.h:1410
void reset_(bool reset_nextion=true)
void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a line on the screen.
void qrcode(uint16_t x1, uint16_t y1, const char *content, uint16_t size=200, uint16_t background_color=65535, uint16_t foreground_color=0, int32_t logo_pic=-1, uint8_t border_width=8)
Draws a QR code in the screen.
void process_pending_in_queue_()
Process any commands in the queue that are pending due to command spacing.
static constexpr size_t NEXTION_FW_MAX
'S' prefix + integer (e.g. 'S99' or 123)
Definition nextion.h:1622
void add_no_result_to_queue_(const std::string &variable_name)
void add_wake_state_callback(F &&callback)
Add a callback to be notified of wake state changes.
Definition nextion.h:1158
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
Definition nextion.h:1601
struct esphome::nextion::Nextion::@148 connection_state_
Status flags for Nextion display state management.
void register_binarysensor_component(NextionComponentBase *obj)
Definition nextion.h:1054
uint16_t get_max_commands_per_loop() const
Get the current maximum number of commands allowed per loop iteration.
Definition nextion.h:97
void dump_config() override
void set_command_spacing(uint32_t spacing_ms)
Set the command spacing for the display.
Definition nextion.h:118
NextionCommandPacer command_pacer_
Definition nextion.h:1445
void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color)
Fill a rectangle with a color.
void set_nextion_text_state(const std::string &name, const std::string &state)
void add_custom_switch_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom switch protocol frame (0x90).
Definition nextion.h:1227
bool add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
void update() override
void display_picture(uint16_t picture_id, uint16_t x_start, uint16_t y_start)
Display a picture at coordinates.
uint8_t is_connected_
Connection established with Nextion display.
Definition nextion.h:1480
CallbackManager< void()> buffer_overflow_callback_
Definition nextion.h:1602
void show_component(const char *component) override
Show a component.
void set_writer(const nextion_writer_t &writer)
char device_model_[NEXTION_MODEL_MAX+1]
Definition nextion.h:1624
CallbackManager< void(StringRef, StringRef)> custom_text_sensor_callback_
Definition nextion.h:1613
void add_no_result_to_queue_with_pending_command_(const std::string &variable_name, const std::string &command)
Add a command to the Nextion queue with a pending command for retry.
void register_sensor_component(NextionComponentBase *obj)
Definition nextion.h:1055
void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value) override
static constexpr size_t NEXTION_SERIAL_MAX
Consistently 16 hex chars across all documented examples.
Definition nextion.h:1623
CallbackManager< void(StringRef, bool)> custom_switch_callback_
Definition nextion.h:1610
void set_component_aph(const char *component, uint8_t aph)
Set the opaqueness (fading) of a component.
void update_components_by_prefix(const std::string &prefix)
uint32_t tft_upload_watchdog_timeout_
WDT timeout in ms (0 = no adjustment)
Definition nextion.h:1559
uint8_t nextion_reports_is_setup_
Nextion has reported successful initialization.
Definition nextion.h:1483
void set_backlight_brightness(float brightness)
Set the brightness of the backlight.
const Component * component
Definition component.cpp:34
bool state
Definition fan.h:2
const char * format
bool active_mode
uint16_t size
Definition helpers.cpp:33
STL namespace.
static void uint32_t
A more user-friendly version of struct tm from time.h.
Definition time.h:23
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6