Advertisement
jak0lantash

IoT control panel

Feb 16th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.62 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <ESP8266WiFi.h>
  3. #include <ESP8266HTTPClient.h>
  4. #include "Adafruit_MQTT.h"
  5. #include "Adafruit_MQTT_Client.h"
  6.  
  7. /* ---- Constants ---- */
  8.  
  9. /* ---- WiFi ---- */
  10. #define WIFI_SSID "xxxxx"
  11. #define WIFI_PASSWORD "xxxxx"
  12. const int WIFI_GRACE_PERIOD = 15000;
  13. // Create an ESP8266 WiFiClient class to connect to the MQTT server.
  14. WiFiClient client;
  15. // or... use WiFiFlientSecure for SSL
  16. //WiFiClientSecure client;
  17.  
  18. /* ---- Home Assistant ---- */
  19. const int API_INTERVAL = 15000;
  20. unsigned long API_last_hello = 0;
  21. String API_HELLO = "http://xxxxx:8123/api/";
  22. bool API_never_been_up = true;
  23. const String API_AUTHORIZATION = "Bearer xxxxxx";
  24. //const String API_AUTHORIZATION = "Bearer test";
  25. const String API_CONTENT_TYPE = "application/json";
  26. String API_GET_STATE = "http://xxxxx:8123/api/states/";
  27. String API_SET_STATE = "http://xxxxx:8123/api/services/";
  28.  
  29. /* ---- WS2812B ---- */
  30. const byte LED_PIN = 0;
  31. const byte LED_COUNT = 4;
  32. byte current_color = 0;
  33. const byte MAX_COLOR = 120;
  34. const byte LED_PHASE1 = 0;
  35. const byte LED_PHASE2 = 3;
  36. const byte LED_PHASE3 = 2;
  37. const byte LED_PHASE4 = 1;
  38. const byte UP_R = 0; // Green is for online/on
  39. const byte UP_G = MAX_COLOR;
  40. const byte UP_B = 0;
  41. const byte DOWN_R = MAX_COLOR; // Red is for offline/off
  42. const byte DOWN_G = 0;
  43. const byte DOWN_B = 0;
  44. const byte HOT_R = 0; // Blue is for cooling 3D Printer
  45. const byte HOT_G = 0;
  46. const byte HOT_B = MAX_COLOR;
  47. const byte PRINTING_R = MAX_COLOR; // Purple is for printing
  48. const byte PRINTING_G = 0;
  49. const byte PRINTING_B = MAX_COLOR;
  50. const byte UNKNOWN_R = MAX_COLOR; // Orange is for unknown
  51. const byte UNKNOWN_G = (int)MAX_COLOR/2;
  52. const byte UNKNOWN_B = 0;
  53. const byte PENDING_R = 0; // Black is for pending
  54. const byte PENDING_G = 0;
  55. const byte PENDING_B = 0;
  56. Adafruit_NeoPixel led_strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  57.  
  58. /* ---- Global ---- */
  59. const byte MATRIX_COMMON_PIN = 5;
  60. const int COMPONENTS_INTERVAL = 500;
  61. const int BUTTONS_READ_INTERVAL = 50;
  62. const byte DEBUG_LEVEL = 1;
  63. unsigned long uptime = millis();
  64. unsigned long buttons_read_last = 0;
  65. const byte STATE_COOL = 2;
  66. const byte STATE_DOWN = 3;
  67. const byte STATE_HOT = 5;
  68. const byte STATE_OFF = 3;
  69. const byte STATE_ON = 2;
  70. const byte STATE_PENDING = 1;
  71. const byte STATE_UNKNOWN = 0;
  72. const byte STATE_UP = 2;
  73. const byte STATE_PRINTING = 6;
  74.  
  75. /* ---- 3D Printer ---- */
  76. const byte ENDER3_BUTTON_PIN = 14;
  77. const byte ENDER3_LED = 2;
  78. String ENDER3_API_STATE = "sensor.ender_3_current_state";
  79. String ENDER3_API_CURRENT_BED_TEMP = "sensor.ender_3_actual_bed_temp";
  80. String ENDER3_API_CURRENT_E0_TEMP = "sensor.ender_3_actual_tool0_temp";
  81. String ENDER3_API_POWER = "switch.power_ender_3";
  82. String ENDER3_API_PRINTING = "binary_sensor.ender_3_printing";
  83. int ENDER3_COOL_BED = 35;
  84. int ENDER3_COOL_EXTRUDER = 35;
  85. byte Ender3_last_known_state = 0;
  86. bool Ender3_requested_change = false;
  87. bool Ender3_button_last_known_state = false;
  88. bool Ender3_was_printing = false;
  89.  
  90. /* ---- PC ---- */
  91. const byte PC_BUTTON_PIN = 4;
  92. const byte PC_LED = 3;
  93. String PC_API = "switch.power_pc";
  94. byte PC_last_known_state = 0;
  95. bool PC_requested_change = false;
  96. bool PC_button_last_known_state = false;
  97.  
  98. /* ---- Screens ---- */
  99. const byte SCREENS_BUTTON_PIN = 13;
  100. const byte SCREENS_LED = 0;
  101. String SCREENS_API = "switch.power_screens";
  102. byte screens_last_known_state = 0;
  103. bool screens_requested_change = false;
  104. bool screens_button_last_known_state = false;
  105.  
  106. /* ---- Soldering Iron ---- */
  107. const byte SOLDERING_IRON_BUTTON_PIN = 12;
  108. const byte SOLDERING_IRON_LED = 1;
  109. String SOLDERING_IRON_API = "switch.soldering_iron";
  110. byte soldering_iron_last_known_state = 0;
  111. bool soldering_iron_requested_change = false;
  112. bool soldering_iron_button_last_known_state = false;
  113.  
  114. /* ---- Functions ---- */
  115. /* ---- WiFi ---- */
  116. void connectWiFi() {
  117. Serial.println();
  118. Serial.println();
  119. Serial.print("Connecting to ");
  120. Serial.println(WIFI_SSID);
  121. WiFi.mode(WIFI_STA);
  122. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  123. while (WiFi.status() != WL_CONNECTED) {
  124. delay(500);
  125. Serial.print(".");
  126. }
  127. Serial.println("");
  128. Serial.println("WiFi connected");
  129. Serial.println("IP address: ");
  130. Serial.println(WiFi.localIP());
  131. }
  132. void disconnectWiFi() {
  133. API_never_been_up = true;
  134. WiFi.disconnect();
  135. }
  136. void checkWiFi() {
  137. if (WiFi.status() != WL_CONNECTED) {
  138. // Reconnect WiFi
  139. showPhase1();
  140. API_never_been_up = true;
  141. connectWiFi();
  142. delay(COMPONENTS_INTERVAL);
  143. // Check API
  144. checkAPI();
  145. }
  146. }
  147.  
  148. /* ---- Home Assistant ---- */
  149. void prepareHTTPRequest(HTTPClient &http, String url) {
  150. http.begin (url);
  151. http.addHeader("Authorization", API_AUTHORIZATION);
  152. http.addHeader("Content-Type", API_CONTENT_TYPE);
  153. }
  154. void checkAPI() {
  155. HTTPClient http;
  156. prepareHTTPRequest(http, API_HELLO);
  157. int httpCode = http.GET();
  158. http.end();
  159. if (httpCode <= 0) {
  160. Serial.print ("HTTP hello failed (" + (String) httpCode + "). ");
  161. if (uptime > WIFI_GRACE_PERIOD) {
  162. Serial.println ("Trying to reconnect to WiFi");
  163. showPhase1();
  164. disconnectWiFi();
  165. } else {
  166. showPhase3();
  167. Serial.println ("Still in grace period.");
  168. }
  169. } else {
  170. Serial.print ("HTTP hello succeeded (" + (String) httpCode + "). ");
  171. API_never_been_up = false;
  172. showPhase4();
  173. delay(COMPONENTS_INTERVAL);
  174. }
  175. }
  176. String simpleJSONExtract(String data, String key) {
  177. // Adding the surrounding quotes to avoid partial match
  178. if (key.indexOf("\"") == -1)
  179. key = "\"" + key + "\"";
  180. // Adding color to avoid matching a value
  181. if (key.indexOf(":") == -1)
  182. key = key + ":";
  183. // Starting by truncating after: "key":
  184. int next_idx = data.indexOf(key);
  185. if (next_idx == -1)
  186. return "";
  187. String value = data.substring(next_idx + 1 + key.length());
  188. debugLog3("1: " + value);
  189. // Then cutting to the first "
  190. next_idx = value.indexOf("\"");
  191. if (next_idx == -1)
  192. return "";
  193. value = value.substring(next_idx + 1);
  194. debugLog3("2: " + value);
  195. // Then cutting until the next "
  196. next_idx = value.indexOf("\"");
  197. if (next_idx == -1)
  198. return "";
  199. value = value.substring(0, next_idx);
  200. debugLog3("3: " + value);
  201. return value;
  202. }
  203. int queryAndDisplayState(String API_id, byte LED_id, byte &last_known_state) {
  204. HTTPClient http;
  205. prepareHTTPRequest(http, API_GET_STATE + API_id);
  206. int httpCode = http.GET();
  207. byte current_state;
  208. if (httpCode != 200) {
  209. debugLog("Query " + API_id + ": HTTP " + (String)httpCode);
  210. current_state = STATE_UNKNOWN;
  211. displayState (LED_id, STATE_UNKNOWN);
  212. } else {
  213. String payload = http.getString();
  214. debugLog3(payload);
  215. String value = simpleJSONExtract(payload, "state");
  216. debugLog2(value);
  217. if (value == "on") {
  218. current_state = STATE_UP;
  219. displayState (LED_id, STATE_UP);
  220. } else if (value == "off") {
  221. current_state = STATE_DOWN;
  222. displayState (LED_id, STATE_DOWN);
  223. } else {
  224. current_state = STATE_UNKNOWN;
  225. displayState (LED_id, STATE_UNKNOWN);
  226. }
  227. }
  228. if (current_state != last_known_state) {
  229. debugLog("Query " + API_id + ": new value " + (String)current_state);
  230. last_known_state = current_state;
  231. }
  232. http.end();
  233. return httpCode;
  234. }
  235. int toggleAndSubmitState(String API_id, byte LED_id, byte &last_known_state) {
  236. displayState (LED_id, STATE_PENDING);
  237. HTTPClient http;
  238. String httpPOSTURL = API_SET_STATE;
  239. String httpPOSTdata = "{\"entity_id\":\"" + API_id + "\"}";
  240. byte requested_state;
  241. if (last_known_state == STATE_UP) {
  242. requested_state = STATE_OFF;
  243. httpPOSTURL += API_id.substring(0,API_id.indexOf(".")) + "/turn_off";
  244. } else {
  245. requested_state = STATE_UP;
  246. httpPOSTURL += API_id.substring(0,API_id.indexOf(".")) + "/turn_on";
  247. }
  248. prepareHTTPRequest(http, httpPOSTURL);
  249. int httpCode = http.POST(httpPOSTdata);
  250. debugLog("POST " + httpPOSTURL + ": HTTP " + (String)httpCode);
  251. if (httpCode != 200 && httpCode != 201) {
  252. debugLog("Payload was " + httpPOSTdata);
  253. last_known_state = STATE_UNKNOWN;
  254. displayState (LED_id, STATE_UNKNOWN);
  255. } else {
  256. debugLog("Requested state becomes new state " + (String)requested_state);
  257. last_known_state = requested_state;
  258. displayState (LED_id, requested_state);
  259. }
  260. http.end();
  261. return httpCode;
  262. }
  263. void Ender3ToggleState() {
  264. displayState (ENDER3_LED, STATE_PENDING);
  265. switch (Ender3_last_known_state) {
  266. // If current state is off, then turn on
  267. case STATE_OFF:
  268. toggleAndSubmitState (ENDER3_API_POWER, ENDER3_LED, Ender3_last_known_state);
  269. break;
  270. // If current state is on, then checking printing state
  271. case STATE_ON:
  272. HTTPClient http;
  273. prepareHTTPRequest(http, API_GET_STATE + ENDER3_API_PRINTING);
  274. int httpCode = http.GET();
  275. if (httpCode != 200) {
  276. debugLog("Query " + ENDER3_API_PRINTING + ": HTTP " + (String)httpCode);
  277. Ender3_last_known_state = STATE_UNKNOWN;
  278. displayState (ENDER3_LED, STATE_UNKNOWN);
  279. } else {
  280. String payload = http.getString();
  281. debugLog3(payload);
  282. String value = simpleJSONExtract(payload, "state");
  283. debugLog2(value);
  284. byte current_state;
  285. if (value == "on") {
  286. debugLog("Ender 3 is printing, denied changing power to OFF");
  287. Ender3_last_known_state = STATE_UNKNOWN;
  288. displayState (ENDER3_LED, STATE_UNKNOWN);
  289. } else if (value == "off") {
  290. debugLog("Ender 3 is NOT printing, granted changing power to OFF");
  291. toggleAndSubmitState (ENDER3_API_POWER, ENDER3_LED, Ender3_last_known_state);
  292. } else {
  293. current_state = STATE_UNKNOWN;
  294. displayState (ENDER3_LED, STATE_UNKNOWN);
  295. }
  296. }
  297. http.end();
  298. break;
  299. }
  300. }
  301. String simplyFetchTheValue(String URL, String entity) {
  302. HTTPClient http;
  303. prepareHTTPRequest(http, URL);
  304. int httpCode = http.GET();
  305. String fetched_value;
  306. if (httpCode == 200) {
  307. fetched_value = simpleJSONExtract(http.getString(), entity);
  308. }
  309. http.end();
  310. return fetched_value;
  311. }
  312. void Ender3FullUpdate() {
  313. HTTPClient http;
  314. prepareHTTPRequest(http, API_GET_STATE + ENDER3_API_POWER);
  315. int httpCode = http.GET();
  316. byte current_state;
  317. if (httpCode != 200) {
  318. debugLog("Query " + ENDER3_API_POWER + ": HTTP " + (String)httpCode);
  319. current_state = STATE_UNKNOWN;
  320. displayState (ENDER3_LED, STATE_UNKNOWN);
  321. } else {
  322. String payload = http.getString();
  323. debugLog3(payload);
  324. String value = simpleJSONExtract(payload, "state");
  325. debugLog2(value);
  326. if (value == "on") {
  327. current_state = STATE_UP;
  328. } else if (value == "off") {
  329. current_state = STATE_DOWN;
  330. Ender3_was_printing = false;
  331. displayState (ENDER3_LED, current_state);
  332. } else {
  333. current_state = STATE_UNKNOWN;
  334. }
  335. }
  336. http.end();
  337. if (current_state != Ender3_last_known_state) {
  338. debugLog("Query " + ENDER3_API_POWER + ": new value " + (String)current_state);
  339. Ender3_last_known_state = current_state;
  340. }
  341.  
  342. if (Ender3_last_known_state == STATE_ON) {
  343. String currently_printing = simplyFetchTheValue (API_GET_STATE + ENDER3_API_PRINTING, "state");
  344. if (currently_printing == "on") {
  345. Ender3_was_printing = true;
  346. displayState (ENDER3_LED, STATE_PRINTING);
  347. } else {
  348. displayState (ENDER3_LED, STATE_UP);
  349. }
  350. if (currently_printing == "off" && Ender3_was_printing) {
  351. float bed_temp = simplyFetchTheValue (API_GET_STATE + ENDER3_API_CURRENT_BED_TEMP, "state").toFloat();
  352. debugLog ("Bed temperature: " + (String)bed_temp);
  353. if (bed_temp == 0) {
  354. displayState (ENDER3_LED, STATE_HOT);
  355. return;
  356. }
  357. if (bed_temp > ENDER3_COOL_BED) {
  358. displayState (ENDER3_LED, STATE_HOT);
  359. return;
  360. }
  361. float extruder_temp = simplyFetchTheValue (API_GET_STATE + ENDER3_API_CURRENT_E0_TEMP, "state").toFloat();
  362. debugLog ("Extruder temperature: " + (String)extruder_temp);
  363. if (extruder_temp == 0) {
  364. displayState (ENDER3_LED, STATE_HOT);
  365. return;
  366. }
  367. if (extruder_temp > ENDER3_COOL_EXTRUDER) {
  368. displayState (ENDER3_LED, STATE_HOT);
  369. return;
  370. }
  371. displayState (ENDER3_LED, STATE_COOL);
  372. }
  373. }
  374. }
  375.  
  376. /* ---- WS2812B ---- */
  377. void applyColorToAllLEDs (int red, int green, int blue) {
  378. for (int i=0; i<LED_COUNT; i++) {
  379. led_strip.setPixelColor (i, red, green, blue);
  380. }
  381. led_strip.show();
  382. }
  383. void applyColorToOneLED (int led, int red, int green, int blue) {
  384. led_strip.setPixelColor (led, red, green, blue);
  385. led_strip.show();
  386. }
  387. void offAllLEDs () {
  388. for (int i=0; i<12; i++) {
  389. led_strip.setPixelColor (i, 0,0,0);
  390. }
  391. led_strip.show();
  392. }
  393. void showPhase1() {
  394. applyColorToAllLEDs(0,0,0);
  395. applyColorToOneLED(LED_PHASE1, MAX_COLOR, MAX_COLOR, MAX_COLOR);
  396. }
  397. void showPhase2() {
  398. showPhase1();
  399. applyColorToOneLED(LED_PHASE2, MAX_COLOR, MAX_COLOR, MAX_COLOR);
  400. }
  401. void showPhase3() {
  402. showPhase2();
  403. applyColorToOneLED(LED_PHASE3, MAX_COLOR, MAX_COLOR, MAX_COLOR);
  404. }
  405. void showPhase4() {
  406. showPhase3();
  407. applyColorToOneLED(LED_PHASE4, MAX_COLOR, MAX_COLOR, MAX_COLOR);
  408. }
  409. void testAllLEDs() {
  410. // Cycle through the colors to validate the LEDs
  411. Serial.println ("All red");
  412. applyColorToAllLEDs (255, 0, 0); delay (1000);
  413. Serial.println ("All green");
  414. applyColorToAllLEDs ( 0, 255, 0); delay (1000);
  415. Serial.println ("All blue");
  416. applyColorToAllLEDs ( 0, 0, 255); delay (1000);
  417. Serial.println ("All off");
  418. applyColorToAllLEDs ( 0, 0, 0); delay (1000);
  419. }
  420. void displayState(byte LED_id, byte state) {
  421. switch (state) {
  422. case STATE_HOT:
  423. applyColorToOneLED (LED_id, HOT_R, HOT_G, HOT_B);
  424. break;
  425. // case STATE_DOWN:
  426. case STATE_OFF:
  427. applyColorToOneLED (LED_id, DOWN_R, DOWN_G, DOWN_B);
  428. break;
  429. case STATE_ON:
  430. // case STATE_UP:
  431. // case STATE_COOL:
  432. applyColorToOneLED (LED_id, UP_R, UP_G, UP_B);
  433. break;
  434. case STATE_PENDING:
  435. applyColorToOneLED (LED_id, PENDING_R, PENDING_G, PENDING_B);
  436. break;
  437. case STATE_UNKNOWN:
  438. applyColorToOneLED (LED_id, UNKNOWN_R, UNKNOWN_G, UNKNOWN_B);
  439. break;
  440. case STATE_PRINTING:
  441. applyColorToOneLED (LED_id, PRINTING_R, PRINTING_G, PRINTING_B);
  442. break;
  443. }
  444. }
  445.  
  446. /* ---- Buttons ---- */
  447. void readButtons() {
  448. pinMode(MATRIX_COMMON_PIN, OUTPUT);
  449. bool button_read = false;
  450. buttons_read_last = millis();
  451.  
  452. byte Ender3_button_read = 0;
  453. byte screens_button_read = 0;
  454. byte soldering_iron_button_read = 0;
  455. byte PC_button_read = 0;
  456. for (int i=0; i<5; i++) {
  457. /* ---- Ender 3 ---- */
  458. pinMode(ENDER3_BUTTON_PIN, INPUT_PULLUP);
  459. Ender3_button_read += digitalRead(ENDER3_BUTTON_PIN);
  460. pinMode(ENDER3_BUTTON_PIN, INPUT);
  461.  
  462. /* ---- Screens ---- */
  463. pinMode(SCREENS_BUTTON_PIN, INPUT_PULLUP);
  464. screens_button_read += digitalRead(SCREENS_BUTTON_PIN);
  465. pinMode(SCREENS_BUTTON_PIN, INPUT);
  466.  
  467. /* ---- Soldering iron ---- */
  468. pinMode(SOLDERING_IRON_BUTTON_PIN, INPUT_PULLUP);
  469. soldering_iron_button_read += digitalRead(SOLDERING_IRON_BUTTON_PIN);
  470. pinMode(SOLDERING_IRON_BUTTON_PIN, INPUT);
  471.  
  472. /* ---- PC ---- */
  473. pinMode(PC_BUTTON_PIN, INPUT_PULLUP);
  474. PC_button_read += digitalRead(PC_BUTTON_PIN);
  475. pinMode(PC_BUTTON_PIN, INPUT);
  476.  
  477. delay (1);
  478. }
  479.  
  480. if (Ender3_button_read == 0) {
  481. if (!Ender3_button_last_known_state) {
  482. Ender3_button_last_known_state = true;
  483. Ender3_requested_change = true;
  484. }
  485. } else {
  486. Ender3_button_last_known_state = false;
  487. }
  488. if (screens_button_read == 0) {
  489. if (!screens_button_last_known_state) {
  490. screens_button_last_known_state = true;
  491. screens_requested_change = true;
  492. }
  493. } else {
  494. screens_button_last_known_state = false;
  495. }
  496. if (soldering_iron_button_read == 0) {
  497. if (!soldering_iron_button_last_known_state) {
  498. soldering_iron_button_last_known_state = true;
  499. soldering_iron_requested_change = true;
  500. }
  501. } else {
  502. soldering_iron_button_last_known_state = false;
  503. }
  504. if (PC_button_read == 0) {
  505. if (!PC_button_last_known_state) {
  506. PC_button_last_known_state = true;
  507. PC_requested_change = true;
  508. }
  509. } else {
  510. PC_button_last_known_state = false;
  511. }
  512.  
  513. pinMode(MATRIX_COMMON_PIN, INPUT_PULLUP);
  514. }
  515.  
  516. /* ---- Setup and Loop ---- */
  517. void setup() {
  518. Serial.begin(115200);
  519. delay(10);
  520. led_strip.begin();
  521. randomSeed (analogRead (0));
  522.  
  523. pinMode(MATRIX_COMMON_PIN, INPUT_PULLUP);
  524. pinMode(ENDER3_BUTTON_PIN, INPUT);
  525. pinMode(SCREENS_BUTTON_PIN, INPUT);
  526. pinMode(SOLDERING_IRON_BUTTON_PIN, INPUT);
  527. pinMode(PC_BUTTON_PIN, INPUT);
  528.  
  529. testAllLEDs();
  530. showPhase1(); delay(2000);
  531. connectWiFi();
  532. showPhase2(); delay(2000);
  533. while (WiFi.status() == WL_CONNECTED && API_never_been_up) {
  534. checkAPI();
  535. delay(COMPONENTS_INTERVAL);
  536. }
  537. delay(2000);
  538. }
  539.  
  540. void loop() {
  541. // When is it
  542. uptime = millis();
  543.  
  544. // Read button changes
  545. if (uptime - buttons_read_last > BUTTONS_READ_INTERVAL) {
  546. readButtons();
  547. }
  548.  
  549. // Apply requested changes
  550. if (Ender3_requested_change) {
  551. Ender3ToggleState();
  552. Ender3_requested_change = false;
  553. }
  554. if (screens_requested_change) {
  555. toggleAndSubmitState(SCREENS_API, SCREENS_LED, screens_last_known_state);
  556. screens_requested_change = false;
  557. }
  558. if (soldering_iron_requested_change) {
  559. toggleAndSubmitState(SOLDERING_IRON_API, SOLDERING_IRON_LED, soldering_iron_last_known_state);
  560. soldering_iron_requested_change = false;
  561. }
  562. if (PC_requested_change) {
  563. toggleAndSubmitState(PC_API, PC_LED, PC_last_known_state);
  564. PC_requested_change = false;
  565. }
  566.  
  567. // Read states from HomeAssistant
  568. if (uptime - API_last_hello > API_INTERVAL) {
  569. if (WiFi.status() == WL_CONNECTED) {
  570. queryAndDisplayState (SCREENS_API, SCREENS_LED, screens_last_known_state);
  571. queryAndDisplayState (SOLDERING_IRON_API, SOLDERING_IRON_LED, soldering_iron_last_known_state);
  572. queryAndDisplayState (PC_API, PC_LED, PC_last_known_state);
  573.  
  574. Ender3FullUpdate();
  575.  
  576. Ender3_requested_change = false;
  577. screens_requested_change = false;
  578. soldering_iron_requested_change = false;
  579. PC_requested_change = false;
  580.  
  581. API_last_hello = millis();
  582. delay(COMPONENTS_INTERVAL);
  583. } else {
  584. checkWiFi();
  585. }
  586. }
  587. }
  588.  
  589. void debugLog(String string) {
  590. if (DEBUG_LEVEL >= 1)
  591. Serial.println(string);
  592. }
  593. void debugLog2(String string) {
  594. if (DEBUG_LEVEL >= 2)
  595. Serial.println(string);
  596. }
  597. void debugLog3(String string) {
  598. if (DEBUG_LEVEL >= 3)
  599. Serial.println(string);
  600. }
  601.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement