ESPHome  2024.10.2
nextion.cpp
Go to the documentation of this file.
1 #include "nextion.h"
2 #include "esphome/core/util.h"
3 #include "esphome/core/log.h"
5 #include <cinttypes>
6 
7 namespace esphome {
8 namespace nextion {
9 
10 static const char *const TAG = "nextion";
11 
13  this->is_setup_ = false;
14  this->ignore_is_setup_ = true;
15 
16  // Wake up the nextion
17  this->send_command_("bkcmd=0");
18  this->send_command_("sleep=0");
19 
20  this->send_command_("bkcmd=0");
21  this->send_command_("sleep=0");
22 
23  // Reboot it
24  this->send_command_("rest");
25 
26  this->ignore_is_setup_ = false;
27 }
28 
29 bool Nextion::send_command_(const std::string &command) {
30  if (!this->ignore_is_setup_ && !this->is_setup()) {
31  return false;
32  }
33 
34  ESP_LOGN(TAG, "send_command %s", command.c_str());
35 
36  this->write_str(command.c_str());
37  const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF};
38  this->write_array(to_send, sizeof(to_send));
39  return true;
40 }
41 
43  if (this->get_is_connected_())
44  return true;
45 
46  // Check if the handshake should be skipped for the Nextion connection
47  if (this->skip_connection_handshake_) {
48  // Log the connection status without handshake
49  ESP_LOGW(TAG, "Nextion display set as connected without performing handshake");
50  // Set the connection status to true
51  this->is_connected_ = true;
52  // Return true indicating the connection is set
53  return true;
54  }
55 
56  if (this->comok_sent_ == 0) {
57  this->reset_(false);
58 
59  this->ignore_is_setup_ = true;
60  this->send_command_("boguscommand=0"); // bogus command. needed sometimes after updating
61  if (this->exit_reparse_on_start_) {
62  this->send_command_("DRAKJHSUYDGBNCJHGJKSHBDN");
63  }
64  this->send_command_("connect");
65 
66  this->comok_sent_ = millis();
67  this->ignore_is_setup_ = false;
68 
69  return false;
70  }
71 
72  if (millis() - this->comok_sent_ <= 500) // Wait 500 ms
73  return false;
74 
75  std::string response;
76 
77  this->recv_ret_string_(response, 0, false);
78  if (!response.empty() && response[0] == 0x1A) {
79  // Swallow invalid variable name responses that may be caused by the above commands
80  ESP_LOGD(TAG, "0x1A error ignored during setup");
81  return false;
82  }
83  if (response.empty() || response.find("comok") == std::string::npos) {
84 #ifdef NEXTION_PROTOCOL_LOG
85  ESP_LOGN(TAG, "Bad connect request %s", response.c_str());
86  for (size_t i = 0; i < response.length(); i++) {
87  ESP_LOGN(TAG, "response %s %d %d %c", response.c_str(), i, response[i], response[i]);
88  }
89 #endif
90 
91  ESP_LOGW(TAG, "Nextion is not connected! ");
92  comok_sent_ = 0;
93  return false;
94  }
95 
96  this->ignore_is_setup_ = true;
97  ESP_LOGI(TAG, "Nextion is connected");
98  this->is_connected_ = true;
99 
100  ESP_LOGN(TAG, "connect request %s", response.c_str());
101 
102  size_t start;
103  size_t end = 0;
104  std::vector<std::string> connect_info;
105  while ((start = response.find_first_not_of(',', end)) != std::string::npos) {
106  end = response.find(',', start);
107  connect_info.push_back(response.substr(start, end - start));
108  }
109 
110  this->is_detected_ = (connect_info.size() == 7);
111  if (this->is_detected_) {
112  ESP_LOGN(TAG, "Received connect_info %zu", connect_info.size());
113 
114  this->device_model_ = connect_info[2];
115  this->firmware_version_ = connect_info[3];
116  this->serial_number_ = connect_info[5];
117  this->flash_size_ = connect_info[6];
118  } else {
119  ESP_LOGE(TAG, "Nextion returned bad connect value \"%s\"", response.c_str());
120  }
121 
122  this->ignore_is_setup_ = false;
123  this->dump_config();
124  return true;
125 }
126 
127 void Nextion::reset_(bool reset_nextion) {
128  uint8_t d;
129 
130  while (this->available()) { // Clear receive buffer
131  this->read_byte(&d);
132  };
133  this->nextion_queue_.clear();
134  this->waveform_queue_.clear();
135 }
136 
138  ESP_LOGCONFIG(TAG, "Nextion:");
139  if (this->skip_connection_handshake_) {
140  ESP_LOGCONFIG(TAG, " Skip handshake: %s", YESNO(this->skip_connection_handshake_));
141  } else {
142  ESP_LOGCONFIG(TAG, " Device Model: %s", this->device_model_.c_str());
143  ESP_LOGCONFIG(TAG, " Firmware Version: %s", this->firmware_version_.c_str());
144  ESP_LOGCONFIG(TAG, " Serial Number: %s", this->serial_number_.c_str());
145  ESP_LOGCONFIG(TAG, " Flash Size: %s", this->flash_size_.c_str());
146  }
147  ESP_LOGCONFIG(TAG, " Wake On Touch: %s", YESNO(this->auto_wake_on_touch_));
148  ESP_LOGCONFIG(TAG, " Exit reparse: %s", YESNO(this->exit_reparse_on_start_));
149 
150  if (this->touch_sleep_timeout_ != 0) {
151  ESP_LOGCONFIG(TAG, " Touch Timeout: %" PRIu32, this->touch_sleep_timeout_);
152  }
153 
154  if (this->wake_up_page_ != -1) {
155  ESP_LOGCONFIG(TAG, " Wake Up Page: %" PRId16, this->wake_up_page_);
156  }
157 
158  if (this->start_up_page_ != -1) {
159  ESP_LOGCONFIG(TAG, " Start Up Page: %" PRId16, this->start_up_page_);
160  }
161 }
162 
165  if (!this->is_setup()) {
166  return;
167  }
168  if (this->writer_.has_value()) {
169  (*this->writer_)(*this);
170  }
171 }
172 
173 void Nextion::add_sleep_state_callback(std::function<void()> &&callback) {
174  this->sleep_callback_.add(std::move(callback));
175 }
176 
177 void Nextion::add_wake_state_callback(std::function<void()> &&callback) {
178  this->wake_callback_.add(std::move(callback));
179 }
180 
181 void Nextion::add_setup_state_callback(std::function<void()> &&callback) {
182  this->setup_callback_.add(std::move(callback));
183 }
184 
185 void Nextion::add_new_page_callback(std::function<void(uint8_t)> &&callback) {
186  this->page_callback_.add(std::move(callback));
187 }
188 
189 void Nextion::add_touch_event_callback(std::function<void(uint8_t, uint8_t, bool)> &&callback) {
190  this->touch_callback_.add(std::move(callback));
191 }
192 
194  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
195  return;
196 
197  for (auto *binarysensortype : this->binarysensortype_) {
198  binarysensortype->update_component();
199  }
200  for (auto *sensortype : this->sensortype_) {
201  sensortype->update_component();
202  }
203  for (auto *switchtype : this->switchtype_) {
204  switchtype->update_component();
205  }
206  for (auto *textsensortype : this->textsensortype_) {
207  textsensortype->update_component();
208  }
209 }
210 
211 bool Nextion::send_command(const char *command) {
212  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
213  return false;
214 
215  if (this->send_command_(command)) {
216  this->add_no_result_to_queue_("send_command");
217  return true;
218  }
219  return false;
220 }
221 
222 bool Nextion::send_command_printf(const char *format, ...) {
223  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
224  return false;
225 
226  char buffer[256];
227  va_list arg;
228  va_start(arg, format);
229  int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
230  va_end(arg);
231  if (ret <= 0) {
232  ESP_LOGW(TAG, "Building command for format '%s' failed!", format);
233  return false;
234  }
235 
236  if (this->send_command_(buffer)) {
237  this->add_no_result_to_queue_("send_command_printf");
238  return true;
239  }
240  return false;
241 }
242 
243 #ifdef NEXTION_PROTOCOL_LOG
245  ESP_LOGN(TAG, "print_queue_members_ (top 10) size %zu", this->nextion_queue_.size());
246  ESP_LOGN(TAG, "*******************************************");
247  int count = 0;
248  for (auto *i : this->nextion_queue_) {
249  if (count++ == 10)
250  break;
251 
252  if (i == nullptr) {
253  ESP_LOGN(TAG, "Nextion queue is null");
254  } else {
255  ESP_LOGN(TAG, "Nextion queue type: %d:%s , name: %s", i->component->get_queue_type(),
256  i->component->get_queue_type_string().c_str(), i->component->get_variable_name().c_str());
257  }
258  }
259  ESP_LOGN(TAG, "*******************************************");
260 }
261 #endif
262 
264  if (!this->check_connect_() || this->is_updating_)
265  return;
266 
267  if (this->nextion_reports_is_setup_ && !this->sent_setup_commands_) {
268  this->ignore_is_setup_ = true;
269  this->sent_setup_commands_ = true;
270  this->send_command_("bkcmd=3"); // Always, returns 0x00 to 0x23 result of serial command.
271 
273 
274  // Check if a startup page has been set and send the command
275  if (this->start_up_page_ != -1) {
276  this->goto_page(this->start_up_page_);
277  }
278 
279  // This could probably be removed from the loop area, as those are redundant.
282 
283  if (this->touch_sleep_timeout_ != 0) {
285  }
286 
287  if (this->wake_up_page_ != -1) {
288  this->set_wake_up_page(this->wake_up_page_);
289  }
290 
291  this->ignore_is_setup_ = false;
292  }
293 
294  this->process_serial_(); // Receive serial data
295  this->process_nextion_commands_(); // Process nextion return commands
296 
297  if (!this->nextion_reports_is_setup_) {
298  if (this->started_ms_ == 0)
299  this->started_ms_ = millis();
300 
301  if (this->started_ms_ + this->startup_override_ms_ < millis()) {
302  ESP_LOGD(TAG, "Manually set nextion report ready");
303  this->nextion_reports_is_setup_ = true;
304  }
305  }
306 }
307 
308 bool Nextion::remove_from_q_(bool report_empty) {
309  if (this->nextion_queue_.empty()) {
310  if (report_empty) {
311  ESP_LOGE(TAG, "Nextion queue is empty!");
312  }
313  return false;
314  }
315 
316  NextionQueue *nb = this->nextion_queue_.front();
317  NextionComponentBase *component = nb->component;
318 
319  ESP_LOGN(TAG, "Removing %s from the queue", component->get_variable_name().c_str());
320 
321  if (component->get_queue_type() == NextionQueueType::NO_RESULT) {
322  if (component->get_variable_name() == "sleep_wake") {
323  this->is_sleeping_ = false;
324  }
325  delete component; // NOLINT(cppcoreguidelines-owning-memory)
326  }
327  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
328  this->nextion_queue_.pop_front();
329  return true;
330 }
331 
333  uint8_t d;
334 
335  while (this->available()) {
336  read_byte(&d);
337  this->command_data_ += d;
338  }
339 }
340 // nextion.tech/instruction-set/
342  if (this->command_data_.length() == 0) {
343  return;
344  }
345 
346  size_t to_process_length = 0;
347  std::string to_process;
348 
349  ESP_LOGN(TAG, "this->command_data_ %s length %d", this->command_data_.c_str(), this->command_data_.length());
350 #ifdef NEXTION_PROTOCOL_LOG
351  this->print_queue_members_();
352 #endif
353  while ((to_process_length = this->command_data_.find(COMMAND_DELIMITER)) != std::string::npos) {
354  ESP_LOGN(TAG, "print_queue_members_ size %zu", this->nextion_queue_.size());
355  while (to_process_length + COMMAND_DELIMITER.length() < this->command_data_.length() &&
356  static_cast<uint8_t>(this->command_data_[to_process_length + COMMAND_DELIMITER.length()]) == 0xFF) {
357  ++to_process_length;
358  ESP_LOGN(TAG, "Add extra 0xFF to process");
359  }
360 
361  this->nextion_event_ = this->command_data_[0];
362 
363  to_process_length -= 1;
364  to_process = this->command_data_.substr(1, to_process_length);
365 
366  switch (this->nextion_event_) {
367  case 0x00: // instruction sent by user has failed
368  ESP_LOGW(TAG, "Nextion reported invalid instruction!");
369  this->remove_from_q_();
370 
371  break;
372  case 0x01: // instruction sent by user was successful
373 
374  ESP_LOGVV(TAG, "instruction sent by user was successful");
375  ESP_LOGN(TAG, "this->nextion_queue_.empty() %s", this->nextion_queue_.empty() ? "True" : "False");
376 
377  this->remove_from_q_();
378  if (!this->is_setup_) {
379  if (this->nextion_queue_.empty()) {
380  ESP_LOGD(TAG, "Nextion is setup");
381  this->is_setup_ = true;
382  this->setup_callback_.call();
383  }
384  }
385 
386  break;
387  case 0x02: // invalid Component ID or name was used
388  ESP_LOGW(TAG, "Nextion reported component ID or name invalid!");
389  this->remove_from_q_();
390  break;
391  case 0x03: // invalid Page ID or name was used
392  ESP_LOGW(TAG, "Nextion reported page ID invalid!");
393  this->remove_from_q_();
394  break;
395  case 0x04: // invalid Picture ID was used
396  ESP_LOGW(TAG, "Nextion reported picture ID invalid!");
397  this->remove_from_q_();
398  break;
399  case 0x05: // invalid Font ID was used
400  ESP_LOGW(TAG, "Nextion reported font ID invalid!");
401  this->remove_from_q_();
402  break;
403  case 0x06: // File operation fails
404  ESP_LOGW(TAG, "Nextion File operation fail!");
405  break;
406  case 0x09: // Instructions with CRC validation fails their CRC check
407  ESP_LOGW(TAG, "Nextion Instructions with CRC validation fails their CRC check!");
408  break;
409  case 0x11: // invalid Baud rate was used
410  ESP_LOGW(TAG, "Nextion reported baud rate invalid!");
411  break;
412  case 0x12: // invalid Waveform ID or Channel # was used
413  if (this->waveform_queue_.empty()) {
414  ESP_LOGW(TAG,
415  "Nextion reported invalid Waveform ID or Channel # was used but no waveform sensor in queue found!");
416  } else {
417  auto &nb = this->waveform_queue_.front();
418  NextionComponentBase *component = nb->component;
419 
420  ESP_LOGW(TAG, "Nextion reported invalid Waveform ID %d or Channel # %d was used!",
421  component->get_component_id(), component->get_wave_channel_id());
422 
423  ESP_LOGN(TAG, "Removing waveform from queue with component id %d and waveform id %d",
424  component->get_component_id(), component->get_wave_channel_id());
425 
426  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
427  this->waveform_queue_.pop_front();
428  }
429  break;
430  case 0x1A: // variable name invalid
431  ESP_LOGW(TAG, "Nextion reported variable name invalid!");
432  this->remove_from_q_();
433  break;
434  case 0x1B: // variable operation invalid
435  ESP_LOGW(TAG, "Nextion reported variable operation invalid!");
436  this->remove_from_q_();
437  break;
438  case 0x1C: // failed to assign
439  ESP_LOGW(TAG, "Nextion reported failed to assign variable!");
440  this->remove_from_q_();
441  break;
442  case 0x1D: // operate EEPROM failed
443  ESP_LOGW(TAG, "Nextion reported operating EEPROM failed!");
444  break;
445  case 0x1E: // parameter quantity invalid
446  ESP_LOGW(TAG, "Nextion reported parameter quantity invalid!");
447  this->remove_from_q_();
448  break;
449  case 0x1F: // IO operation failed
450  ESP_LOGW(TAG, "Nextion reported component I/O operation invalid!");
451  break;
452  case 0x20: // undefined escape characters
453  ESP_LOGW(TAG, "Nextion reported undefined escape characters!");
454  this->remove_from_q_();
455  break;
456  case 0x23: // too long variable name
457  ESP_LOGW(TAG, "Nextion reported too long variable name!");
458  this->remove_from_q_();
459  break;
460  case 0x24: // Serial Buffer overflow occurs
461  ESP_LOGW(TAG, "Nextion reported Serial Buffer overflow!");
462  break;
463  case 0x65: { // touch event return data
464  if (to_process_length != 3) {
465  ESP_LOGW(TAG, "Touch event data is expecting 3, received %zu", to_process_length);
466  break;
467  }
468 
469  uint8_t page_id = to_process[0];
470  uint8_t component_id = to_process[1];
471  uint8_t touch_event = to_process[2]; // 0 -> release, 1 -> press
472  ESP_LOGD(TAG, "Got touch event:");
473  ESP_LOGD(TAG, " page_id: %u", page_id);
474  ESP_LOGD(TAG, " component_id: %u", component_id);
475  ESP_LOGD(TAG, " event type: %s", touch_event ? "PRESS" : "RELEASE");
476  for (auto *touch : this->touch_) {
477  touch->process_touch(page_id, component_id, touch_event != 0);
478  }
479  this->touch_callback_.call(page_id, component_id, touch_event != 0);
480  break;
481  }
482  case 0x66: { // Nextion initiated new page event return data.
483  // Also is used for sendme command which we never explicitly initiate
484  if (to_process_length != 1) {
485  ESP_LOGW(TAG, "New page event data is expecting 1, received %zu", to_process_length);
486  break;
487  }
488 
489  uint8_t page_id = to_process[0];
490  ESP_LOGD(TAG, "Got new page: %u", page_id);
491  this->page_callback_.call(page_id);
492  break;
493  }
494  case 0x67: { // Touch Coordinate (awake)
495  break;
496  }
497  case 0x68: { // touch coordinate data (sleep)
498 
499  if (to_process_length != 5) {
500  ESP_LOGW(TAG, "Touch coordinate data is expecting 5, received %zu", to_process_length);
501  ESP_LOGW(TAG, "%s", to_process.c_str());
502  break;
503  }
504 
505  uint16_t x = (uint16_t(to_process[0]) << 8) | to_process[1];
506  uint16_t y = (uint16_t(to_process[2]) << 8) | to_process[3];
507  uint8_t touch_event = to_process[4]; // 0 -> release, 1 -> press
508  ESP_LOGD(TAG, "Got touch event:");
509  ESP_LOGD(TAG, " x: %u", x);
510  ESP_LOGD(TAG, " y: %u", y);
511  ESP_LOGD(TAG, " type: %s", touch_event ? "PRESS" : "RELEASE");
512  break;
513  }
514 
515  // 0x70 0x61 0x62 0x31 0x32 0x33 0xFF 0xFF 0xFF
516  // Returned when using get command for a string.
517  // Each byte is converted to char.
518  // data: ab123
519  case 0x70: // string variable data return
520  {
521  if (this->nextion_queue_.empty()) {
522  ESP_LOGW(TAG, "ERROR: Received string return but the queue is empty");
523  break;
524  }
525 
526  NextionQueue *nb = this->nextion_queue_.front();
527  NextionComponentBase *component = nb->component;
528 
529  if (component->get_queue_type() != NextionQueueType::TEXT_SENSOR) {
530  ESP_LOGE(TAG, "ERROR: Received string return but next in queue \"%s\" is not a text sensor",
531  component->get_variable_name().c_str());
532  } else {
533  ESP_LOGN(TAG, "Received get_string response: \"%s\" for component id: %s, type: %s", to_process.c_str(),
534  component->get_variable_name().c_str(), component->get_queue_type_string().c_str());
535  component->set_state_from_string(to_process, true, false);
536  }
537 
538  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
539  this->nextion_queue_.pop_front();
540 
541  break;
542  }
543  // 0x71 0x01 0x02 0x03 0x04 0xFF 0xFF 0xFF
544  // Returned when get command to return a number
545  // 4 byte 32-bit value in little endian order.
546  // (0x01+0x02*256+0x03*65536+0x04*16777216)
547  // data: 67305985
548  case 0x71: // numeric variable data return
549  {
550  if (this->nextion_queue_.empty()) {
551  ESP_LOGE(TAG, "ERROR: Received numeric return but the queue is empty");
552  break;
553  }
554 
555  if (to_process_length == 0) {
556  ESP_LOGE(TAG, "ERROR: Received numeric return but no data!");
557  break;
558  }
559 
560  int dataindex = 0;
561 
562  int value = 0;
563 
564  for (int i = 0; i < 4; ++i) {
565  value += to_process[i] << (8 * i);
566  ++dataindex;
567  }
568 
569  NextionQueue *nb = this->nextion_queue_.front();
570  NextionComponentBase *component = nb->component;
571 
572  if (component->get_queue_type() != NextionQueueType::SENSOR &&
574  component->get_queue_type() != NextionQueueType::SWITCH) {
575  ESP_LOGE(TAG, "ERROR: Received numeric return but next in queue \"%s\" is not a valid sensor type %d",
576  component->get_variable_name().c_str(), component->get_queue_type());
577  } else {
578  ESP_LOGN(TAG, "Received numeric return for variable %s, queue type %d:%s, value %d",
579  component->get_variable_name().c_str(), component->get_queue_type(),
580  component->get_queue_type_string().c_str(), value);
581  component->set_state_from_int(value, true, false);
582  }
583 
584  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
585  this->nextion_queue_.pop_front();
586 
587  break;
588  }
589 
590  case 0x86: { // device automatically enters into sleep mode
591  ESP_LOGVV(TAG, "Received Nextion entering sleep automatically");
592  this->is_sleeping_ = true;
593  this->sleep_callback_.call();
594  break;
595  }
596  case 0x87: // device automatically wakes up
597  {
598  ESP_LOGVV(TAG, "Received Nextion leaves sleep automatically");
599  this->is_sleeping_ = false;
600  this->wake_callback_.call();
601  this->all_components_send_state_(false);
602  break;
603  }
604  case 0x88: // system successful start up
605  {
606  ESP_LOGD(TAG, "system successful start up %zu", to_process_length);
607  this->nextion_reports_is_setup_ = true;
608  break;
609  }
610  case 0x89: { // start SD card upgrade
611  break;
612  }
613  // Data from nextion is
614  // 0x90 - Start
615  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
616  // 00 - NULL
617  // 00/01 - Single byte for on/off
618  // FF FF FF - End
619  case 0x90: { // Switched component
620  std::string variable_name;
621 
622  // Get variable name
623  auto index = to_process.find('\0');
624  if (index == std::string::npos || (to_process_length - index - 1) < 1) {
625  ESP_LOGE(TAG, "Bad switch component data received for 0x90 event!");
626  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
627  break;
628  }
629 
630  variable_name = to_process.substr(0, index);
631  ++index;
632 
633  ESP_LOGN(TAG, "Got Switch:");
634  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
635  ESP_LOGN(TAG, " value: %d", to_process[0] != 0);
636 
637  for (auto *switchtype : this->switchtype_) {
638  switchtype->process_bool(variable_name, to_process[index] != 0);
639  }
640  break;
641  }
642  // Data from nextion is
643  // 0x91 - Start
644  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
645  // 00 - NULL
646  // variable length of 0x71 return data: prints temp1.val,0
647  // FF FF FF - End
648  case 0x91: { // Sensor component
649  std::string variable_name;
650 
651  auto index = to_process.find('\0');
652  if (index == std::string::npos || (to_process_length - index - 1) != 4) {
653  ESP_LOGE(TAG, "Bad sensor component data received for 0x91 event!");
654  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
655  break;
656  }
657 
658  index = to_process.find('\0');
659  variable_name = to_process.substr(0, index);
660  // // Get variable name
661  int value = 0;
662  for (int i = 0; i < 4; ++i) {
663  value += to_process[i + index + 1] << (8 * i);
664  }
665 
666  ESP_LOGN(TAG, "Got sensor:");
667  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
668  ESP_LOGN(TAG, " value: %d", value);
669 
670  for (auto *sensor : this->sensortype_) {
671  sensor->process_sensor(variable_name, value);
672  }
673  break;
674  }
675 
676  // Data from nextion is
677  // 0x92 - Start
678  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
679  // 00 - NULL
680  // variable length of 0x70 return formatted data (bytes) that contain the text prints temp1.txt,0
681  // 00 - NULL
682  // FF FF FF - End
683  case 0x92: { // Text Sensor Component
684  std::string variable_name;
685  std::string text_value;
686 
687  // Get variable name
688  auto index = to_process.find('\0');
689  if (index == std::string::npos || (to_process_length - index - 1) < 1) {
690  ESP_LOGE(TAG, "Bad text sensor component data received for 0x92 event!");
691  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
692  break;
693  }
694 
695  variable_name = to_process.substr(0, index);
696  ++index;
697 
698  text_value = to_process.substr(index);
699 
700  ESP_LOGN(TAG, "Got Text Sensor:");
701  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
702  ESP_LOGN(TAG, " value: %s", text_value.c_str());
703 
704  // NextionTextSensorResponseQueue *nq = new NextionTextSensorResponseQueue;
705  // nq->variable_name = variable_name;
706  // nq->state = text_value;
707  // this->textsensorq_.push_back(nq);
708  for (auto *textsensortype : this->textsensortype_) {
709  textsensortype->process_text(variable_name, text_value);
710  }
711  break;
712  }
713  // Data from nextion is
714  // 0x93 - Start
715  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
716  // 00 - NULL
717  // 00/01 - Single byte for on/off
718  // FF FF FF - End
719  case 0x93: { // Binary Sensor component
720  std::string variable_name;
721 
722  // Get variable name
723  auto index = to_process.find('\0');
724  if (index == std::string::npos || (to_process_length - index - 1) < 1) {
725  ESP_LOGE(TAG, "Bad binary sensor component data received for 0x92 event!");
726  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
727  break;
728  }
729 
730  variable_name = to_process.substr(0, index);
731  ++index;
732 
733  ESP_LOGN(TAG, "Got Binary Sensor:");
734  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
735  ESP_LOGN(TAG, " value: %d", to_process[index] != 0);
736 
737  for (auto *binarysensortype : this->binarysensortype_) {
738  binarysensortype->process_bool(&variable_name[0], to_process[index] != 0);
739  }
740  break;
741  }
742  case 0xFD: { // data transparent transmit finished
743  ESP_LOGVV(TAG, "Nextion reported data transmit finished!");
744  this->check_pending_waveform_();
745  break;
746  }
747  case 0xFE: { // data transparent transmit ready
748  ESP_LOGVV(TAG, "Nextion reported ready for transmit!");
749  if (this->waveform_queue_.empty()) {
750  ESP_LOGE(TAG, "No waveforms in queue to send data!");
751  break;
752  }
753 
754  auto &nb = this->waveform_queue_.front();
755  auto *component = nb->component;
756  size_t buffer_to_send = component->get_wave_buffer_size() < 255 ? component->get_wave_buffer_size()
757  : 255; // ADDT command can only send 255
758 
759  this->write_array(component->get_wave_buffer().data(), static_cast<int>(buffer_to_send));
760 
761  ESP_LOGN(TAG, "Nextion sending waveform data for component id %d and waveform id %d, size %zu",
762  component->get_component_id(), component->get_wave_channel_id(), buffer_to_send);
763 
764  component->clear_wave_buffer(buffer_to_send);
765  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
766  this->waveform_queue_.pop_front();
767  break;
768  }
769  default:
770  ESP_LOGW(TAG, "Received unknown event from nextion: 0x%02X", this->nextion_event_);
771  break;
772  }
773 
774  // ESP_LOGN(TAG, "nextion_event_ deleting from 0 to %d", to_process_length + COMMAND_DELIMITER.length() + 1);
775  this->command_data_.erase(0, to_process_length + COMMAND_DELIMITER.length() + 1);
776  // App.feed_wdt(); Remove before master merge
777  this->process_serial_();
778  }
779 
780  uint32_t ms = millis();
781 
782  if (!this->nextion_queue_.empty() && this->nextion_queue_.front()->queue_time + this->max_q_age_ms_ < ms) {
783  for (size_t i = 0; i < this->nextion_queue_.size(); i++) {
784  NextionComponentBase *component = this->nextion_queue_[i]->component;
785  if (this->nextion_queue_[i]->queue_time + this->max_q_age_ms_ < ms) {
786  if (this->nextion_queue_[i]->queue_time == 0) {
787  ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\" queue_time 0",
788  component->get_queue_type_string().c_str(), component->get_variable_name().c_str());
789  }
790 
791  if (component->get_variable_name() == "sleep_wake") {
792  this->is_sleeping_ = false;
793  }
794 
795  ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\"", component->get_queue_type_string().c_str(),
796  component->get_variable_name().c_str());
797 
798  if (component->get_queue_type() == NextionQueueType::NO_RESULT) {
799  if (component->get_variable_name() == "sleep_wake") {
800  this->is_sleeping_ = false;
801  }
802  delete component; // NOLINT(cppcoreguidelines-owning-memory)
803  }
804 
805  delete this->nextion_queue_[i]; // NOLINT(cppcoreguidelines-owning-memory)
806 
807  this->nextion_queue_.erase(this->nextion_queue_.begin() + i);
808  i--;
809 
810  } else {
811  break;
812  }
813  }
814  }
815  ESP_LOGN(TAG, "Loop End");
816  // App.feed_wdt(); Remove before master merge
817  this->process_serial_();
818 } // namespace nextion
819 
820 void Nextion::set_nextion_sensor_state(int queue_type, const std::string &name, float state) {
821  this->set_nextion_sensor_state(static_cast<NextionQueueType>(queue_type), name, state);
822 }
823 
824 void Nextion::set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state) {
825  ESP_LOGN(TAG, "Received state:");
826  ESP_LOGN(TAG, " variable: %s", name.c_str());
827  ESP_LOGN(TAG, " state: %lf", state);
828  ESP_LOGN(TAG, " queue type: %d", queue_type);
829 
830  switch (queue_type) {
832  for (auto *sensor : this->sensortype_) {
833  if (name == sensor->get_variable_name()) {
834  sensor->set_state(state, true, true);
835  break;
836  }
837  }
838  break;
839  }
841  for (auto *sensor : this->binarysensortype_) {
842  if (name == sensor->get_variable_name()) {
843  sensor->set_state(state != 0, true, true);
844  break;
845  }
846  }
847  break;
848  }
850  for (auto *sensor : this->switchtype_) {
851  if (name == sensor->get_variable_name()) {
852  sensor->set_state(state != 0, true, true);
853  break;
854  }
855  }
856  break;
857  }
858  default: {
859  ESP_LOGW(TAG, "set_nextion_sensor_state does not support a queue type %d", queue_type);
860  }
861  }
862 }
863 
864 void Nextion::set_nextion_text_state(const std::string &name, const std::string &state) {
865  ESP_LOGD(TAG, "Received state:");
866  ESP_LOGD(TAG, " variable: %s", name.c_str());
867  ESP_LOGD(TAG, " state: %s", state.c_str());
868 
869  for (auto *sensor : this->textsensortype_) {
870  if (name == sensor->get_variable_name()) {
871  sensor->set_state(state, true, true);
872  break;
873  }
874  }
875 }
876 
877 void Nextion::all_components_send_state_(bool force_update) {
878  ESP_LOGD(TAG, "all_components_send_state_ ");
879  for (auto *binarysensortype : this->binarysensortype_) {
880  if (force_update || binarysensortype->get_needs_to_send_update())
881  binarysensortype->send_state_to_nextion();
882  }
883  for (auto *sensortype : this->sensortype_) {
884  if ((force_update || sensortype->get_needs_to_send_update()) && sensortype->get_wave_chan_id() == 0)
885  sensortype->send_state_to_nextion();
886  }
887  for (auto *switchtype : this->switchtype_) {
888  if (force_update || switchtype->get_needs_to_send_update())
889  switchtype->send_state_to_nextion();
890  }
891  for (auto *textsensortype : this->textsensortype_) {
892  if (force_update || textsensortype->get_needs_to_send_update())
893  textsensortype->send_state_to_nextion();
894  }
895 }
896 
897 void Nextion::update_components_by_prefix(const std::string &prefix) {
898  for (auto *binarysensortype : this->binarysensortype_) {
899  if (binarysensortype->get_variable_name().find(prefix, 0) != std::string::npos)
900  binarysensortype->update_component_settings(true);
901  }
902  for (auto *sensortype : this->sensortype_) {
903  if (sensortype->get_variable_name().find(prefix, 0) != std::string::npos)
904  sensortype->update_component_settings(true);
905  }
906  for (auto *switchtype : this->switchtype_) {
907  if (switchtype->get_variable_name().find(prefix, 0) != std::string::npos)
908  switchtype->update_component_settings(true);
909  }
910  for (auto *textsensortype : this->textsensortype_) {
911  if (textsensortype->get_variable_name().find(prefix, 0) != std::string::npos)
912  textsensortype->update_component_settings(true);
913  }
914 }
915 
916 uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag) {
917  uint16_t ret = 0;
918  uint8_t c = 0;
919  uint8_t nr_of_ff_bytes = 0;
920  uint64_t start;
921  bool exit_flag = false;
922  bool ff_flag = false;
923 
924  start = millis();
925 
926  while ((timeout == 0 && this->available()) || millis() - start <= timeout) {
927  if (!this->available()) {
928  App.feed_wdt();
929  delay(1);
930  continue;
931  }
932 
933  this->read_byte(&c);
934  if (c == 0xFF) {
935  nr_of_ff_bytes++;
936  } else {
937  nr_of_ff_bytes = 0;
938  ff_flag = false;
939  }
940 
941  if (nr_of_ff_bytes >= 3)
942  ff_flag = true;
943 
944  response += (char) c;
945  if (recv_flag) {
946  if (response.find(0x05) != std::string::npos) {
947  exit_flag = true;
948  }
949  }
950  App.feed_wdt();
951  delay(2);
952 
953  if (exit_flag || ff_flag) {
954  break;
955  }
956  }
957 
958  if (ff_flag)
959  response = response.substr(0, response.length() - 3); // Remove last 3 0xFF
960 
961  ret = response.length();
962  return ret;
963 }
964 
970 void Nextion::add_no_result_to_queue_(const std::string &variable_name) {
971  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
972  nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
973 
974  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
975  nextion_queue->component = new nextion::NextionComponentBase;
976  nextion_queue->component->set_variable_name(variable_name);
977 
978  nextion_queue->queue_time = millis();
979 
980  this->nextion_queue_.push_back(nextion_queue);
981 
982  ESP_LOGN(TAG, "Add to queue type: NORESULT component %s", nextion_queue->component->get_variable_name().c_str());
983 }
984 
991 void Nextion::add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command) {
992  if ((!this->is_setup() && !this->ignore_is_setup_) || command.empty())
993  return;
994 
995  if (this->send_command_(command)) {
996  this->add_no_result_to_queue_(variable_name);
997  }
998 }
999 
1000 bool Nextion::add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,
1001  ...) {
1002  if ((!this->is_setup() && !this->ignore_is_setup_))
1003  return false;
1004 
1005  char buffer[256];
1006  va_list arg;
1007  va_start(arg, format);
1008  int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
1009  va_end(arg);
1010  if (ret <= 0) {
1011  ESP_LOGW(TAG, "Building command for format '%s' failed!", format);
1012  return false;
1013  }
1014 
1015  this->add_no_result_to_queue_with_command_(variable_name, buffer);
1016  return true;
1017 }
1018 
1026 bool Nextion::add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format, ...) {
1027  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
1028  return false;
1029 
1030  char buffer[256];
1031  va_list arg;
1032  va_start(arg, format);
1033  int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
1034  va_end(arg);
1035  if (ret <= 0) {
1036  ESP_LOGW(TAG, "Building command for format '%s' failed!", format);
1037  return false;
1038  }
1039 
1040  this->add_no_result_to_queue_with_command_(variable_name, buffer);
1041  return true;
1042 }
1043 
1055  state_value);
1056 }
1057 
1058 void Nextion::add_no_result_to_queue_with_set(const std::string &variable_name,
1059  const std::string &variable_name_to_send, int32_t state_value) {
1060  this->add_no_result_to_queue_with_set_internal_(variable_name, variable_name_to_send, state_value);
1061 }
1062 
1063 void Nextion::add_no_result_to_queue_with_set_internal_(const std::string &variable_name,
1064  const std::string &variable_name_to_send, int32_t state_value,
1065  bool is_sleep_safe) {
1066  if ((!this->is_setup() && !this->ignore_is_setup_) || (!is_sleep_safe && this->is_sleeping()))
1067  return;
1068 
1069  this->add_no_result_to_queue_with_ignore_sleep_printf_(variable_name, "%s=%" PRId32, variable_name_to_send.c_str(),
1070  state_value);
1071 }
1072 
1081 void Nextion::add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) {
1083  state_value);
1084 }
1085 void Nextion::add_no_result_to_queue_with_set(const std::string &variable_name,
1086  const std::string &variable_name_to_send,
1087  const std::string &state_value) {
1088  this->add_no_result_to_queue_with_set_internal_(variable_name, variable_name_to_send, state_value);
1089 }
1090 
1091 void Nextion::add_no_result_to_queue_with_set_internal_(const std::string &variable_name,
1092  const std::string &variable_name_to_send,
1093  const std::string &state_value, bool is_sleep_safe) {
1094  if ((!this->is_setup() && !this->ignore_is_setup_) || (!is_sleep_safe && this->is_sleeping()))
1095  return;
1096 
1097  this->add_no_result_to_queue_with_printf_(variable_name, "%s=\"%s\"", variable_name_to_send.c_str(),
1098  state_value.c_str());
1099 }
1100 
1102  if ((!this->is_setup() && !this->ignore_is_setup_))
1103  return;
1104 
1105  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
1106  nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
1107 
1108  nextion_queue->component = component;
1109  nextion_queue->queue_time = millis();
1110 
1111  ESP_LOGN(TAG, "Add to queue type: %s component %s", component->get_queue_type_string().c_str(),
1112  component->get_variable_name().c_str());
1113 
1114  std::string command = "get " + component->get_variable_name_to_send();
1115 
1116  if (this->send_command_(command)) {
1117  this->nextion_queue_.push_back(nextion_queue);
1118  }
1119 }
1120 
1130  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
1131  return;
1132 
1133  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
1134  nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
1135 
1136  nextion_queue->component = component;
1137  nextion_queue->queue_time = millis();
1138 
1139  this->waveform_queue_.push_back(nextion_queue);
1140  if (this->waveform_queue_.size() == 1)
1141  this->check_pending_waveform_();
1142 }
1143 
1145  if (this->waveform_queue_.empty())
1146  return;
1147 
1148  auto *nb = this->waveform_queue_.front();
1149  auto *component = nb->component;
1150  size_t buffer_to_send = component->get_wave_buffer_size() < 255 ? component->get_wave_buffer_size()
1151  : 255; // ADDT command can only send 255
1152 
1153  std::string command = "addt " + to_string(component->get_component_id()) + "," +
1154  to_string(component->get_wave_channel_id()) + "," + to_string(buffer_to_send);
1155  if (!this->send_command_(command)) {
1156  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
1157  this->waveform_queue_.pop_front();
1158  }
1159 }
1160 
1161 void Nextion::set_writer(const nextion_writer_t &writer) { this->writer_ = writer; }
1162 
1163 ESPDEPRECATED("set_wait_for_ack(bool) is deprecated and has no effect", "v1.20")
1164 void Nextion::set_wait_for_ack(bool wait_for_ack) { ESP_LOGE(TAG, "This command is deprecated"); }
1165 
1166 bool Nextion::is_updating() { return this->is_updating_; }
1167 
1168 } // namespace nextion
1169 } // namespace esphome
void goto_page(const char *page)
Show the page with a given name.
bool ignore_is_setup_
Sends commands ignoring of the Nextion has been setup.
Definition: nextion.h:1226
const uint16_t startup_override_ms_
Definition: nextion.h:1344
void write_str(const char *str)
Definition: uart.h:27
void all_components_send_state_(bool force_update=false)
Definition: nextion.cpp:877
CallbackManager< void(uint8_t)> page_callback_
Definition: nextion.h:1324
CallbackManager< void()> sleep_callback_
Definition: nextion.h:1322
const char * name
Definition: stm32flash.h:78
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void add_new_page_callback(std::function< void(uint8_t)> &&callback)
Add a callback to be notified when the nextion changes pages.
Definition: nextion.cpp:185
void write_array(const uint8_t *data, size_t len)
Definition: uart.h:21
void add_wake_state_callback(std::function< void()> &&callback)
Add a callback to be notified of wake state changes.
Definition: nextion.cpp:177
bool send_command(const char *command)
Manually send a raw command to the display.
Definition: nextion.cpp:211
bool send_command_printf(const char *format,...) __attribute__((format(printf
Manually send a raw formatted command to the display.
Definition: nextion.cpp:222
void add_addt_command_to_queue(NextionComponentBase *component) override
Add addt command to the queue.
Definition: nextion.cpp:1129
bool is_updating() override
Check if the TFT update process is currently running.
Definition: nextion.cpp:1166
void add_to_get_queue(NextionComponentBase *component) override
Definition: nextion.cpp:1101
std::vector< NextionComponentBase * > touch_
Definition: nextion.h:1316
optional< nextion_writer_t > writer_
Definition: nextion.h:1327
uint16_t x
Definition: tt21100.cpp:17
void add_setup_state_callback(std::function< void()> &&callback)
Add a callback to be notified when the nextion completes its initialize setup.
Definition: nextion.cpp:181
const uint16_t max_q_age_ms_
Definition: nextion.h:1345
bool send_command_(const std::string &command)
Manually send a raw command to the display and don&#39;t wait for an acknowledgement packet.
Definition: nextion.cpp:29
float get_setup_priority() const override
Definition: nextion.cpp:163
void setup() override
Definition: nextion.cpp:12
std::string serial_number_
Definition: nextion.h:1332
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
Definition: nextion.h:1325
bool has_value() const
Definition: optional.h:87
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:25
void set_exit_reparse_on_start(bool exit_reparse)
Sets if Nextion should exit the active reparse mode before the "connect" command is sent...
uint16_t y
Definition: tt21100.cpp:18
bool add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
Sends a formatted command to the nextion.
Definition: nextion.cpp:1026
void add_sleep_state_callback(std::function< void()> &&callback)
Add a callback to be notified of sleep state changes.
Definition: nextion.cpp:173
virtual void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion)
std::string flash_size_
Definition: nextion.h:1333
void set_nextion_sensor_state(int queue_type, const std::string &name, float state)
Set the nextion sensor state object.
Definition: nextion.cpp:820
CallbackManager< void()> setup_callback_
Definition: nextion.h:1321
bool read_byte(uint8_t *data)
Definition: uart.h:29
void set_nextion_text_state(const std::string &name, const std::string &state)
Definition: nextion.cpp:864
void set_wait_for_ack(bool wait_for_ack)
void loop() override
Definition: nextion.cpp:263
std::deque< NextionQueue * > nextion_queue_
Definition: nextion.h:1215
CallbackManager< void()> wake_callback_
Definition: nextion.h:1323
Application App
Global storage of Application pointer - only one Application can exist.
void add_no_result_to_queue_(const std::string &variable_name)
Definition: nextion.cpp:970
std::deque< NextionQueue * > waveform_queue_
Definition: nextion.h:1216
std::string command_data_
Definition: nextion.h:1342
bool remove_from_q_(bool report_empty=true)
Definition: nextion.cpp:308
void set_backlight_brightness(float brightness)
Set the brightness of the backlight.
std::string device_model_
Definition: nextion.h:1330
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)
Definition: nextion.cpp:1063
bool add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
Definition: nextion.cpp:1000
void set_touch_sleep_timeout(uint16_t timeout)
Set the touch sleep timeout of the display.
std::vector< NextionComponentBase * > textsensortype_
Definition: nextion.h:1319
ESPDEPRECATED("set_wait_for_ack(bool) is deprecated and has no effect", "v1.20") void Nextion
Definition: nextion.cpp:1163
void add_touch_event_callback(std::function< void(uint8_t, uint8_t, bool)> &&callback)
Add a callback to be notified when Nextion has a touch event.
Definition: nextion.cpp:189
void set_wake_up_page(uint8_t page_id=255)
Sets which page Nextion loads when exiting sleep mode.
std::vector< NextionComponentBase * > sensortype_
Definition: nextion.h:1318
void dump_config() override
Definition: nextion.cpp:137
std::string to_string(int value)
Definition: helpers.cpp:80
std::vector< NextionComponentBase * > switchtype_
Definition: nextion.h:1317
void set_auto_wake_on_touch(bool auto_wake)
Sets if Nextion should auto-wake from sleep when touch press occurs.
virtual void set_state_from_int(int state_value, bool publish, bool send_to_nextion)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool void add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command)
Definition: nextion.cpp:991
void reset_(bool reset_nextion=true)
Definition: nextion.cpp:127
void update_components_by_prefix(const std::string &prefix)
Definition: nextion.cpp:897
void update() override
Definition: nextion.cpp:164
uint8_t end[39]
Definition: sun_gtil2.cpp:31
std::string firmware_version_
Definition: nextion.h:1331
void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send="")
uint32_t touch_sleep_timeout_
Definition: nextion.h:1234
esphome::sensor::Sensor * sensor
Definition: statsd.h:37
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag)
Definition: nextion.cpp:916
void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value) override
Definition: nextion.cpp:1053
std::function< void(Nextion &)> nextion_writer_t
Definition: nextion.h:34
std::vector< NextionComponentBase * > binarysensortype_
Definition: nextion.h:1320
bool state
Definition: fan.h:34
void set_writer(const nextion_writer_t &writer)
Definition: nextion.cpp:1161
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26