ESPHome  2025.2.0
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->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 
193 void Nextion::add_buffer_overflow_event_callback(std::function<void()> &&callback) {
194  this->buffer_overflow_callback_.add(std::move(callback));
195 }
196 
198  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
199  return;
200 
201  for (auto *binarysensortype : this->binarysensortype_) {
202  binarysensortype->update_component();
203  }
204  for (auto *sensortype : this->sensortype_) {
205  sensortype->update_component();
206  }
207  for (auto *switchtype : this->switchtype_) {
208  switchtype->update_component();
209  }
210  for (auto *textsensortype : this->textsensortype_) {
211  textsensortype->update_component();
212  }
213 }
214 
215 bool Nextion::send_command(const char *command) {
216  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
217  return false;
218 
219  if (this->send_command_(command)) {
220  this->add_no_result_to_queue_("send_command");
221  return true;
222  }
223  return false;
224 }
225 
226 bool Nextion::send_command_printf(const char *format, ...) {
227  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
228  return false;
229 
230  char buffer[256];
231  va_list arg;
232  va_start(arg, format);
233  int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
234  va_end(arg);
235  if (ret <= 0) {
236  ESP_LOGW(TAG, "Building command for format '%s' failed!", format);
237  return false;
238  }
239 
240  if (this->send_command_(buffer)) {
241  this->add_no_result_to_queue_("send_command_printf");
242  return true;
243  }
244  return false;
245 }
246 
247 #ifdef NEXTION_PROTOCOL_LOG
249  ESP_LOGN(TAG, "print_queue_members_ (top 10) size %zu", this->nextion_queue_.size());
250  ESP_LOGN(TAG, "*******************************************");
251  int count = 0;
252  for (auto *i : this->nextion_queue_) {
253  if (count++ == 10)
254  break;
255 
256  if (i == nullptr) {
257  ESP_LOGN(TAG, "Nextion queue is null");
258  } else {
259  ESP_LOGN(TAG, "Nextion queue type: %d:%s , name: %s", i->component->get_queue_type(),
260  i->component->get_queue_type_string().c_str(), i->component->get_variable_name().c_str());
261  }
262  }
263  ESP_LOGN(TAG, "*******************************************");
264 }
265 #endif
266 
268  if (!this->check_connect_() || this->is_updating_)
269  return;
270 
271  if (this->nextion_reports_is_setup_ && !this->sent_setup_commands_) {
272  this->ignore_is_setup_ = true;
273  this->sent_setup_commands_ = true;
274  this->send_command_("bkcmd=3"); // Always, returns 0x00 to 0x23 result of serial command.
275 
276  if (this->brightness_.has_value()) {
278  }
279 
280  // Check if a startup page has been set and send the command
281  if (this->start_up_page_ != -1) {
282  this->goto_page(this->start_up_page_);
283  }
284 
285  if (this->wake_up_page_ != -1) {
286  this->set_wake_up_page(this->wake_up_page_);
287  }
288 
289  this->ignore_is_setup_ = false;
290  }
291 
292  this->process_serial_(); // Receive serial data
293  this->process_nextion_commands_(); // Process nextion return commands
294 
295  if (!this->nextion_reports_is_setup_) {
296  if (this->started_ms_ == 0)
297  this->started_ms_ = millis();
298 
299  if (this->started_ms_ + this->startup_override_ms_ < millis()) {
300  ESP_LOGD(TAG, "Manually set nextion report ready");
301  this->nextion_reports_is_setup_ = true;
302  }
303  }
304 }
305 
306 bool Nextion::remove_from_q_(bool report_empty) {
307  if (this->nextion_queue_.empty()) {
308  if (report_empty) {
309  ESP_LOGE(TAG, "Nextion queue is empty!");
310  }
311  return false;
312  }
313 
314  NextionQueue *nb = this->nextion_queue_.front();
315  NextionComponentBase *component = nb->component;
316 
317  ESP_LOGN(TAG, "Removing %s from the queue", component->get_variable_name().c_str());
318 
319  if (component->get_queue_type() == NextionQueueType::NO_RESULT) {
320  if (component->get_variable_name() == "sleep_wake") {
321  this->is_sleeping_ = false;
322  }
323  delete component; // NOLINT(cppcoreguidelines-owning-memory)
324  }
325  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
326  this->nextion_queue_.pop_front();
327  return true;
328 }
329 
331  uint8_t d;
332 
333  while (this->available()) {
334  read_byte(&d);
335  this->command_data_ += d;
336  }
337 }
338 // nextion.tech/instruction-set/
340  if (this->command_data_.empty()) {
341  return;
342  }
343 
344  size_t to_process_length = 0;
345  std::string to_process;
346 
347  ESP_LOGN(TAG, "this->command_data_ %s length %d", this->command_data_.c_str(), this->command_data_.length());
348 #ifdef NEXTION_PROTOCOL_LOG
349  this->print_queue_members_();
350 #endif
351  while ((to_process_length = this->command_data_.find(COMMAND_DELIMITER)) != std::string::npos) {
352  ESP_LOGN(TAG, "print_queue_members_ size %zu", this->nextion_queue_.size());
353  while (to_process_length + COMMAND_DELIMITER.length() < this->command_data_.length() &&
354  static_cast<uint8_t>(this->command_data_[to_process_length + COMMAND_DELIMITER.length()]) == 0xFF) {
355  ++to_process_length;
356  ESP_LOGN(TAG, "Add extra 0xFF to process");
357  }
358 
359  this->nextion_event_ = this->command_data_[0];
360 
361  to_process_length -= 1;
362  to_process = this->command_data_.substr(1, to_process_length);
363 
364  switch (this->nextion_event_) {
365  case 0x00: // instruction sent by user has failed
366  ESP_LOGW(TAG, "Nextion reported invalid instruction!");
367  this->remove_from_q_();
368 
369  break;
370  case 0x01: // instruction sent by user was successful
371 
372  ESP_LOGVV(TAG, "instruction sent by user was successful");
373  ESP_LOGN(TAG, "this->nextion_queue_.empty() %s", this->nextion_queue_.empty() ? "True" : "False");
374 
375  this->remove_from_q_();
376  if (!this->is_setup_) {
377  if (this->nextion_queue_.empty()) {
378  ESP_LOGD(TAG, "Nextion is setup");
379  this->is_setup_ = true;
380  this->setup_callback_.call();
381  }
382  }
383 
384  break;
385  case 0x02: // invalid Component ID or name was used
386  ESP_LOGW(TAG, "Nextion reported component ID or name invalid!");
387  this->remove_from_q_();
388  break;
389  case 0x03: // invalid Page ID or name was used
390  ESP_LOGW(TAG, "Nextion reported page ID invalid!");
391  this->remove_from_q_();
392  break;
393  case 0x04: // invalid Picture ID was used
394  ESP_LOGW(TAG, "Nextion reported picture ID invalid!");
395  this->remove_from_q_();
396  break;
397  case 0x05: // invalid Font ID was used
398  ESP_LOGW(TAG, "Nextion reported font ID invalid!");
399  this->remove_from_q_();
400  break;
401  case 0x06: // File operation fails
402  ESP_LOGW(TAG, "Nextion File operation fail!");
403  break;
404  case 0x09: // Instructions with CRC validation fails their CRC check
405  ESP_LOGW(TAG, "Nextion Instructions with CRC validation fails their CRC check!");
406  break;
407  case 0x11: // invalid Baud rate was used
408  ESP_LOGW(TAG, "Nextion reported baud rate invalid!");
409  break;
410  case 0x12: // invalid Waveform ID or Channel # was used
411  if (this->waveform_queue_.empty()) {
412  ESP_LOGW(TAG,
413  "Nextion reported invalid Waveform ID or Channel # was used but no waveform sensor in queue found!");
414  } else {
415  auto &nb = this->waveform_queue_.front();
416  NextionComponentBase *component = nb->component;
417 
418  ESP_LOGW(TAG, "Nextion reported invalid Waveform ID %d or Channel # %d was used!",
419  component->get_component_id(), component->get_wave_channel_id());
420 
421  ESP_LOGN(TAG, "Removing waveform from queue with component id %d and waveform id %d",
422  component->get_component_id(), component->get_wave_channel_id());
423 
424  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
425  this->waveform_queue_.pop_front();
426  }
427  break;
428  case 0x1A: // variable name invalid
429  ESP_LOGW(TAG, "Nextion reported variable name invalid!");
430  this->remove_from_q_();
431  break;
432  case 0x1B: // variable operation invalid
433  ESP_LOGW(TAG, "Nextion reported variable operation invalid!");
434  this->remove_from_q_();
435  break;
436  case 0x1C: // failed to assign
437  ESP_LOGW(TAG, "Nextion reported failed to assign variable!");
438  this->remove_from_q_();
439  break;
440  case 0x1D: // operate EEPROM failed
441  ESP_LOGW(TAG, "Nextion reported operating EEPROM failed!");
442  break;
443  case 0x1E: // parameter quantity invalid
444  ESP_LOGW(TAG, "Nextion reported parameter quantity invalid!");
445  this->remove_from_q_();
446  break;
447  case 0x1F: // IO operation failed
448  ESP_LOGW(TAG, "Nextion reported component I/O operation invalid!");
449  break;
450  case 0x20: // undefined escape characters
451  ESP_LOGW(TAG, "Nextion reported undefined escape characters!");
452  this->remove_from_q_();
453  break;
454  case 0x23: // too long variable name
455  ESP_LOGW(TAG, "Nextion reported too long variable name!");
456  this->remove_from_q_();
457  break;
458  case 0x24: // Serial Buffer overflow occurs
459  // Buffer will continue to receive the current instruction, all previous instructions are lost.
460  ESP_LOGE(TAG, "Nextion reported Serial Buffer overflow!");
461  this->buffer_overflow_callback_.call();
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 value = 0;
561 
562  for (int i = 0; i < 4; ++i) {
563  value += to_process[i] << (8 * i);
564  }
565 
566  NextionQueue *nb = this->nextion_queue_.front();
567  NextionComponentBase *component = nb->component;
568 
569  if (component->get_queue_type() != NextionQueueType::SENSOR &&
571  component->get_queue_type() != NextionQueueType::SWITCH) {
572  ESP_LOGE(TAG, "ERROR: Received numeric return but next in queue \"%s\" is not a valid sensor type %d",
573  component->get_variable_name().c_str(), component->get_queue_type());
574  } else {
575  ESP_LOGN(TAG, "Received numeric return for variable %s, queue type %d:%s, value %d",
576  component->get_variable_name().c_str(), component->get_queue_type(),
577  component->get_queue_type_string().c_str(), value);
578  component->set_state_from_int(value, true, false);
579  }
580 
581  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
582  this->nextion_queue_.pop_front();
583 
584  break;
585  }
586 
587  case 0x86: { // device automatically enters into sleep mode
588  ESP_LOGVV(TAG, "Received Nextion entering sleep automatically");
589  this->is_sleeping_ = true;
590  this->sleep_callback_.call();
591  break;
592  }
593  case 0x87: // device automatically wakes up
594  {
595  ESP_LOGVV(TAG, "Received Nextion leaves sleep automatically");
596  this->is_sleeping_ = false;
597  this->wake_callback_.call();
598  this->all_components_send_state_(false);
599  break;
600  }
601  case 0x88: // system successful start up
602  {
603  ESP_LOGD(TAG, "system successful start up %zu", to_process_length);
604  this->nextion_reports_is_setup_ = true;
605  break;
606  }
607  case 0x89: { // start SD card upgrade
608  break;
609  }
610  // Data from nextion is
611  // 0x90 - Start
612  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
613  // 00 - NULL
614  // 00/01 - Single byte for on/off
615  // FF FF FF - End
616  case 0x90: { // Switched component
617  std::string variable_name;
618 
619  // Get variable name
620  auto index = to_process.find('\0');
621  if (index == std::string::npos || (to_process_length - index - 1) < 1) {
622  ESP_LOGE(TAG, "Bad switch component data received for 0x90 event!");
623  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
624  break;
625  }
626 
627  variable_name = to_process.substr(0, index);
628  ++index;
629 
630  ESP_LOGN(TAG, "Got Switch:");
631  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
632  ESP_LOGN(TAG, " value: %d", to_process[0] != 0);
633 
634  for (auto *switchtype : this->switchtype_) {
635  switchtype->process_bool(variable_name, to_process[index] != 0);
636  }
637  break;
638  }
639  // Data from nextion is
640  // 0x91 - Start
641  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
642  // 00 - NULL
643  // variable length of 0x71 return data: prints temp1.val,0
644  // FF FF FF - End
645  case 0x91: { // Sensor component
646  std::string variable_name;
647 
648  auto index = to_process.find('\0');
649  if (index == std::string::npos || (to_process_length - index - 1) != 4) {
650  ESP_LOGE(TAG, "Bad sensor component data received for 0x91 event!");
651  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
652  break;
653  }
654 
655  index = to_process.find('\0');
656  variable_name = to_process.substr(0, index);
657  // // Get variable name
658  int value = 0;
659  for (int i = 0; i < 4; ++i) {
660  value += to_process[i + index + 1] << (8 * i);
661  }
662 
663  ESP_LOGN(TAG, "Got sensor:");
664  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
665  ESP_LOGN(TAG, " value: %d", value);
666 
667  for (auto *sensor : this->sensortype_) {
668  sensor->process_sensor(variable_name, value);
669  }
670  break;
671  }
672 
673  // Data from nextion is
674  // 0x92 - Start
675  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
676  // 00 - NULL
677  // variable length of 0x70 return formatted data (bytes) that contain the text prints temp1.txt,0
678  // 00 - NULL
679  // FF FF FF - End
680  case 0x92: { // Text Sensor Component
681  std::string variable_name;
682  std::string text_value;
683 
684  // Get variable name
685  auto index = to_process.find('\0');
686  if (index == std::string::npos || (to_process_length - index - 1) < 1) {
687  ESP_LOGE(TAG, "Bad text sensor component data received for 0x92 event!");
688  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
689  break;
690  }
691 
692  variable_name = to_process.substr(0, index);
693  ++index;
694 
695  text_value = to_process.substr(index);
696 
697  ESP_LOGN(TAG, "Got Text Sensor:");
698  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
699  ESP_LOGN(TAG, " value: %s", text_value.c_str());
700 
701  // NextionTextSensorResponseQueue *nq = new NextionTextSensorResponseQueue;
702  // nq->variable_name = variable_name;
703  // nq->state = text_value;
704  // this->textsensorq_.push_back(nq);
705  for (auto *textsensortype : this->textsensortype_) {
706  textsensortype->process_text(variable_name, text_value);
707  }
708  break;
709  }
710  // Data from nextion is
711  // 0x93 - Start
712  // variable length of 0x70 return formatted data (bytes) that contain the variable name: prints "temp1",0
713  // 00 - NULL
714  // 00/01 - Single byte for on/off
715  // FF FF FF - End
716  case 0x93: { // Binary Sensor component
717  std::string variable_name;
718 
719  // Get variable name
720  auto index = to_process.find('\0');
721  if (index == std::string::npos || (to_process_length - index - 1) < 1) {
722  ESP_LOGE(TAG, "Bad binary sensor component data received for 0x92 event!");
723  ESP_LOGN(TAG, "to_process %s %zu %d", to_process.c_str(), to_process_length, index);
724  break;
725  }
726 
727  variable_name = to_process.substr(0, index);
728  ++index;
729 
730  ESP_LOGN(TAG, "Got Binary Sensor:");
731  ESP_LOGN(TAG, " variable_name: %s", variable_name.c_str());
732  ESP_LOGN(TAG, " value: %d", to_process[index] != 0);
733 
734  for (auto *binarysensortype : this->binarysensortype_) {
735  binarysensortype->process_bool(&variable_name[0], to_process[index] != 0);
736  }
737  break;
738  }
739  case 0xFD: { // data transparent transmit finished
740  ESP_LOGVV(TAG, "Nextion reported data transmit finished!");
741  this->check_pending_waveform_();
742  break;
743  }
744  case 0xFE: { // data transparent transmit ready
745  ESP_LOGVV(TAG, "Nextion reported ready for transmit!");
746  if (this->waveform_queue_.empty()) {
747  ESP_LOGE(TAG, "No waveforms in queue to send data!");
748  break;
749  }
750 
751  auto &nb = this->waveform_queue_.front();
752  auto *component = nb->component;
753  size_t buffer_to_send = component->get_wave_buffer_size() < 255 ? component->get_wave_buffer_size()
754  : 255; // ADDT command can only send 255
755 
756  this->write_array(component->get_wave_buffer().data(), static_cast<int>(buffer_to_send));
757 
758  ESP_LOGN(TAG, "Nextion sending waveform data for component id %d and waveform id %d, size %zu",
759  component->get_component_id(), component->get_wave_channel_id(), buffer_to_send);
760 
761  component->clear_wave_buffer(buffer_to_send);
762  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
763  this->waveform_queue_.pop_front();
764  break;
765  }
766  default:
767  ESP_LOGW(TAG, "Received unknown event from nextion: 0x%02X", this->nextion_event_);
768  break;
769  }
770 
771  // ESP_LOGN(TAG, "nextion_event_ deleting from 0 to %d", to_process_length + COMMAND_DELIMITER.length() + 1);
772  this->command_data_.erase(0, to_process_length + COMMAND_DELIMITER.length() + 1);
773  // App.feed_wdt(); Remove before master merge
774  this->process_serial_();
775  }
776 
777  uint32_t ms = millis();
778 
779  if (!this->nextion_queue_.empty() && this->nextion_queue_.front()->queue_time + this->max_q_age_ms_ < ms) {
780  for (size_t i = 0; i < this->nextion_queue_.size(); i++) {
781  NextionComponentBase *component = this->nextion_queue_[i]->component;
782  if (this->nextion_queue_[i]->queue_time + this->max_q_age_ms_ < ms) {
783  if (this->nextion_queue_[i]->queue_time == 0) {
784  ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\" queue_time 0",
785  component->get_queue_type_string().c_str(), component->get_variable_name().c_str());
786  }
787 
788  if (component->get_variable_name() == "sleep_wake") {
789  this->is_sleeping_ = false;
790  }
791 
792  ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\"", component->get_queue_type_string().c_str(),
793  component->get_variable_name().c_str());
794 
795  if (component->get_queue_type() == NextionQueueType::NO_RESULT) {
796  if (component->get_variable_name() == "sleep_wake") {
797  this->is_sleeping_ = false;
798  }
799  delete component; // NOLINT(cppcoreguidelines-owning-memory)
800  }
801 
802  delete this->nextion_queue_[i]; // NOLINT(cppcoreguidelines-owning-memory)
803 
804  this->nextion_queue_.erase(this->nextion_queue_.begin() + i);
805  i--;
806 
807  } else {
808  break;
809  }
810  }
811  }
812  ESP_LOGN(TAG, "Loop End");
813  // App.feed_wdt(); Remove before master merge
814  this->process_serial_();
815 } // namespace nextion
816 
817 void Nextion::set_nextion_sensor_state(int queue_type, const std::string &name, float state) {
818  this->set_nextion_sensor_state(static_cast<NextionQueueType>(queue_type), name, state);
819 }
820 
821 void Nextion::set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state) {
822  ESP_LOGN(TAG, "Received state:");
823  ESP_LOGN(TAG, " variable: %s", name.c_str());
824  ESP_LOGN(TAG, " state: %lf", state);
825  ESP_LOGN(TAG, " queue type: %d", queue_type);
826 
827  switch (queue_type) {
829  for (auto *sensor : this->sensortype_) {
830  if (name == sensor->get_variable_name()) {
831  sensor->set_state(state, true, true);
832  break;
833  }
834  }
835  break;
836  }
838  for (auto *sensor : this->binarysensortype_) {
839  if (name == sensor->get_variable_name()) {
840  sensor->set_state(state != 0, true, true);
841  break;
842  }
843  }
844  break;
845  }
847  for (auto *sensor : this->switchtype_) {
848  if (name == sensor->get_variable_name()) {
849  sensor->set_state(state != 0, true, true);
850  break;
851  }
852  }
853  break;
854  }
855  default: {
856  ESP_LOGW(TAG, "set_nextion_sensor_state does not support a queue type %d", queue_type);
857  }
858  }
859 }
860 
861 void Nextion::set_nextion_text_state(const std::string &name, const std::string &state) {
862  ESP_LOGD(TAG, "Received state:");
863  ESP_LOGD(TAG, " variable: %s", name.c_str());
864  ESP_LOGD(TAG, " state: %s", state.c_str());
865 
866  for (auto *sensor : this->textsensortype_) {
867  if (name == sensor->get_variable_name()) {
868  sensor->set_state(state, true, true);
869  break;
870  }
871  }
872 }
873 
874 void Nextion::all_components_send_state_(bool force_update) {
875  ESP_LOGD(TAG, "all_components_send_state_ ");
876  for (auto *binarysensortype : this->binarysensortype_) {
877  if (force_update || binarysensortype->get_needs_to_send_update())
878  binarysensortype->send_state_to_nextion();
879  }
880  for (auto *sensortype : this->sensortype_) {
881  if ((force_update || sensortype->get_needs_to_send_update()) && sensortype->get_wave_chan_id() == 0)
882  sensortype->send_state_to_nextion();
883  }
884  for (auto *switchtype : this->switchtype_) {
885  if (force_update || switchtype->get_needs_to_send_update())
886  switchtype->send_state_to_nextion();
887  }
888  for (auto *textsensortype : this->textsensortype_) {
889  if (force_update || textsensortype->get_needs_to_send_update())
890  textsensortype->send_state_to_nextion();
891  }
892 }
893 
894 void Nextion::update_components_by_prefix(const std::string &prefix) {
895  for (auto *binarysensortype : this->binarysensortype_) {
896  if (binarysensortype->get_variable_name().find(prefix, 0) != std::string::npos)
897  binarysensortype->update_component_settings(true);
898  }
899  for (auto *sensortype : this->sensortype_) {
900  if (sensortype->get_variable_name().find(prefix, 0) != std::string::npos)
901  sensortype->update_component_settings(true);
902  }
903  for (auto *switchtype : this->switchtype_) {
904  if (switchtype->get_variable_name().find(prefix, 0) != std::string::npos)
905  switchtype->update_component_settings(true);
906  }
907  for (auto *textsensortype : this->textsensortype_) {
908  if (textsensortype->get_variable_name().find(prefix, 0) != std::string::npos)
909  textsensortype->update_component_settings(true);
910  }
911 }
912 
913 uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag) {
914  uint16_t ret = 0;
915  uint8_t c = 0;
916  uint8_t nr_of_ff_bytes = 0;
917  uint64_t start;
918  bool exit_flag = false;
919  bool ff_flag = false;
920 
921  start = millis();
922 
923  while ((timeout == 0 && this->available()) || millis() - start <= timeout) {
924  if (!this->available()) {
925  App.feed_wdt();
926  delay(1);
927  continue;
928  }
929 
930  this->read_byte(&c);
931  if (c == 0xFF) {
932  nr_of_ff_bytes++;
933  } else {
934  nr_of_ff_bytes = 0;
935  ff_flag = false;
936  }
937 
938  if (nr_of_ff_bytes >= 3)
939  ff_flag = true;
940 
941  response += (char) c;
942  if (recv_flag) {
943  if (response.find(0x05) != std::string::npos) {
944  exit_flag = true;
945  }
946  }
947  App.feed_wdt();
948  delay(2);
949 
950  if (exit_flag || ff_flag) {
951  break;
952  }
953  }
954 
955  if (ff_flag)
956  response = response.substr(0, response.length() - 3); // Remove last 3 0xFF
957 
958  ret = response.length();
959  return ret;
960 }
961 
967 void Nextion::add_no_result_to_queue_(const std::string &variable_name) {
968  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
969  nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
970 
971  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
972  nextion_queue->component = new nextion::NextionComponentBase;
973  nextion_queue->component->set_variable_name(variable_name);
974 
975  nextion_queue->queue_time = millis();
976 
977  this->nextion_queue_.push_back(nextion_queue);
978 
979  ESP_LOGN(TAG, "Add to queue type: NORESULT component %s", nextion_queue->component->get_variable_name().c_str());
980 }
981 
988 void Nextion::add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command) {
989  if ((!this->is_setup() && !this->ignore_is_setup_) || command.empty())
990  return;
991 
992  if (this->send_command_(command)) {
993  this->add_no_result_to_queue_(variable_name);
994  }
995 }
996 
997 bool Nextion::add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,
998  ...) {
999  if ((!this->is_setup() && !this->ignore_is_setup_))
1000  return false;
1001 
1002  char buffer[256];
1003  va_list arg;
1004  va_start(arg, format);
1005  int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
1006  va_end(arg);
1007  if (ret <= 0) {
1008  ESP_LOGW(TAG, "Building command for format '%s' failed!", format);
1009  return false;
1010  }
1011 
1012  this->add_no_result_to_queue_with_command_(variable_name, buffer);
1013  return true;
1014 }
1015 
1023 bool Nextion::add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format, ...) {
1024  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
1025  return false;
1026 
1027  char buffer[256];
1028  va_list arg;
1029  va_start(arg, format);
1030  int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
1031  va_end(arg);
1032  if (ret <= 0) {
1033  ESP_LOGW(TAG, "Building command for format '%s' failed!", format);
1034  return false;
1035  }
1036 
1037  this->add_no_result_to_queue_with_command_(variable_name, buffer);
1038  return true;
1039 }
1040 
1052  state_value);
1053 }
1054 
1055 void Nextion::add_no_result_to_queue_with_set(const std::string &variable_name,
1056  const std::string &variable_name_to_send, int32_t state_value) {
1057  this->add_no_result_to_queue_with_set_internal_(variable_name, variable_name_to_send, state_value);
1058 }
1059 
1060 void Nextion::add_no_result_to_queue_with_set_internal_(const std::string &variable_name,
1061  const std::string &variable_name_to_send, int32_t state_value,
1062  bool is_sleep_safe) {
1063  if ((!this->is_setup() && !this->ignore_is_setup_) || (!is_sleep_safe && this->is_sleeping()))
1064  return;
1065 
1066  this->add_no_result_to_queue_with_ignore_sleep_printf_(variable_name, "%s=%" PRId32, variable_name_to_send.c_str(),
1067  state_value);
1068 }
1069 
1078 void Nextion::add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) {
1080  state_value);
1081 }
1082 void Nextion::add_no_result_to_queue_with_set(const std::string &variable_name,
1083  const std::string &variable_name_to_send,
1084  const std::string &state_value) {
1085  this->add_no_result_to_queue_with_set_internal_(variable_name, variable_name_to_send, state_value);
1086 }
1087 
1088 void Nextion::add_no_result_to_queue_with_set_internal_(const std::string &variable_name,
1089  const std::string &variable_name_to_send,
1090  const std::string &state_value, bool is_sleep_safe) {
1091  if ((!this->is_setup() && !this->ignore_is_setup_) || (!is_sleep_safe && this->is_sleeping()))
1092  return;
1093 
1094  this->add_no_result_to_queue_with_printf_(variable_name, "%s=\"%s\"", variable_name_to_send.c_str(),
1095  state_value.c_str());
1096 }
1097 
1099  if ((!this->is_setup() && !this->ignore_is_setup_))
1100  return;
1101 
1102  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
1103  nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
1104 
1105  nextion_queue->component = component;
1106  nextion_queue->queue_time = millis();
1107 
1108  ESP_LOGN(TAG, "Add to queue type: %s component %s", component->get_queue_type_string().c_str(),
1109  component->get_variable_name().c_str());
1110 
1111  std::string command = "get " + component->get_variable_name_to_send();
1112 
1113  if (this->send_command_(command)) {
1114  this->nextion_queue_.push_back(nextion_queue);
1115  }
1116 }
1117 
1127  if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
1128  return;
1129 
1130  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
1131  nextion::NextionQueue *nextion_queue = new nextion::NextionQueue;
1132 
1133  nextion_queue->component = component;
1134  nextion_queue->queue_time = millis();
1135 
1136  this->waveform_queue_.push_back(nextion_queue);
1137  if (this->waveform_queue_.size() == 1)
1138  this->check_pending_waveform_();
1139 }
1140 
1142  if (this->waveform_queue_.empty())
1143  return;
1144 
1145  auto *nb = this->waveform_queue_.front();
1146  auto *component = nb->component;
1147  size_t buffer_to_send = component->get_wave_buffer_size() < 255 ? component->get_wave_buffer_size()
1148  : 255; // ADDT command can only send 255
1149 
1150  std::string command = "addt " + to_string(component->get_component_id()) + "," +
1151  to_string(component->get_wave_channel_id()) + "," + to_string(buffer_to_send);
1152  if (!this->send_command_(command)) {
1153  delete nb; // NOLINT(cppcoreguidelines-owning-memory)
1154  this->waveform_queue_.pop_front();
1155  }
1156 }
1157 
1158 void Nextion::set_writer(const nextion_writer_t &writer) { this->writer_ = writer; }
1159 
1160 ESPDEPRECATED("set_wait_for_ack(bool) is deprecated and has no effect", "v1.20")
1161 void Nextion::set_wait_for_ack(bool wait_for_ack) { ESP_LOGE(TAG, "This command is deprecated"); }
1162 
1163 bool Nextion::is_updating() { return this->is_updating_; }
1164 
1165 } // namespace nextion
1166 } // namespace esphome
void goto_page(const char *page)
Show the page with a given name.
value_type const & value() const
Definition: optional.h:89
bool ignore_is_setup_
Sends commands ignoring of the Nextion has been setup.
Definition: nextion.h:1241
const uint16_t startup_override_ms_
Definition: nextion.h:1358
void write_str(const char *str)
Definition: uart.h:27
void all_components_send_state_(bool force_update=false)
Definition: nextion.cpp:874
CallbackManager< void(uint8_t)> page_callback_
Definition: nextion.h:1337
CallbackManager< void()> sleep_callback_
Definition: nextion.h:1335
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:215
bool send_command_printf(const char *format,...) __attribute__((format(printf
Manually send a raw formatted command to the display.
Definition: nextion.cpp:226
void add_addt_command_to_queue(NextionComponentBase *component) override
Add addt command to the queue.
Definition: nextion.cpp:1126
bool is_updating() override
Check if the TFT update process is currently running.
Definition: nextion.cpp:1163
void add_to_get_queue(NextionComponentBase *component) override
Definition: nextion.cpp:1098
std::vector< NextionComponentBase * > touch_
Definition: nextion.h:1329
optional< nextion_writer_t > writer_
Definition: nextion.h:1341
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
CallbackManager< void()> buffer_overflow_callback_
Definition: nextion.h:1339
const uint16_t max_q_age_ms_
Definition: nextion.h:1359
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:1346
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
Definition: nextion.h:1338
bool has_value() const
Definition: optional.h:87
void add_buffer_overflow_event_callback(std::function< void()> &&callback)
Add a callback to be notified when the nextion reports a buffer overflow.
Definition: nextion.cpp:193
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:25
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:1023
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:1347
void set_wake_up_page(uint8_t wake_up_page=255)
Sets which page Nextion loads when exiting sleep mode.
void set_nextion_sensor_state(int queue_type, const std::string &name, float state)
Set the nextion sensor state object.
Definition: nextion.cpp:817
CallbackManager< void()> setup_callback_
Definition: nextion.h:1334
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:861
void set_wait_for_ack(bool wait_for_ack)
void loop() override
Definition: nextion.cpp:267
std::deque< NextionQueue * > nextion_queue_
Definition: nextion.h:1230
CallbackManager< void()> wake_callback_
Definition: nextion.h:1336
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:967
std::deque< NextionQueue * > waveform_queue_
Definition: nextion.h:1231
std::string command_data_
Definition: nextion.h:1356
bool remove_from_q_(bool report_empty=true)
Definition: nextion.cpp:306
void set_backlight_brightness(float brightness)
Set the brightness of the backlight.
std::string device_model_
Definition: nextion.h:1344
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:1060
bool add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
Definition: nextion.cpp:997
optional< float > brightness_
Definition: nextion.h:1342
std::vector< NextionComponentBase * > textsensortype_
Definition: nextion.h:1332
ESPDEPRECATED("set_wait_for_ack(bool) is deprecated and has no effect", "v1.20") void Nextion
Definition: nextion.cpp:1160
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
std::vector< NextionComponentBase * > sensortype_
Definition: nextion.h:1331
void dump_config() override
Definition: nextion.cpp:137
std::string to_string(int value)
Definition: helpers.cpp:83
std::vector< NextionComponentBase * > switchtype_
Definition: nextion.h:1330
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:988
void reset_(bool reset_nextion=true)
Definition: nextion.cpp:127
void update_components_by_prefix(const std::string &prefix)
Definition: nextion.cpp:894
void update() override
Definition: nextion.cpp:164
uint8_t end[39]
Definition: sun_gtil2.cpp:31
std::string firmware_version_
Definition: nextion.h:1345
void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send="")
uint32_t touch_sleep_timeout_
Definition: nextion.h:1249
esphome::sensor::Sensor * sensor
Definition: statsd.h:38
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag)
Definition: nextion.cpp:913
void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value) override
Definition: nextion.cpp:1050
std::function< void(Nextion &)> nextion_writer_t
Definition: nextion.h:34
std::vector< NextionComponentBase * > binarysensortype_
Definition: nextion.h:1333
bool state
Definition: fan.h:34
void set_writer(const nextion_writer_t &writer)
Definition: nextion.cpp:1158
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26