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.

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