ESPHome 2026.8.0-dev
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
617#ifdef USE_NEXTION_WAVEFORM
624 void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value);
625
626 void open_waveform_channel(uint8_t component_id, uint8_t channel_number, uint8_t value);
627#endif // USE_NEXTION_WAVEFORM
628
642 void display_picture(uint16_t picture_id, uint16_t x_start, uint16_t y_start);
643
662 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
663
681 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, const char *color);
682
700 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, Color color);
701
720 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
721
739 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, const char *color);
740
758 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, Color color);
759
778 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
779
797 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, const char *color);
798
816 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, Color color);
817
827 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
828
837 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, const char *color);
838
846 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, Color color);
847
864 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
865
881 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, const char *color);
882
898 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, Color color);
899
918 void qrcode(uint16_t x1, uint16_t y1, const char *content, uint16_t size = 200, uint16_t background_color = 65535,
919 uint16_t foreground_color = 0, int32_t logo_pic = -1, uint8_t border_width = 8);
920
942 void qrcode(uint16_t x1, uint16_t y1, const char *content, uint16_t size,
943 Color background_color = Color(255, 255, 255), Color foreground_color = Color(0, 0, 0),
944 int32_t logo_pic = -1, uint8_t border_width = 8);
945
957 void set_backlight_brightness(float brightness);
958
963 void sleep(bool sleep);
964
984
985 // ======== Nextion Intelligent Series ========
986
1001 void set_component_vid(const char *component, uint8_t vid_id);
1002
1017 void set_component_drag(const char *component, bool drag);
1018
1033 void set_component_aph(const char *component, uint8_t aph);
1034
1051
1052 // ========== INTERNAL METHODS ==========
1053 // (In most use cases you won't need these)
1054 void register_touch_component(NextionComponentBase *obj) { this->touch_.push_back(obj); }
1059
1060 void setup() override;
1061 void set_brightness(float brightness) { this->brightness_ = brightness; }
1062 void update() override;
1063 void loop() override;
1064 void set_writer(const nextion_writer_t &writer);
1065
1066 // This function has been deprecated
1067 void set_wait_for_ack(bool wait_for_ack);
1068
1074 bool send_command(const char *command);
1075
1082 bool send_command_printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
1083
1084#ifdef USE_NEXTION_TFT_UPLOAD
1089 void set_tft_upload_http_timeout(uint16_t timeout_ms) { this->tft_upload_http_timeout_ = timeout_ms; }
1090
1091#ifdef USE_ESP32
1104#endif // USE_ESP32
1105
1110 void set_tft_upload_http_retries(uint8_t retries) { this->tft_upload_http_retries_ = retries; }
1111
1115 void set_tft_url(const std::string &tft_url) { this->tft_url_ = tft_url; }
1116
1137 bool upload_tft(uint32_t baud_rate = 0, bool exit_reparse = true);
1138
1139#endif // USE_NEXTION_TFT_UPLOAD
1140
1141 void dump_config() override;
1142
1146 void soft_reset();
1147
1152 template<typename F> void add_sleep_state_callback(F &&callback) {
1153 this->sleep_callback_.add(std::forward<F>(callback));
1154 }
1155
1160 template<typename F> void add_wake_state_callback(F &&callback) {
1161 this->wake_callback_.add(std::forward<F>(callback));
1162 }
1163
1168 template<typename F> void add_setup_state_callback(F &&callback) {
1169 this->setup_callback_.add(std::forward<F>(callback));
1170 }
1171
1176 template<typename F> void add_new_page_callback(F &&callback) { this->page_callback_.add(std::forward<F>(callback)); }
1177
1182 template<typename F> void add_touch_event_callback(F &&callback) {
1183 this->touch_callback_.add(std::forward<F>(callback));
1184 }
1185
1190 template<typename F> void add_buffer_overflow_event_callback(F &&callback) {
1191 this->buffer_overflow_callback_.add(std::forward<F>(callback));
1192 }
1193
1194 // Callbacks for Nextion "custom protocol" frames (0x90..0x93)
1195#ifdef USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1203 template<typename F> void add_custom_binary_sensor_callback(F &&callback) {
1204 this->custom_binary_sensor_callback_.add(std::forward<F>(callback));
1205 }
1206#endif // USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1207
1208#ifdef USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1216 template<typename F> void add_custom_sensor_callback(F &&callback) {
1217 this->custom_sensor_callback_.add(std::forward<F>(callback));
1218 }
1219#endif // USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1220
1221#ifdef USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1229 template<typename F> void add_custom_switch_callback(F &&callback) {
1230 this->custom_switch_callback_.add(std::forward<F>(callback));
1231 }
1232#endif // USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1233
1234#ifdef USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1242 template<typename F> void add_custom_text_sensor_callback(F &&callback) {
1243 this->custom_text_sensor_callback_.add(std::forward<F>(callback));
1244 }
1245#endif // USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1246
1248
1261 void set_nextion_sensor_state(int queue_type, const std::string &name, float state);
1262 void set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state);
1263 void set_nextion_text_state(const std::string &name, const std::string &state);
1264
1266 void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send,
1267 int32_t state_value) override;
1268
1269 void add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) override;
1270 void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send,
1271 const std::string &state_value) override;
1272
1274
1275#ifdef USE_NEXTION_WAVEFORM
1277#endif // USE_NEXTION_WAVEFORM
1278
1279 void update_components_by_prefix(const std::string &prefix);
1280
1314 void set_touch_sleep_timeout(uint16_t touch_sleep_timeout = 0);
1315
1328 void set_wake_up_page(uint8_t wake_up_page = 255);
1329
1330#ifdef USE_NEXTION_CONF_START_UP_PAGE
1343 void set_start_up_page(uint8_t start_up_page = 255) { this->start_up_page_ = start_up_page; }
1344#endif // USE_NEXTION_CONF_START_UP_PAGE
1345
1358 void set_auto_wake_on_touch(bool auto_wake_on_touch);
1359
1373 size_t queue_size() { return this->nextion_queue_.size(); }
1374
1393 bool is_updating() override;
1394
1412 bool is_connected() { return this->connection_state_.is_connected_; }
1413
1418 inline void set_max_queue_age(uint16_t age_ms) { this->max_q_age_ms_ = age_ms; }
1419
1424 inline uint16_t get_max_queue_age() const { return this->max_q_age_ms_; }
1425
1430 inline void set_startup_override_ms(uint16_t timeout_ms) { this->startup_override_ms_ = timeout_ms; }
1431
1436 inline uint16_t get_startup_override_ms() const { return this->startup_override_ms_; }
1437
1438 protected:
1439#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
1441#endif // USE_NEXTION_MAX_COMMANDS_PER_LOOP
1442#ifdef USE_NEXTION_MAX_QUEUE_SIZE
1444#endif // USE_NEXTION_MAX_QUEUE_SIZE
1445
1446#ifdef USE_NEXTION_COMMAND_SPACING
1448
1460#endif // USE_NEXTION_COMMAND_SPACING
1461
1462 std::list<NextionQueue *> nextion_queue_;
1463#ifdef USE_NEXTION_WAVEFORM
1467#endif // USE_NEXTION_WAVEFORM
1468 uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag);
1469 void all_components_send_state_(bool force_update = false);
1471 bool remove_from_q_(bool report_empty = true);
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:316
StringRef is a reference to a string owned by something else.
Definition string_ref.h:26
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:1152
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:1466
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:1242
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:1061
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:1110
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.
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:1343
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:1436
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:1058
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:1440
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:1418
WiFiClient * wifi_client_
Definition nextion.h:1546
std::list< NextionQueue * > nextion_queue_
Definition nextion.h:1462
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:1089
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:1168
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:1176
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:1424
optional< float > brightness_
Definition nextion.h:1617
CallbackManager< void()> wake_callback_
Definition nextion.h:1599
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:1054
struct esphome::nextion::Nextion::@147 connection_state_
Status flags for Nextion display state management.
void set_startup_override_ms(uint16_t timeout_ms)
Set the startup override timeout.
Definition nextion.h:1430
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:1190
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:1203
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:1182
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:1055
void set_tft_upload_watchdog_timeout(uint32_t timeout_ms)
Set the watchdog timeout during TFT upload.
Definition nextion.h:1103
size_t queue_size()
Retrieves the number of commands pending in the Nextion command queue.
Definition nextion.h:1373
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:1216
void set_tft_url(const std::string &tft_url)
Set the tft file URL.
Definition nextion.h:1115
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:1412
void reset_(bool reset_nextion=true)
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:1160
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
Definition nextion.h:1601
void register_binarysensor_component(NextionComponentBase *obj)
Definition nextion.h:1056
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:1447
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:1229
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:1057
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.
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
const Component * component
Definition component.cpp:34
bool state
Definition fan.h:2
bool active_mode
const char int line
Definition log.h:74
const char int const __FlashStringHelper * format
Definition log.h:74
uint16_t size
Definition helpers.cpp:25
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