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.

796 lines
28 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
  1. // =============================================================================
  2. // SENSORS - General data
  3. // =============================================================================
  4. #define SENSOR_DEBUG 0 // Debug sensors
  5. #define SENSOR_READ_INTERVAL 6 // Read data from sensors every 6 seconds
  6. #define SENSOR_READ_MIN_INTERVAL 6 // Minimum read interval
  7. #define SENSOR_READ_MAX_INTERVAL 3600 // Maximum read interval
  8. #define SENSOR_INIT_INTERVAL 10000 // Try to re-init non-ready sensors every 10s
  9. #define SENSOR_REPORT_EVERY 10 // Report every this many readings
  10. #define SENSOR_REPORT_MIN_EVERY 1 // Minimum every value
  11. #define SENSOR_REPORT_MAX_EVERY 12 // Maximum
  12. #define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0)
  13. // even if just one sensor (0 for backwards compatibility)
  14. #ifndef SENSOR_POWER_CHECK_STATUS
  15. #define SENSOR_POWER_CHECK_STATUS 1 // If set to 1 the reported power/current/energy will be 0 if the relay[0] is OFF
  16. #endif
  17. #ifndef SENSOR_TEMPERATURE_CORRECTION
  18. #define SENSOR_TEMPERATURE_CORRECTION 0.0 // Offset correction
  19. #endif
  20. #ifndef TEMPERATURE_MIN_CHANGE
  21. #define TEMPERATURE_MIN_CHANGE 0.0 // Minimum temperature change to report
  22. #endif
  23. #ifndef SENSOR_HUMIDITY_CORRECTION
  24. #define SENSOR_HUMIDITY_CORRECTION 0.0 // Offset correction
  25. #endif
  26. #ifndef HUMIDITY_MIN_CHANGE
  27. #define HUMIDITY_MIN_CHANGE 0 // Minimum humidity change to report
  28. #endif
  29. // American Society of Heating, Refrigerating and Air-Conditioning Engineers suggests a range of 45% - 55% humidity to manage health effects and illnesses.
  30. // Comfortable: 30% - 60%
  31. // Recommended: 45% - 55%
  32. // High : 55% - 80%
  33. #define HUMIDITY_NORMAL 0 // > %30
  34. #define HUMIDITY_COMFORTABLE 1 // > %45
  35. #define HUMIDITY_DRY 2 // < %30
  36. #define HUMIDITY_WET 3 // > %70
  37. // United States Environmental Protection Agency - UV Index Scale
  38. // One UV Index unit is equivalent to 25 milliWatts per square meter.
  39. #define UV_INDEX_LOW 0 // 0 to 2 means low danger from the sun's UV rays for the average person.
  40. #define UV_INDEX_MODERATE 1 // 3 to 5 means moderate risk of harm from unprotected sun exposure.
  41. #define UV_INDEX_HIGH 2 // 6 to 7 means high risk of harm from unprotected sun exposure. Protection against skin and eye damage is needed.
  42. #define UV_INDEX_VERY_HIGH 3 // 8 to 10 means very high risk of harm from unprotected sun exposure.
  43. // Take extra precautions because unprotected skin and eyes will be damaged and can burn quickly.
  44. #define UV_INDEX_EXTREME 4 // 11 or more means extreme risk of harm from unprotected sun exposure.
  45. // Take all precautions because unprotected skin and eyes can burn in minutes.
  46. #define SENSOR_PUBLISH_ADDRESSES 0 // Publish sensor addresses
  47. #define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
  48. //------------------------------------------------------------------------------
  49. // UNITS
  50. //------------------------------------------------------------------------------
  51. #define POWER_WATTS 0
  52. #define POWER_KILOWATTS 1
  53. #define ENERGY_JOULES 0
  54. #define ENERGY_KWH 1
  55. #define TMP_CELSIUS 0
  56. #define TMP_FAHRENHEIT 1
  57. #ifndef SENSOR_TEMPERATURE_UNITS
  58. #define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
  59. #endif
  60. #ifndef SENSOR_ENERGY_UNITS
  61. #define SENSOR_ENERGY_UNITS ENERGY_JOULES // Energy units (ENERGY_JOULES | ENERGY_KWH)
  62. #endif
  63. #ifndef SENSOR_POWER_UNITS
  64. #define SENSOR_POWER_UNITS POWER_WATTS // Power units (POWER_WATTS | POWER_KILOWATTS)
  65. #endif
  66. //--------------------------------------------------------------------------------
  67. // Sensor ID
  68. // These should remain over time, do not modify them, only add new ones at the end
  69. //--------------------------------------------------------------------------------
  70. #define SENSOR_DHTXX_ID 0x01
  71. #define SENSOR_DALLAS_ID 0x02
  72. #define SENSOR_EMON_ANALOG_ID 0x03
  73. #define SENSOR_EMON_ADC121_ID 0x04
  74. #define SENSOR_EMON_ADS1X15_ID 0x05
  75. #define SENSOR_HLW8012_ID 0x06
  76. #define SENSOR_V9261F_ID 0x07
  77. #define SENSOR_ECH1560_ID 0x08
  78. #define SENSOR_ANALOG_ID 0x09
  79. #define SENSOR_DIGITAL_ID 0x10
  80. #define SENSOR_EVENTS_ID 0x11
  81. #define SENSOR_PMSX003_ID 0x12
  82. #define SENSOR_BMX280_ID 0x13
  83. #define SENSOR_MHZ19_ID 0x14
  84. #define SENSOR_SI7021_ID 0x15
  85. #define SENSOR_SHT3X_I2C_ID 0x16
  86. #define SENSOR_BH1750_ID 0x17
  87. #define SENSOR_PZEM004T_ID 0x18
  88. #define SENSOR_AM2320_ID 0x19
  89. #define SENSOR_GUVAS12SD_ID 0x20
  90. #define SENSOR_CSE7766_ID 0x21
  91. //--------------------------------------------------------------------------------
  92. // Magnitudes
  93. //--------------------------------------------------------------------------------
  94. #define MAGNITUDE_NONE 0
  95. #define MAGNITUDE_TEMPERATURE 1
  96. #define MAGNITUDE_HUMIDITY 2
  97. #define MAGNITUDE_PRESSURE 3
  98. #define MAGNITUDE_CURRENT 4
  99. #define MAGNITUDE_VOLTAGE 5
  100. #define MAGNITUDE_POWER_ACTIVE 6
  101. #define MAGNITUDE_POWER_APPARENT 7
  102. #define MAGNITUDE_POWER_REACTIVE 8
  103. #define MAGNITUDE_POWER_FACTOR 9
  104. #define MAGNITUDE_ENERGY 10
  105. #define MAGNITUDE_ENERGY_DELTA 11
  106. #define MAGNITUDE_ANALOG 12
  107. #define MAGNITUDE_DIGITAL 13
  108. #define MAGNITUDE_EVENTS 14
  109. #define MAGNITUDE_PM1dot0 15
  110. #define MAGNITUDE_PM2dot5 16
  111. #define MAGNITUDE_PM10 17
  112. #define MAGNITUDE_CO2 18
  113. #define MAGNITUDE_LUX 19
  114. #define MAGNITUDE_UV 20
  115. #define MAGNITUDE_MAX 21
  116. // =============================================================================
  117. // Specific data for each sensor
  118. // =============================================================================
  119. //------------------------------------------------------------------------------
  120. // Analog sensor
  121. // Enable support by passing ANALOG_SUPPORT=1 build flag
  122. //--------------------------------------------------------------------------------
  123. #ifndef ANALOG_SUPPORT
  124. #define ANALOG_SUPPORT 0
  125. #endif
  126. #if ANALOG_SUPPORT
  127. #undef ADC_VCC_ENABLED
  128. #define ADC_VCC_ENABLED 0
  129. #endif
  130. //------------------------------------------------------------------------------
  131. // BH1750
  132. // Enable support by passing BH1750_SUPPORT=1 build flag
  133. // http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf
  134. //------------------------------------------------------------------------------
  135. #ifndef BH1750_SUPPORT
  136. #define BH1750_SUPPORT 0
  137. #endif
  138. #ifndef BH1750_ADDRESS
  139. #define BH1750_ADDRESS 0x00 // 0x00 means auto
  140. #endif
  141. #define BH1750_MODE BH1750_CONTINUOUS_HIGH_RES_MODE
  142. #if BH1750_SUPPORT
  143. #undef I2C_SUPPORT
  144. #define I2C_SUPPORT 1
  145. #endif
  146. //------------------------------------------------------------------------------
  147. // BME280/BMP280
  148. // Enable support by passing BMX280_SUPPORT=1 build flag
  149. //------------------------------------------------------------------------------
  150. #ifndef BMX280_SUPPORT
  151. #define BMX280_SUPPORT 0
  152. #endif
  153. #ifndef BMX280_ADDRESS
  154. #define BMX280_ADDRESS 0x00 // 0x00 means auto
  155. #endif
  156. #define BMX280_MODE 1 // 0 for sleep mode, 1 or 2 for forced mode, 3 for normal mode
  157. #define BMX280_STANDBY 0 // 0 for 0.5ms, 1 for 62.5ms, 2 for 125ms
  158. // 3 for 250ms, 4 for 500ms, 5 for 1000ms
  159. // 6 for 10ms, 7 for 20ms
  160. #define BMX280_FILTER 0 // 0 for OFF, 1 for 2 values, 2 for 4 values, 3 for 8 values and 4 for 16 values
  161. #define BMX280_TEMPERATURE 1 // Oversampling for temperature (set to 0 to disable magnitude)
  162. #define BMX280_HUMIDITY 1 // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
  163. #define BMX280_PRESSURE 1 // Oversampling for pressure (set to 0 to disable magnitude)
  164. #if BMX280_SUPPORT
  165. #undef I2C_SUPPORT
  166. #define I2C_SUPPORT 1
  167. #endif
  168. //------------------------------------------------------------------------------
  169. // Dallas OneWire temperature sensors
  170. // Enable support by passing DALLAS_SUPPORT=1 build flag
  171. //------------------------------------------------------------------------------
  172. #ifndef DALLAS_SUPPORT
  173. #define DALLAS_SUPPORT 0
  174. #endif
  175. #ifndef DALLAS_PIN
  176. #define DALLAS_PIN 14
  177. #endif
  178. #define DALLAS_RESOLUTION 9 // Not used atm
  179. #define DALLAS_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
  180. //------------------------------------------------------------------------------
  181. // DHTXX temperature/humidity sensor
  182. // Enable support by passing DHT_SUPPORT=1 build flag
  183. //------------------------------------------------------------------------------
  184. #ifndef DHT_SUPPORT
  185. #define DHT_SUPPORT 0
  186. #endif
  187. #ifndef DHT_PIN
  188. #define DHT_PIN 14
  189. #endif
  190. #ifndef DHT_TYPE
  191. #define DHT_TYPE DHT_CHIP_DHT22
  192. #endif
  193. //------------------------------------------------------------------------------
  194. // CSE7766 based power sensor
  195. // Enable support by passing CSE7766_SUPPORT=1 build flag
  196. //------------------------------------------------------------------------------
  197. #ifndef CSE7766_SUPPORT
  198. #define CSE7766_SUPPORT 1
  199. #endif
  200. #ifndef CSE7766_PIN
  201. #define CSE7766_PIN 1 // TX pin from the CSE7766
  202. #endif
  203. #ifndef CSE7766_PIN_INVERSE
  204. #define CSE7766_PIN_INVERSE 0 // Signal is inverted
  205. #endif
  206. #define CSE7766_SYNC_INTERVAL 300 // Safe time between transmissions (ms)
  207. #define CSE7766_BAUDRATE 4800 // UART baudrate
  208. #define CSE7766_V1R 1.0 // 1mR current resistor
  209. #define CSE7766_V2R 1.0 // 1M voltage resistor
  210. //------------------------------------------------------------------------------
  211. // Digital sensor
  212. // Enable support by passing DIGITAL_SUPPORT=1 build flag
  213. //------------------------------------------------------------------------------
  214. #ifndef DIGITAL_SUPPORT
  215. #define DIGITAL_SUPPORT 0
  216. #endif
  217. #ifndef DIGITAL_PIN
  218. #define DIGITAL_PIN 2
  219. #endif
  220. #ifndef DIGITAL_PIN_MODE
  221. #define DIGITAL_PIN_MODE INPUT_PULLUP
  222. #endif
  223. #ifndef DIGITAL_DEFAULT_STATE
  224. #define DIGITAL_DEFAULT_STATE 1
  225. #endif
  226. //------------------------------------------------------------------------------
  227. // ECH1560 based power sensor
  228. // Enable support by passing ECH1560_SUPPORT=1 build flag
  229. //------------------------------------------------------------------------------
  230. #ifndef ECH1560_SUPPORT
  231. #define ECH1560_SUPPORT 0
  232. #endif
  233. #ifndef ECH1560_CLK_PIN
  234. #define ECH1560_CLK_PIN 4 // CLK pin for the ECH1560
  235. #endif
  236. #ifndef ECH1560_MISO_PIN
  237. #define ECH1560_MISO_PIN 5 // MISO pin for the ECH1560
  238. #endif
  239. #ifndef ECH1560_INVERTED
  240. #define ECH1560_INVERTED 0 // Signal is inverted
  241. #endif
  242. //------------------------------------------------------------------------------
  243. // Energy Monitor general settings
  244. //------------------------------------------------------------------------------
  245. #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
  246. #define EMON_MAX_TIME 250 // Max time in ms to sample
  247. #define EMON_FILTER_SPEED 512 // Mobile average filter speed
  248. #define EMON_MAINS_VOLTAGE 230 // Mains voltage
  249. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  250. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  251. #define EMON_REPORT_CURRENT 0 // Report current
  252. #define EMON_REPORT_POWER 1 // Report power
  253. #define EMON_REPORT_ENERGY 1 // Report energy
  254. //------------------------------------------------------------------------------
  255. // Energy Monitor based on ADC121
  256. // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
  257. //------------------------------------------------------------------------------
  258. #ifndef EMON_ADC121_SUPPORT
  259. #define EMON_ADC121_SUPPORT 0 // Do not build support by default
  260. #endif
  261. #define EMON_ADC121_I2C_ADDRESS 0x00 // 0x00 means auto
  262. #if EMON_ADC121_SUPPORT
  263. #undef I2C_SUPPORT
  264. #define I2C_SUPPORT 1
  265. #endif
  266. //------------------------------------------------------------------------------
  267. // Energy Monitor based on ADS1X15
  268. // Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
  269. //------------------------------------------------------------------------------
  270. #ifndef EMON_ADS1X15_SUPPORT
  271. #define EMON_ADS1X15_SUPPORT 0 // Do not build support by default
  272. #endif
  273. #define EMON_ADS1X15_I2C_ADDRESS 0x00 // 0x00 means auto
  274. #define EMON_ADS1X15_TYPE ADS1X15_CHIP_ADS1115
  275. #define EMON_ADS1X15_GAIN ADS1X15_REG_CONFIG_PGA_4_096V
  276. #define EMON_ADS1X15_MASK 0x0F // A0=1 A1=2 A2=4 A3=8
  277. #if EMON_ADS1X15_SUPPORT
  278. #undef I2C_SUPPORT
  279. #define I2C_SUPPORT 1
  280. #endif
  281. //------------------------------------------------------------------------------
  282. // Energy Monitor based on interval analog GPIO
  283. // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
  284. //------------------------------------------------------------------------------
  285. #ifndef EMON_ANALOG_SUPPORT
  286. #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
  287. #endif
  288. #if EMON_ANALOG_SUPPORT
  289. #undef ADC_VCC_ENABLED
  290. #define ADC_VCC_ENABLED 0
  291. #endif
  292. //------------------------------------------------------------------------------
  293. // Counter sensor
  294. // Enable support by passing EVENTS_SUPPORT=1 build flag
  295. //------------------------------------------------------------------------------
  296. #ifndef EVENTS_SUPPORT
  297. #define EVENTS_SUPPORT 0 // Do not build with counter support by default
  298. #endif
  299. #ifndef EVENTS_PIN
  300. #define EVENTS_PIN 2 // GPIO to monitor
  301. #endif
  302. #ifndef EVENTS_PIN_MODE
  303. #define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  304. #endif
  305. #ifndef EVENTS_INTERRUPT_MODE
  306. #define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
  307. #endif
  308. #define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
  309. //------------------------------------------------------------------------------
  310. // HLW8012 Energy monitor IC
  311. // Enable support by passing HLW8012_SUPPORT=1 build flag
  312. //------------------------------------------------------------------------------
  313. #ifndef HLW8012_SUPPORT
  314. #define HLW8012_SUPPORT 0
  315. #endif
  316. #ifndef HLW8012_SEL_PIN
  317. #define HLW8012_SEL_PIN 5
  318. #endif
  319. #ifndef HLW8012_CF1_PIN
  320. #define HLW8012_CF1_PIN 13
  321. #endif
  322. #ifndef HLW8012_CF_PIN
  323. #define HLW8012_CF_PIN 14
  324. #endif
  325. #ifndef HLW8012_SEL_CURRENT
  326. #define HLW8012_SEL_CURRENT HIGH // SEL pin to HIGH to measure current
  327. #endif
  328. #ifndef HLW8012_CURRENT_R
  329. #define HLW8012_CURRENT_R 0.001 // Current resistor
  330. #endif
  331. #ifndef HLW8012_VOLTAGE_R_UP
  332. #define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Upstream voltage resistor
  333. #endif
  334. #ifndef HLW8012_VOLTAGE_R_DOWN
  335. #define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor
  336. #endif
  337. #define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
  338. //------------------------------------------------------------------------------
  339. // MHZ19 CO2 sensor
  340. // Enable support by passing MHZ19_SUPPORT=1 build flag
  341. //------------------------------------------------------------------------------
  342. #ifndef MHZ19_SUPPORT
  343. #define MHZ19_SUPPORT 0
  344. #endif
  345. #define MHZ19_RX_PIN 13
  346. #define MHZ19_TX_PIN 15
  347. //------------------------------------------------------------------------------
  348. // Particle Monitor based on Plantower PMSX003
  349. // Enable support by passing PMSX003_SUPPORT=1 build flag
  350. //------------------------------------------------------------------------------
  351. #ifndef PMSX003_SUPPORT
  352. #define PMSX003_SUPPORT 0
  353. #endif
  354. #define PMS_RX_PIN 13
  355. #define PMS_TX_PIN 15
  356. //------------------------------------------------------------------------------
  357. // PZEM004T based power monitor
  358. // Enable support by passing PZEM004T_SUPPORT=1 build flag
  359. //------------------------------------------------------------------------------
  360. #ifndef PZEM004T_SUPPORT
  361. #define PZEM004T_SUPPORT 0
  362. #endif
  363. #ifndef PZEM004T_USE_SOFT
  364. #define PZEM004T_USE_SOFT 1 // Use software serial
  365. #endif
  366. #ifndef PZEM004T_RX_PIN
  367. #define PZEM004T_RX_PIN 13 // Software serial RX GPIO (if PZEM004T_USE_SOFT == 1)
  368. #endif
  369. #ifndef PZEM004T_TX_PIN
  370. #define PZEM004T_TX_PIN 15 // Software serial TX GPIO (if PZEM004T_USE_SOFT == 1)
  371. #endif
  372. #ifndef PZEM004T_HW_PORT
  373. #define PZEM004T_HW_PORT Serial1 // Hardware serial port (if PZEM004T_USE_SOFT == 0)
  374. #endif
  375. //------------------------------------------------------------------------------
  376. // SHT3X I2C (Wemos) temperature & humidity sensor
  377. // Enable support by passing SHT3X_SUPPORT=1 build flag
  378. //------------------------------------------------------------------------------
  379. #ifndef SHT3X_I2C_SUPPORT
  380. #define SHT3X_I2C_SUPPORT 0
  381. #endif
  382. #ifndef SHT3X_I2C_ADDRESS
  383. #define SHT3X_I2C_ADDRESS 0x00 // 0x00 means auto
  384. #endif
  385. #if SHT3X_I2C_SUPPORT
  386. #undef I2C_SUPPORT
  387. #define I2C_SUPPORT 1
  388. #endif
  389. //------------------------------------------------------------------------------
  390. // SI7021 temperature & humidity sensor
  391. // Enable support by passing SI7021_SUPPORT=1 build flag
  392. //------------------------------------------------------------------------------
  393. #ifndef SI7021_SUPPORT
  394. #define SI7021_SUPPORT 0
  395. #endif
  396. #ifndef SI7021_ADDRESS
  397. #define SI7021_ADDRESS 0x00 // 0x00 means auto
  398. #endif
  399. #if SI7021_SUPPORT
  400. #undef I2C_SUPPORT
  401. #define I2C_SUPPORT 1
  402. #endif
  403. //------------------------------------------------------------------------------
  404. // V9261F based power sensor
  405. // Enable support by passing SI7021_SUPPORT=1 build flag
  406. //------------------------------------------------------------------------------
  407. #ifndef V9261F_SUPPORT
  408. #define V9261F_SUPPORT 0
  409. #endif
  410. #ifndef V9261F_PIN
  411. #define V9261F_PIN 2 // TX pin from the V9261F
  412. #endif
  413. #ifndef V9261F_PIN_INVERSE
  414. #define V9261F_PIN_INVERSE 1 // Signal is inverted
  415. #endif
  416. #define V9261F_SYNC_INTERVAL 600 // Sync signal length (ms)
  417. #define V9261F_BAUDRATE 4800 // UART baudrate
  418. // Default ratios
  419. #define V9261F_CURRENT_FACTOR 79371434.0
  420. #define V9261F_VOLTAGE_FACTOR 4160651.0
  421. #define V9261F_POWER_FACTOR 153699.0
  422. #define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR
  423. //------------------------------------------------------------------------------
  424. // AM2320 Humidity & Temperature sensor over I2C
  425. // Enable support by passing AM2320_SUPPORT=1 build flag
  426. //------------------------------------------------------------------------------
  427. #ifndef AM2320_SUPPORT
  428. #define AM2320_SUPPORT 0
  429. #endif
  430. #ifndef AM2320_ADDRESS
  431. #define AM2320_ADDRESS 0x00 // 0x00 means auto
  432. #endif
  433. #if AM2320_SUPPORT
  434. #undef I2C_SUPPORT
  435. #define I2C_SUPPORT 1
  436. #endif
  437. //------------------------------------------------------------------------------
  438. // GUVAS12SD UV Sensor (analog)
  439. // Enable support by passing GUVAS12SD_SUPPORT=1 build flag
  440. //------------------------------------------------------------------------------
  441. #ifndef GUVAS12SD_SUPPORT
  442. #define GUVAS12SD_SUPPORT 0
  443. #endif
  444. #ifndef GUVAS12SD_PIN
  445. #define GUVAS12SD_PIN 14
  446. #endif
  447. // =============================================================================
  448. // Sensor helpers configuration
  449. // =============================================================================
  450. #ifndef SENSOR_SUPPORT
  451. #if ANALOG_SUPPORT || BH1750_SUPPORT || BMX280_SUPPORT || DALLAS_SUPPORT \
  452. || DHT_SUPPORT || DIGITAL_SUPPORT || ECH1560_SUPPORT \
  453. || EMON_ADC121_SUPPORT || EMON_ADS1X15_SUPPORT \
  454. || EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \
  455. || MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \
  456. || SI7021_SUPPORT || V9261F_SUPPORT || AM2320_SUPPORT \
  457. || GUVAS12SD_SUPPORT || CSE7766_SUPPORT
  458. #define SENSOR_SUPPORT 1
  459. #else
  460. #define SENSOR_SUPPORT 0
  461. #endif
  462. #endif
  463. // -----------------------------------------------------------------------------
  464. // I2C
  465. // -----------------------------------------------------------------------------
  466. #ifndef I2C_SUPPORT
  467. #define I2C_SUPPORT 0 // I2C enabled (1.98Kb)
  468. #endif
  469. #define I2C_USE_BRZO 0 // Use brzo_i2c library or standard Wire
  470. #ifndef I2C_SDA_PIN
  471. #define I2C_SDA_PIN SDA // SDA GPIO (Sonoff => 4)
  472. #endif
  473. #ifndef I2C_SCL_PIN
  474. #define I2C_SCL_PIN SCL // SCL GPIO (Sonoff => 14)
  475. #endif
  476. #define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
  477. #define I2C_SCL_FREQUENCY 1000 // BRZO SCL frequency
  478. #define I2C_CLEAR_BUS 0 // Clear I2C bus on boot
  479. #define I2C_PERFORM_SCAN 1 // Perform a bus scan on boot
  480. //--------------------------------------------------------------------------------
  481. // Internal power monitor
  482. // Enable support by passing ADC_VCC_ENABLED=1 build flag
  483. // Do not enable this if using the analog GPIO for any other thing
  484. //--------------------------------------------------------------------------------
  485. #ifndef ADC_VCC_ENABLED
  486. #define ADC_VCC_ENABLED 1
  487. #endif
  488. #if ADC_VCC_ENABLED
  489. ADC_MODE(ADC_VCC);
  490. #endif
  491. //--------------------------------------------------------------------------------
  492. // Class loading
  493. //--------------------------------------------------------------------------------
  494. #if SENSOR_SUPPORT
  495. PROGMEM const unsigned char magnitude_decimals[] = {
  496. 0,
  497. 1, 0, 2,
  498. 3, 0, 0, 0, 0, 0, 0, 0,
  499. 0, 0, 0,
  500. 0, 0, 0,
  501. 0, 0
  502. };
  503. PROGMEM const char magnitude_unknown_topic[] = "unknown";
  504. PROGMEM const char magnitude_temperature_topic[] = "temperature";
  505. PROGMEM const char magnitude_humidity_topic[] = "humidity";
  506. PROGMEM const char magnitude_pressure_topic[] = "pressure";
  507. PROGMEM const char magnitude_current_topic[] = "current";
  508. PROGMEM const char magnitude_voltage_topic[] = "voltage";
  509. PROGMEM const char magnitude_active_power_topic[] = "power";
  510. PROGMEM const char magnitude_apparent_power_topic[] = "apparent";
  511. PROGMEM const char magnitude_reactive_power_topic[] = "reactive";
  512. PROGMEM const char magnitude_power_factor_topic[] = "factor";
  513. PROGMEM const char magnitude_energy_topic[] = "energy";
  514. PROGMEM const char magnitude_energy_delta_topic[] = "energy_delta";
  515. PROGMEM const char magnitude_analog_topic[] = "analog";
  516. PROGMEM const char magnitude_digital_topic[] = "digital";
  517. PROGMEM const char magnitude_events_topic[] = "events";
  518. PROGMEM const char magnitude_pm1dot0_topic[] = "pm1dot0";
  519. PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5";
  520. PROGMEM const char magnitude_pm10_topic[] = "pm10";
  521. PROGMEM const char magnitude_co2_topic[] = "co2";
  522. PROGMEM const char magnitude_lux_topic[] = "lux";
  523. PROGMEM const char magnitude_uv_topic[] = "uv";
  524. PROGMEM const char* const magnitude_topics[] = {
  525. magnitude_unknown_topic, magnitude_temperature_topic, magnitude_humidity_topic,
  526. magnitude_pressure_topic, magnitude_current_topic, magnitude_voltage_topic,
  527. magnitude_active_power_topic, magnitude_apparent_power_topic, magnitude_reactive_power_topic,
  528. magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
  529. magnitude_analog_topic, magnitude_digital_topic, magnitude_events_topic,
  530. magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic,
  531. magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic
  532. };
  533. PROGMEM const char magnitude_empty[] = "";
  534. PROGMEM const char magnitude_celsius[] = "C";
  535. PROGMEM const char magnitude_fahrenheit[] = "F";
  536. PROGMEM const char magnitude_percentage[] = "%";
  537. PROGMEM const char magnitude_hectopascals[] = "hPa";
  538. PROGMEM const char magnitude_amperes[] = "A";
  539. PROGMEM const char magnitude_volts[] = "V";
  540. PROGMEM const char magnitude_watts[] = "W";
  541. PROGMEM const char magnitude_kw[] = "kW";
  542. PROGMEM const char magnitude_joules[] = "J";
  543. PROGMEM const char magnitude_kwh[] = "kWh";
  544. PROGMEM const char magnitude_ugm3[] = "µg/m3";
  545. PROGMEM const char magnitude_ppm[] = "ppm";
  546. PROGMEM const char magnitude_lux[] = "lux";
  547. PROGMEM const char magnitude_uv[] = "uv";
  548. PROGMEM const char* const magnitude_units[] = {
  549. magnitude_empty, magnitude_celsius, magnitude_percentage,
  550. magnitude_hectopascals, magnitude_amperes, magnitude_volts,
  551. magnitude_watts, magnitude_watts, magnitude_watts,
  552. magnitude_percentage, magnitude_joules, magnitude_joules,
  553. magnitude_empty, magnitude_empty, magnitude_empty,
  554. magnitude_ugm3, magnitude_ugm3, magnitude_ugm3,
  555. magnitude_ppm, magnitude_lux, magnitude_uv
  556. };
  557. #include "../sensors/BaseSensor.h"
  558. #if ANALOG_SUPPORT
  559. #include "../sensors/AnalogSensor.h"
  560. #endif
  561. #if BH1750_SUPPORT
  562. #include "../sensors/BH1750Sensor.h"
  563. #endif
  564. #if BMX280_SUPPORT
  565. #include "../sensors/BMX280Sensor.h"
  566. #endif
  567. #if CSE7766_SUPPORT
  568. #include <SoftwareSerial.h>
  569. #include "../sensors/CSE7766Sensor.h"
  570. #endif
  571. #if DALLAS_SUPPORT
  572. #include <OneWire.h>
  573. #include "../sensors/DallasSensor.h"
  574. #endif
  575. #if DHT_SUPPORT
  576. #include "../sensors/DHTSensor.h"
  577. #endif
  578. #if DIGITAL_SUPPORT
  579. #include "../sensors/DigitalSensor.h"
  580. #endif
  581. #if ECH1560_SUPPORT
  582. #include "../sensors/ECH1560Sensor.h"
  583. #endif
  584. #if EMON_ADC121_SUPPORT
  585. #include "../sensors/EmonADC121Sensor.h"
  586. #endif
  587. #if EMON_ADS1X15_SUPPORT
  588. #include "../sensors/EmonADS1X15Sensor.h"
  589. #endif
  590. #if EMON_ANALOG_SUPPORT
  591. #include "../sensors/EmonAnalogSensor.h"
  592. #endif
  593. #if EVENTS_SUPPORT
  594. #include "../sensors/EventSensor.h"
  595. #endif
  596. #if HLW8012_SUPPORT
  597. #include <HLW8012.h>
  598. #include "../sensors/HLW8012Sensor.h"
  599. #endif
  600. #if MHZ19_SUPPORT
  601. #include <SoftwareSerial.h>
  602. #include "../sensors/MHZ19Sensor.h"
  603. #endif
  604. #if PMSX003_SUPPORT
  605. #include <SoftwareSerial.h>
  606. #include <PMS.h>
  607. #include "../sensors/PMSX003Sensor.h"
  608. #endif
  609. #if PZEM004T_SUPPORT
  610. #include <SoftwareSerial.h>
  611. #include "../sensors/PZEM004TSensor.h"
  612. #endif
  613. #if SI7021_SUPPORT
  614. #include "../sensors/SI7021Sensor.h"
  615. #endif
  616. #if SHT3X_I2C_SUPPORT
  617. #include "../sensors/SHT3XI2CSensor.h"
  618. #endif
  619. #if V9261F_SUPPORT
  620. #include <SoftwareSerial.h>
  621. #include "../sensors/V9261FSensor.h"
  622. #endif
  623. #if AM2320_SUPPORT
  624. #include "../sensors/AM2320Sensor.h"
  625. #endif
  626. #if GUVAS12SD_SUPPORT
  627. #include "../sensors/GUVAS12SDSensor.h"
  628. #endif
  629. #endif // SENSOR_SUPPORT