Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

683 lines
16 KiB

  1. /*
  2. BOARD MODULE
  3. */
  4. #include "board.h"
  5. #include "relay.h"
  6. #include "sensor.h"
  7. //--------------------------------------------------------------------------------
  8. PROGMEM const char espurna_modules[] =
  9. #if ALEXA_SUPPORT
  10. "ALEXA "
  11. #endif
  12. #if API_SUPPORT
  13. "API "
  14. #endif
  15. #if BROKER_SUPPORT
  16. "BROKER "
  17. #endif
  18. #if BUTTON_SUPPORT
  19. #if BUTTON_EVENTS_SOURCE == BUTTON_EVENTS_SOURCE_GENERIC
  20. "BUTTON "
  21. #else
  22. "BUTTON_DUAL "
  23. #endif
  24. #endif
  25. #if DEBUG_SERIAL_SUPPORT
  26. "DEBUG_SERIAL "
  27. #endif
  28. #if DEBUG_TELNET_SUPPORT
  29. "DEBUG_TELNET "
  30. #endif
  31. #if DEBUG_UDP_SUPPORT
  32. "DEBUG_UDP "
  33. #endif
  34. #if DEBUG_WEB_SUPPORT
  35. "DEBUG_WEB "
  36. #endif
  37. #if DOMOTICZ_SUPPORT
  38. "DOMOTICZ "
  39. #endif
  40. #if ENCODER_SUPPORT
  41. "ENCODER "
  42. #endif
  43. #if HOMEASSISTANT_SUPPORT
  44. "HOMEASSISTANT "
  45. #endif
  46. #if I2C_SUPPORT
  47. "I2C "
  48. #endif
  49. #if INFLUXDB_SUPPORT
  50. "INFLUXDB "
  51. #endif
  52. #if IR_SUPPORT
  53. "IR "
  54. #endif
  55. #if LED_SUPPORT
  56. "LED "
  57. #endif
  58. #if LLMNR_SUPPORT
  59. "LLMNR "
  60. #endif
  61. #if MDNS_CLIENT_SUPPORT
  62. "MDNS_CLIENT "
  63. #endif
  64. #if MDNS_SERVER_SUPPORT
  65. "MDNS_SERVER "
  66. #endif
  67. #if MQTT_SUPPORT
  68. "MQTT "
  69. #endif
  70. #if NETBIOS_SUPPORT
  71. "NETBIOS "
  72. #endif
  73. #if NOFUSS_SUPPORT
  74. "NOFUSS "
  75. #endif
  76. #if NTP_SUPPORT
  77. "NTP "
  78. #endif
  79. #if RFM69_SUPPORT
  80. "RFM69 "
  81. #endif
  82. #if RF_SUPPORT
  83. "RF "
  84. #endif
  85. #if RPN_RULES_SUPPORT
  86. "RPN_RULES "
  87. #endif
  88. #if SCHEDULER_SUPPORT
  89. "SCHEDULER "
  90. #endif
  91. #if SENSOR_SUPPORT
  92. "SENSOR "
  93. #endif
  94. #if SPIFFS_SUPPORT
  95. "SPIFFS "
  96. #endif
  97. #if SSDP_SUPPORT
  98. "SSDP "
  99. #endif
  100. #if TELNET_SUPPORT
  101. #if TELNET_SERVER == TELNET_SERVER_WIFISERVER
  102. "TELNET_SYNC "
  103. #else
  104. "TELNET "
  105. #endif // TELNET_SERVER == TELNET_SERVER_WIFISERVER
  106. #endif
  107. #if TERMINAL_SUPPORT
  108. "TERMINAL "
  109. #endif
  110. #if THERMOSTAT_SUPPORT
  111. "THERMOSTAT "
  112. #endif
  113. #if THERMOSTAT_DISPLAY_SUPPORT
  114. "THERMOSTAT_DISPLAY "
  115. #endif
  116. #if THINGSPEAK_SUPPORT
  117. "THINGSPEAK "
  118. #endif
  119. #if UART_MQTT_SUPPORT
  120. "UART_MQTT "
  121. #endif
  122. #if WEB_SUPPORT
  123. "WEB "
  124. #endif
  125. "";
  126. PROGMEM const char espurna_ota_modules[] =
  127. #if OTA_ARDUINOOTA_SUPPORT
  128. "ARDUINO "
  129. #endif
  130. #if (OTA_CLIENT == OTA_CLIENT_ASYNCTCP)
  131. "ASYNCTCP "
  132. #endif
  133. #if (OTA_CLIENT == OTA_CLIENT_HTTPUPDATE)
  134. #if (SECURE_CLIENT == SECURE_CLIENT_NONE)
  135. "*HTTPUPDATE "
  136. #endif
  137. #if (SECURE_CLIENT == SECURE_CLIENT_AXTLS)
  138. "*HTTPUPDATE_AXTLS "
  139. #endif
  140. #if (SECURE_CLIENT == SECURE_CLIENT_BEARSSL)
  141. "*HTTPUPDATE_BEARSSL "
  142. #endif
  143. #endif // OTA_CLIENT_HTTPUPDATE
  144. #if OTA_MQTT_SUPPORT
  145. "MQTT "
  146. #endif
  147. #if WEB_SUPPORT
  148. "WEB "
  149. #endif
  150. "";
  151. PROGMEM const char espurna_webui[] =
  152. #if WEBUI_IMAGE == WEBUI_IMAGE_SMALL
  153. "SMALL"
  154. #endif
  155. #if WEBUI_IMAGE == WEBUI_IMAGE_LIGHT
  156. "LIGHT"
  157. #endif
  158. #if WEBUI_IMAGE == WEBUI_IMAGE_SENSOR
  159. "SENSOR"
  160. #endif
  161. #if WEBUI_IMAGE == WEBUI_IMAGE_RFBRIDGE
  162. "RFBRIDGE"
  163. #endif
  164. #if WEBUI_IMAGE == WEBUI_IMAGE_RFM69
  165. "RFM69"
  166. #endif
  167. #if WEBUI_IMAGE == WEBUI_IMAGE_LIGHTFOX
  168. "LIGHTFOX"
  169. #endif
  170. #if WEBUI_IMAGE == WEBUI_IMAGE_THERMOSTAT
  171. "THERMOSTAT"
  172. #endif
  173. #if WEBUI_IMAGE == WEBUI_IMAGE_FULL
  174. "FULL"
  175. #endif
  176. "";
  177. #if SENSOR_SUPPORT
  178. PROGMEM const char espurna_sensors[] =
  179. #if AM2320_SUPPORT
  180. "AM2320_I2C "
  181. #endif
  182. #if ANALOG_SUPPORT
  183. "ANALOG "
  184. #endif
  185. #if BH1750_SUPPORT
  186. "BH1750 "
  187. #endif
  188. #if BMP180_SUPPORT
  189. "BMP180 "
  190. #endif
  191. #if BMX280_SUPPORT
  192. "BMX280 "
  193. #endif
  194. #if CSE7766_SUPPORT
  195. "CSE7766 "
  196. #endif
  197. #if DALLAS_SUPPORT
  198. "DALLAS "
  199. #endif
  200. #if DHT_SUPPORT
  201. "DHTXX "
  202. #endif
  203. #if DIGITAL_SUPPORT
  204. "DIGITAL "
  205. #endif
  206. #if ECH1560_SUPPORT
  207. "ECH1560 "
  208. #endif
  209. #if EMON_ADC121_SUPPORT
  210. "EMON_ADC121 "
  211. #endif
  212. #if EMON_ADS1X15_SUPPORT
  213. "EMON_ADX1X15 "
  214. #endif
  215. #if EMON_ANALOG_SUPPORT
  216. "EMON_ANALOG "
  217. #endif
  218. #if EVENTS_SUPPORT
  219. "EVENTS "
  220. #endif
  221. #if GEIGER_SUPPORT
  222. "GEIGER "
  223. #endif
  224. #if GUVAS12SD_SUPPORT
  225. "GUVAS12SD "
  226. #endif
  227. #if HLW8012_SUPPORT
  228. "HLW8012 "
  229. #endif
  230. #if LDR_SUPPORT
  231. "LDR "
  232. #endif
  233. #if MHZ19_SUPPORT
  234. "MHZ19 "
  235. #endif
  236. #if MICS2710_SUPPORT
  237. "MICS2710 "
  238. #endif
  239. #if MICS5525_SUPPORT
  240. "MICS5525 "
  241. #endif
  242. #if NTC_SUPPORT
  243. "NTC "
  244. #endif
  245. #if PMSX003_SUPPORT
  246. "PMSX003 "
  247. #endif
  248. #if PULSEMETER_SUPPORT
  249. "PULSEMETER "
  250. #endif
  251. #if PZEM004T_SUPPORT
  252. "PZEM004T "
  253. #endif
  254. #if SDS011_SUPPORT
  255. "SDS011 "
  256. #endif
  257. #if SENSEAIR_SUPPORT
  258. "SENSEAIR "
  259. #endif
  260. #if SHT3X_I2C_SUPPORT
  261. "SHT3X_I2C "
  262. #endif
  263. #if SI7021_SUPPORT
  264. "SI7021 "
  265. #endif
  266. #if SONAR_SUPPORT
  267. "SONAR "
  268. #endif
  269. #if T6613_SUPPORT
  270. "T6613 "
  271. #endif
  272. #if TMP3X_SUPPORT
  273. "TMP3X "
  274. #endif
  275. #if V9261F_SUPPORT
  276. "V9261F "
  277. #endif
  278. #if VEML6075_SUPPORT
  279. "VEML6075 "
  280. #endif
  281. #if VL53L1X_SUPPORT
  282. "VL53L1X "
  283. #endif
  284. #if EZOPH_SUPPORT
  285. "EZOPH "
  286. #endif
  287. #if ADE7953_SUPPORT
  288. "ADE7953 "
  289. #endif
  290. #if SI1145_SUPPORT
  291. "SI1145 "
  292. #endif
  293. "";
  294. #endif // SENSOR_SUPPORT == 1
  295. //--------------------------------------------------------------------------------
  296. const String& getChipId() {
  297. static String value;
  298. if (!value.length()) {
  299. char buffer[7];
  300. value.reserve(sizeof(buffer));
  301. snprintf_P(buffer, sizeof(buffer), PSTR("%06X"), ESP.getChipId());
  302. value = buffer;
  303. }
  304. return value;
  305. }
  306. const String& getIdentifier() {
  307. static String value;
  308. if (!value.length()) {
  309. value += APP_NAME;
  310. value += '-';
  311. value += getChipId();
  312. }
  313. return value;
  314. }
  315. String getEspurnaModules() {
  316. return FPSTR(espurna_modules);
  317. }
  318. String getEspurnaOTAModules() {
  319. return FPSTR(espurna_ota_modules);
  320. }
  321. #if SENSOR_SUPPORT
  322. String getEspurnaSensors() {
  323. return FPSTR(espurna_sensors);
  324. }
  325. #endif // SENSOR_SUPPORT == 1
  326. String getEspurnaWebUI() {
  327. return FPSTR(espurna_webui);
  328. }
  329. bool isEspurnaCore() {
  330. #if defined(ESPURNA_CORE) || defined(ESPURNA_CORE_WEBUI)
  331. return true;
  332. #else
  333. return false;
  334. #endif
  335. }
  336. bool haveRelaysOrSensors() {
  337. bool result = false;
  338. result = (relayCount() > 0);
  339. #if SENSOR_SUPPORT
  340. result = result || (magnitudeCount() > 0);
  341. #endif
  342. return result;
  343. }
  344. int getBoardId() {
  345. #if defined(ESPURNA_CORE) || defined(ESPURNA_CORE_WEBUI)
  346. return 0;
  347. #elif defined(NODEMCU_LOLIN)
  348. return 2;
  349. #elif defined(NODEMCU_BASIC)
  350. return 3;
  351. #elif defined(WEMOS_D1_MINI)
  352. return 4;
  353. #elif defined(WEMOS_D1_MINI_RELAYSHIELD)
  354. return 5;
  355. #elif defined(WEMOS_D1_TARPUNA_SHIELD)
  356. return 6;
  357. #elif defined(TINKERMAN_ESPURNA_H06)
  358. return 7;
  359. #elif defined(TINKERMAN_ESPURNA_H08)
  360. return 8;
  361. #elif defined(TINKERMAN_ESPURNA_SWITCH)
  362. return 9;
  363. #elif defined(TINKERMAN_RFM69GW)
  364. return 10;
  365. #elif defined(ITEAD_SONOFF_BASIC)
  366. return 11;
  367. #elif defined(ITEAD_SONOFF_RF)
  368. return 12;
  369. #elif defined(ITEAD_SONOFF_MINI)
  370. return 13;
  371. #elif defined(ITEAD_SONOFF_TH)
  372. return 14;
  373. #elif defined(ITEAD_SONOFF_SV)
  374. return 15;
  375. #elif defined(ITEAD_SLAMPHER)
  376. return 16;
  377. #elif defined(ITEAD_S20)
  378. return 17;
  379. #elif defined(ITEAD_SONOFF_TOUCH)
  380. return 18;
  381. #elif defined(ITEAD_SONOFF_POW)
  382. return 19;
  383. #elif defined(ITEAD_SONOFF_POW_R2)
  384. return 20;
  385. #elif defined(ITEAD_SONOFF_DUAL)
  386. return 21;
  387. #elif defined(ITEAD_SONOFF_DUAL_R2)
  388. return 22;
  389. #elif defined(ITEAD_SONOFF_4CH)
  390. return 23;
  391. #elif defined(ITEAD_SONOFF_4CH_PRO)
  392. return 24;
  393. #elif defined(ITEAD_1CH_INCHING)
  394. return 25;
  395. #elif defined(ITEAD_MOTOR)
  396. return 26;
  397. #elif defined(ITEAD_BNSZ01)
  398. return 27;
  399. #elif defined(ITEAD_SONOFF_RFBRIDGE)
  400. return 28;
  401. #elif defined(ITEAD_SONOFF_B1)
  402. return 29;
  403. #elif defined(ITEAD_SONOFF_LED)
  404. return 30;
  405. #elif defined(ITEAD_SONOFF_T1_1CH)
  406. return 31;
  407. #elif defined(ITEAD_SONOFF_T1_2CH)
  408. return 32;
  409. #elif defined(ITEAD_SONOFF_T1_3CH)
  410. return 33;
  411. #elif defined(ITEAD_SONOFF_S31)
  412. return 34;
  413. #elif defined(ITEAD_SONOFF_S31_LITE)
  414. return 35;
  415. #elif defined(ITEAD_SONOFF_IFAN02)
  416. return 36;
  417. #elif defined(ORVIBO_B25)
  418. return 37;
  419. #elif defined(YJZK_SWITCH_1CH)
  420. return 38;
  421. #elif defined(YJZK_SWITCH_2CH)
  422. return 39;
  423. #elif defined(YJZK_SWITCH_3CH)
  424. return 40;
  425. #elif defined(ELECTRODRAGON_WIFI_IOT)
  426. return 41;
  427. #elif defined(WORKCHOICE_ECOPLUG)
  428. return 42;
  429. #elif defined(AITHINKER_AI_LIGHT)
  430. return 43;
  431. #elif defined(LYASI_LIGHT)
  432. return 44;
  433. #elif defined(MAGICHOME_LED_CONTROLLER)
  434. return 45;
  435. #elif defined(MAGICHOME_LED_CONTROLLER_20)
  436. return 46;
  437. #elif defined(MAGICHOME_ZJ_WFMN_A_11)
  438. return 47;
  439. #elif defined(MAGICHOME_ZJ_WFMN_B_11)
  440. return 48;
  441. #elif defined(MAGICHOME_ZJ_WFMN_C_11)
  442. return 49;
  443. #elif defined(MAGICHOME_ZJ_ESPM_5CH_B_13)
  444. return 50;
  445. #elif defined(MAGICHOME_ZJ_LB_RGBWW_L)
  446. return 51;
  447. #elif defined(HUACANXING_H801)
  448. return 52;
  449. #elif defined(HUACANXING_H802)
  450. return 53;
  451. #elif defined(JANGOE_WIFI_RELAY_NC)
  452. return 54;
  453. #elif defined(JANGOE_WIFI_RELAY_NO)
  454. return 55;
  455. #elif defined(JORGEGARCIA_WIFI_RELAYS)
  456. return 56;
  457. #elif defined(OPENENERGYMONITOR_MQTT_RELAY)
  458. return 57;
  459. #elif defined(WION_50055)
  460. return 58;
  461. #elif defined(EXS_WIFI_RELAY_V31)
  462. return 59;
  463. #elif defined(EXS_WIFI_RELAY_V50)
  464. return 60;
  465. #elif defined(GENERIC_V9261F)
  466. return 61;
  467. #elif defined(GENERIC_ECH1560)
  468. return 62;
  469. #elif defined(MANCAVEMADE_ESPLIVE)
  470. return 63;
  471. #elif defined(INTERMITTECH_QUINLED)
  472. return 64;
  473. #elif defined(ARILUX_AL_LC01)
  474. return 65;
  475. #elif defined(ARILUX_AL_LC02)
  476. return 66;
  477. #elif defined(ARILUX_AL_LC02_V14)
  478. return 67;
  479. #elif defined(ARILUX_AL_LC06)
  480. return 68;
  481. #elif defined(ARILUX_AL_LC11)
  482. return 69;
  483. #elif defined(ARILUX_E27)
  484. return 70;
  485. #elif defined(XENON_SM_PW702U)
  486. return 71;
  487. #elif defined(ISELECTOR_SM_PW702)
  488. return 72;
  489. #elif defined(AUTHOMETION_LYT8266)
  490. return 73;
  491. #elif defined(GIZWITS_WITTY_CLOUD)
  492. return 74;
  493. #elif defined(KMC_70011)
  494. return 75;
  495. #elif defined(EUROMATE_WIFI_STECKER_SCHUKO)
  496. return 76;
  497. #elif defined(EUROMATE_WIFI_STECKER_SCHUKO_V2)
  498. return 77;
  499. #elif defined(GENERIC_8CH)
  500. return 78;
  501. #elif defined(STM_RELAY)
  502. return 79;
  503. #elif defined(TONBUX_POWERSTRIP02)
  504. return 80;
  505. #elif defined(LINGAN_SWA1)
  506. return 81;
  507. #elif defined(HEYGO_HY02)
  508. return 82;
  509. #elif defined(MAXCIO_WUS002S)
  510. return 83;
  511. #elif defined(MAXCIO_WDE004)
  512. return 84;
  513. #elif defined(OUKITEL_P1)
  514. return 85;
  515. #elif defined(YIDIAN_XSSSA05)
  516. return 86;
  517. #elif defined(TONBUX_XSSSA01)
  518. return 87;
  519. #elif defined(TONBUX_XSSSA06)
  520. return 88;
  521. #elif defined(GREEN_ESP8266RELAY)
  522. return 89;
  523. #elif defined(IKE_ESPIKE)
  524. return 90;
  525. #elif defined(ARNIEX_SWIFITCH)
  526. return 91;
  527. #elif defined(GENERIC_ESP01S_RELAY_V40)
  528. return 92;
  529. #elif defined(GENERIC_ESP01S_RGBLED_V10)
  530. return 93;
  531. #elif defined(GENERIC_ESP01S_DHT11_V10)
  532. return 94;
  533. #elif defined(GENERIC_ESP01S_DS18B20_V10)
  534. return 95;
  535. #elif defined(PILOTAK_ESP_DIN_V1)
  536. return 96;
  537. #elif defined(HELTEC_TOUCHRELAY)
  538. return 97;
  539. #elif defined(ZHILDE_EU44_W)
  540. return 98;
  541. #elif defined(ALLNET_4DUINO_IOT_WLAN_RELAIS)
  542. return 99;
  543. #elif defined(LUANI_HVIO)
  544. return 100;
  545. #elif defined(TONBUX_MOSQUITO_KILLER)
  546. return 101;
  547. #elif defined(NEO_COOLCAM_NAS_WR01W)
  548. return 102;
  549. #elif defined(DELTACO_SH_P01)
  550. return 103;
  551. #elif defined(DELTACO_SH_P03USB)
  552. return 104;
  553. #elif defined(FORNORM_ZLD_34EU)
  554. return 105;
  555. #elif defined(BH_ONOFRE)
  556. return 106;
  557. #elif defined(BLITZWOLF_BWSHPX)
  558. return 107;
  559. #elif defined(BLITZWOLF_BWSHPX_V23)
  560. return 108;
  561. #elif defined(BLITZWOLF_BWSHP5)
  562. return 109;
  563. #elif defined(TECKIN_SP21)
  564. return 110;
  565. #elif defined(TECKIN_SP22_V14)
  566. return 111;
  567. #elif defined(GOSUND_WS1)
  568. return 112;
  569. #elif defined(HOMECUBE_16A)
  570. return 113;
  571. #elif defined(VANZAVANZU_SMART_WIFI_PLUG_MINI)
  572. return 114;
  573. #elif defined(GENERIC_AG_L4)
  574. return 115;
  575. #elif defined(ALLTERCO_SHELLY1)
  576. return 116;
  577. #elif defined(ALLTERCO_SHELLY2)
  578. return 117;
  579. #elif defined(ALLTERCO_SHELLY1PM)
  580. return 118;
  581. #elif defined(ALLTERCO_SHELLY25)
  582. return 119;
  583. #elif defined(LOHAS_E27_9W)
  584. return 120;
  585. #elif defined(LOHAS_E26_A19)
  586. return 121;
  587. #elif defined(TECKIN_SB53)
  588. return 122;
  589. #elif defined(XIAOMI_SMART_DESK_LAMP)
  590. return 123;
  591. #elif defined(PHYX_ESP12_RGB)
  592. return 124;
  593. #elif defined(IWOOLE_LED_TABLE_LAMP)
  594. return 125;
  595. #elif defined(GENERIC_GU10)
  596. return 126;
  597. #elif defined(GENERIC_E14)
  598. return 127;
  599. #elif defined(DELTACO_SH_LEXXW)
  600. return 128;
  601. #elif defined(DELTACO_SH_LEXXRGB)
  602. return 129;
  603. #elif defined(NEXETE_A19)
  604. return 130;
  605. #elif defined(LOMBEX_LUX_NOVA2_TUNABLE_WHITE)
  606. return 131;
  607. #elif defined(LOMBEX_LUX_NOVA2_WHITE_COLOR)
  608. return 132;
  609. #elif defined(BESTEK_MRJ1011)
  610. return 133;
  611. #elif defined(GBLIFE_RGBW_SOCKET)
  612. return 134;
  613. #elif defined(SMARTLIFE_MINI_SMART_SOCKET)
  614. return 135;
  615. #elif defined(HAMA_WIFI_STECKDOSE_00176533)
  616. return 136;
  617. #elif defined(DIGOO_NX_SP202)
  618. return 137;
  619. #elif defined(FOXEL_LIGHTFOX_DUAL)
  620. return 138;
  621. #elif defined(TECKIN_SP20)
  622. return 139;
  623. #elif defined(LITESUN_LA_WF3)
  624. return 140;
  625. #elif defined(PSH_WIFI_PLUG)
  626. return 141;
  627. #elif defined(PSH_RGBW_CONTROLLER)
  628. return 142;
  629. #elif defined(PSH_WIFI_SENSOR)
  630. return 143;
  631. #elif defined(JINVOO_VALVE_SM_AW713)
  632. return 144;
  633. #elif defined(TUYA_GENERIC_DIMMER)
  634. return 145;
  635. #elif defined(ETEKCITY_ESW01_USA)
  636. return 146;
  637. #elif defined(FS_UAP1)
  638. return 147;
  639. #elif defined(TFLAG_NX_SMX00)
  640. return 148;
  641. #elif defined(MUVIT_IO_MIOBULB001)
  642. return 149;
  643. #elif defined(HYKKER_SMART_HOME_POWER_PLUG)
  644. return 150;
  645. #elif defined(KOGAN_SMARTER_HOME_PLUG_W_POW)
  646. return 151;
  647. #elif defined(LSC_SMART_LED_LIGHT_STRIP)
  648. return 152;
  649. #elif defined(EHOMEDIY_WT02)
  650. return 153;
  651. #elif defined(EHOMEDIY_WT03)
  652. return 154;
  653. #elif defined(LINKSPRITE_LINKNODE_R4)
  654. return 155;
  655. #elif defined(GENERIC_ESP01_512KB)
  656. return 156;
  657. #elif defined(GOSUND_WP3)
  658. return 157;
  659. #else
  660. return -1; // CUSTOM
  661. #endif
  662. }