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.

993 lines
34 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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 1 // 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 60 // 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. #ifndef ENERGY_MAX_CHANGE
  30. #define ENERGY_MAX_CHANGE 0 // Maximum energy change to report (if >0 it will allways report when delta(E) is greater than this)
  31. #endif
  32. #ifndef SENSOR_SAVE_EVERY
  33. #define SENSOR_SAVE_EVERY 0 // Save accumulating values to EEPROM (atm only energy)
  34. // A 0 means do not save and it's the default value
  35. // A number different from 0 means it should store the value in EEPROM
  36. // after these many reports
  37. // Warning: this might wear out flash fast!
  38. #endif
  39. #define SENSOR_PUBLISH_ADDRESSES 0 // Publish sensor addresses
  40. #define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
  41. #ifndef SENSOR_TEMPERATURE_UNITS
  42. #define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
  43. #endif
  44. #ifndef SENSOR_ENERGY_UNITS
  45. #define SENSOR_ENERGY_UNITS ENERGY_JOULES // Energy units (ENERGY_JOULES | ENERGY_KWH)
  46. #endif
  47. #ifndef SENSOR_POWER_UNITS
  48. #define SENSOR_POWER_UNITS POWER_WATTS // Power units (POWER_WATTS | POWER_KILOWATTS)
  49. #endif
  50. // =============================================================================
  51. // Specific data for each sensor
  52. // =============================================================================
  53. //------------------------------------------------------------------------------
  54. // AM2320 Humidity & Temperature sensor over I2C
  55. // Enable support by passing AM2320_SUPPORT=1 build flag
  56. //------------------------------------------------------------------------------
  57. #ifndef AM2320_SUPPORT
  58. #define AM2320_SUPPORT 0
  59. #endif
  60. #ifndef AM2320_ADDRESS
  61. #define AM2320_ADDRESS 0x00 // 0x00 means auto
  62. #endif
  63. //------------------------------------------------------------------------------
  64. // Analog sensor
  65. // Enable support by passing ANALOG_SUPPORT=1 build flag
  66. //--------------------------------------------------------------------------------
  67. #ifndef ANALOG_SUPPORT
  68. #define ANALOG_SUPPORT 0
  69. #endif
  70. #ifndef ANALOG_SAMPLES
  71. #define ANALOG_SAMPLES 10 // Number of samples
  72. #endif
  73. #ifndef ANALOG_DELAY
  74. #define ANALOG_DELAY 0 // Delay between samples in micros
  75. #endif
  76. //------------------------------------------------------------------------------
  77. // BH1750
  78. // Enable support by passing BH1750_SUPPORT=1 build flag
  79. // http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf
  80. //------------------------------------------------------------------------------
  81. #ifndef BH1750_SUPPORT
  82. #define BH1750_SUPPORT 0
  83. #endif
  84. #ifndef BH1750_ADDRESS
  85. #define BH1750_ADDRESS 0x00 // 0x00 means auto
  86. #endif
  87. #define BH1750_MODE BH1750_CONTINUOUS_HIGH_RES_MODE
  88. //------------------------------------------------------------------------------
  89. // VL53L1X
  90. // Enable support by passing VL53L1X_SUPPORT=1 build flag
  91. //------------------------------------------------------------------------------
  92. #ifndef VL53L1X_SUPPORT
  93. #define VL53L1X_SUPPORT 0
  94. #endif
  95. #ifndef VL53L1X_I2C_ADDRESS
  96. #define VL53L1X_I2C_ADDRESS 0x00 // 0x00 means auto
  97. #endif
  98. #ifndef VL53L1X_DISTANCE_MODE
  99. #define VL53L1X_DISTANCE_MODE VL53L1X::Long // The distance mode of the sensor. Can be one of
  100. #endif // `VL53L1X::Short`, `VL53L1X::Medium`, or `VL53L1X::Long.
  101. // Shorter distance modes are less affected by ambient light
  102. // but have lower maximum ranges, especially in the dark.
  103. #ifndef VL53L1X_MEASUREMENT_TIMING_BUDGET
  104. #define VL53L1X_MEASUREMENT_TIMING_BUDGET 140000 // The time, in microseconds, allocated for a single
  105. // measurement. A longer timing budget allows for more
  106. // accurate at the cost of power. The minimum budget is
  107. // 20 ms (20000 us) in short distance mode and 33 ms for
  108. // medium and long distance modes.
  109. #endif
  110. #ifndef VL53L1X_INTER_MEASUREMENT_PERIOD
  111. #define VL53L1X_INTER_MEASUREMENT_PERIOD 50 // Period, in milliseconds, determining how
  112. #endif // often the sensor takes a measurement.
  113. //------------------------------------------------------------------------------
  114. // BME280/BMP280
  115. // Enable support by passing BMX280_SUPPORT=1 build flag
  116. //------------------------------------------------------------------------------
  117. #ifndef BMX280_SUPPORT
  118. #define BMX280_SUPPORT 0
  119. #endif
  120. #ifndef BMX280_ADDRESS
  121. #define BMX280_ADDRESS 0x00 // 0x00 means auto
  122. #endif
  123. #define BMX280_MODE 1 // 0 for sleep mode, 1 or 2 for forced mode, 3 for normal mode
  124. #define BMX280_STANDBY 0 // 0 for 0.5ms, 1 for 62.5ms, 2 for 125ms
  125. // 3 for 250ms, 4 for 500ms, 5 for 1000ms
  126. // 6 for 10ms, 7 for 20ms
  127. #define BMX280_FILTER 0 // 0 for OFF, 1 for 2 values, 2 for 4 values, 3 for 8 values and 4 for 16 values
  128. #define BMX280_TEMPERATURE 1 // Oversampling for temperature (set to 0 to disable magnitude)
  129. #define BMX280_HUMIDITY 1 // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
  130. #define BMX280_PRESSURE 1 // Oversampling for pressure (set to 0 to disable magnitude)
  131. //------------------------------------------------------------------------------
  132. // Dallas OneWire temperature sensors
  133. // Enable support by passing DALLAS_SUPPORT=1 build flag
  134. //------------------------------------------------------------------------------
  135. #ifndef DALLAS_SUPPORT
  136. #define DALLAS_SUPPORT 0
  137. #endif
  138. #ifndef DALLAS_PIN
  139. #define DALLAS_PIN 14
  140. #endif
  141. #define DALLAS_RESOLUTION 9 // Not used atm
  142. #define DALLAS_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
  143. //------------------------------------------------------------------------------
  144. // DHTXX temperature/humidity sensor
  145. // Enable support by passing DHT_SUPPORT=1 build flag
  146. //------------------------------------------------------------------------------
  147. #ifndef DHT_SUPPORT
  148. #define DHT_SUPPORT 0
  149. #endif
  150. #ifndef DHT_PIN
  151. #define DHT_PIN 14
  152. #endif
  153. #ifndef DHT_TYPE
  154. #define DHT_TYPE DHT_CHIP_DHT22
  155. #endif
  156. //------------------------------------------------------------------------------
  157. // CSE7766 based power sensor
  158. // Enable support by passing CSE7766_SUPPORT=1 build flag
  159. //------------------------------------------------------------------------------
  160. #ifndef CSE7766_SUPPORT
  161. #define CSE7766_SUPPORT 0
  162. #endif
  163. #ifndef CSE7766_PIN
  164. #define CSE7766_PIN 1 // TX pin from the CSE7766
  165. #endif
  166. #ifndef CSE7766_PIN_INVERSE
  167. #define CSE7766_PIN_INVERSE 0 // Signal is inverted
  168. #endif
  169. #define CSE7766_SYNC_INTERVAL 300 // Safe time between transmissions (ms)
  170. #define CSE7766_BAUDRATE 4800 // UART baudrate
  171. #define CSE7766_V1R 1.0 // 1mR current resistor
  172. #define CSE7766_V2R 1.0 // 1M voltage resistor
  173. //------------------------------------------------------------------------------
  174. // Digital sensor
  175. // Enable support by passing DIGITAL_SUPPORT=1 build flag
  176. //------------------------------------------------------------------------------
  177. #ifndef DIGITAL_SUPPORT
  178. #define DIGITAL_SUPPORT 0
  179. #endif
  180. #ifndef DIGITAL_PIN
  181. #define DIGITAL_PIN 2
  182. #endif
  183. #ifndef DIGITAL_PIN_MODE
  184. #define DIGITAL_PIN_MODE INPUT_PULLUP
  185. #endif
  186. #ifndef DIGITAL_DEFAULT_STATE
  187. #define DIGITAL_DEFAULT_STATE 1
  188. #endif
  189. //------------------------------------------------------------------------------
  190. // ECH1560 based power sensor
  191. // Enable support by passing ECH1560_SUPPORT=1 build flag
  192. //------------------------------------------------------------------------------
  193. #ifndef ECH1560_SUPPORT
  194. #define ECH1560_SUPPORT 0
  195. #endif
  196. #ifndef ECH1560_CLK_PIN
  197. #define ECH1560_CLK_PIN 4 // CLK pin for the ECH1560
  198. #endif
  199. #ifndef ECH1560_MISO_PIN
  200. #define ECH1560_MISO_PIN 5 // MISO pin for the ECH1560
  201. #endif
  202. #ifndef ECH1560_INVERTED
  203. #define ECH1560_INVERTED 0 // Signal is inverted
  204. #endif
  205. //------------------------------------------------------------------------------
  206. // Energy Monitor general settings
  207. //------------------------------------------------------------------------------
  208. #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
  209. #define EMON_MAX_TIME 250 // Max time in ms to sample
  210. #define EMON_FILTER_SPEED 512 // Mobile average filter speed
  211. #define EMON_MAINS_VOLTAGE 230 // Mains voltage
  212. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  213. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30A/1V)
  214. #define EMON_REPORT_CURRENT 0 // Report current
  215. #define EMON_REPORT_POWER 1 // Report power
  216. #define EMON_REPORT_ENERGY 1 // Report energy
  217. //------------------------------------------------------------------------------
  218. // Energy Monitor based on ADC121
  219. // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
  220. //------------------------------------------------------------------------------
  221. #ifndef EMON_ADC121_SUPPORT
  222. #define EMON_ADC121_SUPPORT 0 // Do not build support by default
  223. #endif
  224. #define EMON_ADC121_I2C_ADDRESS 0x00 // 0x00 means auto
  225. //------------------------------------------------------------------------------
  226. // Energy Monitor based on ADS1X15
  227. // Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
  228. //------------------------------------------------------------------------------
  229. #ifndef EMON_ADS1X15_SUPPORT
  230. #define EMON_ADS1X15_SUPPORT 0 // Do not build support by default
  231. #endif
  232. #define EMON_ADS1X15_I2C_ADDRESS 0x00 // 0x00 means auto
  233. #define EMON_ADS1X15_TYPE ADS1X15_CHIP_ADS1115
  234. #define EMON_ADS1X15_GAIN ADS1X15_REG_CONFIG_PGA_4_096V
  235. #define EMON_ADS1X15_MASK 0x0F // A0=1 A1=2 A2=4 A3=8
  236. //------------------------------------------------------------------------------
  237. // Energy Monitor based on interval analog GPIO
  238. // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
  239. //------------------------------------------------------------------------------
  240. #ifndef EMON_ANALOG_SUPPORT
  241. #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
  242. #endif
  243. //------------------------------------------------------------------------------
  244. // Counter sensor
  245. // Enable support by passing EVENTS_SUPPORT=1 build flag
  246. //------------------------------------------------------------------------------
  247. #ifndef EVENTS_SUPPORT
  248. #define EVENTS_SUPPORT 0 // Do not build with counter support by default
  249. #endif
  250. #ifndef EVENTS_TRIGGER
  251. #define EVENTS_TRIGGER 1 // 1 to trigger callback on events,
  252. // 0 to only count them and report periodically
  253. #endif
  254. #ifndef EVENTS_PIN
  255. #define EVENTS_PIN 2 // GPIO to monitor
  256. #endif
  257. #ifndef EVENTS_PIN_MODE
  258. #define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  259. #endif
  260. #ifndef EVENTS_INTERRUPT_MODE
  261. #define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
  262. #endif
  263. #define EVENTS_DEBOUNCE 50 // Do not register events within less than 50 millis
  264. //------------------------------------------------------------------------------
  265. // Geiger sensor
  266. // Enable support by passing GEIGER_SUPPORT=1 build flag
  267. //------------------------------------------------------------------------------
  268. #ifndef GEIGER_SUPPORT
  269. #define GEIGER_SUPPORT 0 // Do not build with geiger support by default
  270. #endif
  271. #ifndef GEIGER_PIN
  272. #define GEIGER_PIN D1 // GPIO to monitor "D1" => "GPIO5"
  273. #endif
  274. #ifndef GEIGER_PIN_MODE
  275. #define GEIGER_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  276. #endif
  277. #ifndef GEIGER_INTERRUPT_MODE
  278. #define GEIGER_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
  279. #endif
  280. #define GEIGER_DEBOUNCE 25 // Do not register events within less than 25 millis.
  281. // Value derived here: Debounce time 25ms, because https://github.com/Trickx/espurna/wiki/Geiger-counter
  282. #define GEIGER_CPM2SIEVERT 240 // CPM to µSievert per hour conversion factor
  283. // Typically the literature uses the invers, but I find an integer type more convienient.
  284. #define GEIGER_REPORT_SIEVERTS 1 // Enabler for local dose rate reports in µSv/h
  285. #define GEIGER_REPORT_CPM 1 // Enabler for local dose rate reports in counts per minute
  286. //------------------------------------------------------------------------------
  287. // GUVAS12SD UV Sensor (analog)
  288. // Enable support by passing GUVAS12SD_SUPPORT=1 build flag
  289. //------------------------------------------------------------------------------
  290. #ifndef GUVAS12SD_SUPPORT
  291. #define GUVAS12SD_SUPPORT 0
  292. #endif
  293. #ifndef GUVAS12SD_PIN
  294. #define GUVAS12SD_PIN 14
  295. #endif
  296. //------------------------------------------------------------------------------
  297. // HLW8012 Energy monitor IC
  298. // Enable support by passing HLW8012_SUPPORT=1 build flag
  299. //------------------------------------------------------------------------------
  300. #ifndef HLW8012_SUPPORT
  301. #define HLW8012_SUPPORT 0
  302. #endif
  303. #ifndef HLW8012_SEL_PIN
  304. #define HLW8012_SEL_PIN 5
  305. #endif
  306. #ifndef HLW8012_CF1_PIN
  307. #define HLW8012_CF1_PIN 13
  308. #endif
  309. #ifndef HLW8012_CF_PIN
  310. #define HLW8012_CF_PIN 14
  311. #endif
  312. #ifndef HLW8012_SEL_CURRENT
  313. #define HLW8012_SEL_CURRENT HIGH // SEL pin to HIGH to measure current
  314. #endif
  315. #ifndef HLW8012_CURRENT_R
  316. #define HLW8012_CURRENT_R 0.001 // Current resistor
  317. #endif
  318. #ifndef HLW8012_VOLTAGE_R_UP
  319. #define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Upstream voltage resistor
  320. #endif
  321. #ifndef HLW8012_VOLTAGE_R_DOWN
  322. #define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor
  323. #endif
  324. #ifndef HLW8012_CURRENT_RATIO
  325. #define HLW8012_CURRENT_RATIO 0 // Set to 0 to use factory defaults
  326. #endif
  327. #ifndef HLW8012_VOLTAGE_RATIO
  328. #define HLW8012_VOLTAGE_RATIO 0 // Set to 0 to use factory defaults
  329. #endif
  330. #ifndef HLW8012_POWER_RATIO
  331. #define HLW8012_POWER_RATIO 0 // Set to 0 to use factory defaults
  332. #endif
  333. #ifndef HLW8012_USE_INTERRUPTS
  334. #define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
  335. #endif
  336. #ifndef HLW8012_WAIT_FOR_WIFI
  337. #define HLW8012_WAIT_FOR_WIFI 0 // Weather to enable interrupts only after
  338. // wifi connection has been stablished
  339. #endif
  340. #ifndef HLW8012_INTERRUPT_ON
  341. #define HLW8012_INTERRUPT_ON CHANGE // When to trigger the interrupt
  342. // Use CHANGE for HLW8012
  343. // Use FALLING for BL0937 / HJL0
  344. #endif
  345. //------------------------------------------------------------------------------
  346. // MHZ19 CO2 sensor
  347. // Enable support by passing MHZ19_SUPPORT=1 build flag
  348. //------------------------------------------------------------------------------
  349. #ifndef MHZ19_SUPPORT
  350. #define MHZ19_SUPPORT 0
  351. #endif
  352. #ifndef MHZ19_RX_PIN
  353. #define MHZ19_RX_PIN 13
  354. #endif
  355. #ifndef MHZ19_TX_PIN
  356. #define MHZ19_TX_PIN 15
  357. #endif
  358. //------------------------------------------------------------------------------
  359. // MICS-2710 (and MICS-4514) NO2 sensor
  360. // Enable support by passing MICS2710_SUPPORT=1 build flag
  361. //------------------------------------------------------------------------------
  362. #ifndef MICS2710_SUPPORT
  363. #define MICS2710_SUPPORT 0
  364. #endif
  365. #ifndef MICS2710_NOX_PIN
  366. #define MICS2710_NOX_PIN 0
  367. #endif
  368. #ifndef MICS2710_PRE_PIN
  369. #define MICS2710_PRE_PIN 4
  370. #endif
  371. #define MICS2710_PREHEAT_TIME 10000 // 10s preheat for NOX read
  372. #define MICS2710_RL 820 // RL, load resistor
  373. #define MICS2710_R0 2200 // R0 calibration value for NO2 sensor,
  374. // Typical value as per datasheet
  375. //------------------------------------------------------------------------------
  376. // MICS-5525 (and MICS-4514) CO sensor
  377. // Enable support by passing MICS5525_SUPPORT=1 build flag
  378. //------------------------------------------------------------------------------
  379. #ifndef MICS5525_SUPPORT
  380. #define MICS5525_SUPPORT 0
  381. #endif
  382. #ifndef MICS5525_RED_PIN
  383. #define MICS5525_RED_PIN 0
  384. #endif
  385. #define MICS5525_RL 820 // RL, load resistor
  386. #define MICS5525_R0 750000 // R0 calibration value for NO2 sensor,
  387. // Typical value as per datasheet
  388. //------------------------------------------------------------------------------
  389. // NTC sensor
  390. // Enable support by passing NTC_SUPPORT=1 build flag
  391. //--------------------------------------------------------------------------------
  392. #ifndef NTC_SUPPORT
  393. #define NTC_SUPPORT 0
  394. #endif
  395. #ifndef NTC_SAMPLES
  396. #define NTC_SAMPLES 10 // Number of samples
  397. #endif
  398. #ifndef NTC_DELAY
  399. #define NTC_DELAY 0 // Delay between samples in micros
  400. #endif
  401. #ifndef NTC_R_UP
  402. #define NTC_R_UP 0 // Resistor upstream, set to 0 if none
  403. #endif
  404. #ifndef NTC_R_DOWN
  405. #define NTC_R_DOWN 10000 // Resistor downstream, set to 0 if none
  406. #endif
  407. #ifndef NTC_T0
  408. #define NTC_T0 298.15 // 25 Celsius
  409. #endif
  410. #ifndef NTC_R0
  411. #define NTC_R0 10000 // Resistance at T0
  412. #endif
  413. #ifndef NTC_BETA
  414. #define NTC_BETA 3977 // Beta coeficient
  415. #endif
  416. //------------------------------------------------------------------------------
  417. // Particle Monitor based on Plantower PMS
  418. // Enable support by passing PMSX003_SUPPORT=1 build flag
  419. //------------------------------------------------------------------------------
  420. #ifndef PMSX003_SUPPORT
  421. #define PMSX003_SUPPORT 0
  422. #endif
  423. #ifndef PMS_TYPE
  424. #define PMS_TYPE PMS_TYPE_X003
  425. #endif
  426. // You can enable smart sleep (read 6-times then sleep on 24-reading-cycles) to extend PMS sensor's life.
  427. // Otherwise the default lifetime of PMS sensor is about 8000-hours/1-years.
  428. // The PMS's fan will stop working on sleeping cycle, and will wake up on reading cycle.
  429. #ifndef PMS_SMART_SLEEP
  430. #define PMS_SMART_SLEEP 0
  431. #endif
  432. #ifndef PMS_USE_SOFT
  433. #define PMS_USE_SOFT 0 // If PMS_USE_SOFT == 1, DEBUG_SERIAL_SUPPORT must be 0
  434. #endif
  435. #ifndef PMS_RX_PIN
  436. #define PMS_RX_PIN 13 // Software serial RX GPIO (if PMS_USE_SOFT == 1)
  437. #endif
  438. #ifndef PMS_TX_PIN
  439. #define PMS_TX_PIN 15 // Software serial TX GPIO (if PMS_USE_SOFT == 1)
  440. #endif
  441. #ifndef PMS_HW_PORT
  442. #define PMS_HW_PORT Serial // Hardware serial port (if PMS_USE_SOFT == 0)
  443. #endif
  444. //------------------------------------------------------------------------------
  445. // Pulse Meter Energy monitor
  446. // Enable support by passing PULSEMETER_SUPPORT=1 build flag
  447. //------------------------------------------------------------------------------
  448. #ifndef PULSEMETER_SUPPORT
  449. #define PULSEMETER_SUPPORT 0
  450. #endif
  451. #ifndef PULSEMETER_PIN
  452. #define PULSEMETER_PIN 5
  453. #endif
  454. #ifndef PULSEMETER_ENERGY_RATIO
  455. #define PULSEMETER_ENERGY_RATIO 4000 // In pulses/kWh
  456. #endif
  457. #ifndef PULSEMETER_INTERRUPT_ON
  458. #define PULSEMETER_INTERRUPT_ON FALLING
  459. #endif
  460. #define PULSEMETER_DEBOUNCE 50 // Do not register pulses within less than 50 millis
  461. //------------------------------------------------------------------------------
  462. // PZEM004T based power monitor
  463. // Enable support by passing PZEM004T_SUPPORT=1 build flag
  464. //------------------------------------------------------------------------------
  465. #ifndef PZEM004T_SUPPORT
  466. #define PZEM004T_SUPPORT 0
  467. #endif
  468. #ifndef PZEM004T_USE_SOFT
  469. #define PZEM004T_USE_SOFT 0 // Software serial is not working atm, use hardware serial
  470. #endif
  471. #ifndef PZEM004T_RX_PIN
  472. #define PZEM004T_RX_PIN 13 // Software serial RX GPIO (if PZEM004T_USE_SOFT == 1)
  473. #endif
  474. #ifndef PZEM004T_TX_PIN
  475. #define PZEM004T_TX_PIN 15 // Software serial TX GPIO (if PZEM004T_USE_SOFT == 1)
  476. #endif
  477. #ifndef PZEM004T_HW_PORT
  478. #define PZEM004T_HW_PORT Serial // Hardware serial port (if PZEM004T_USE_SOFT == 0)
  479. #endif
  480. #ifndef PZEM004T_ADDRESSES
  481. #define PZEM004T_ADDRESSES "192.168.1.1" // Device(s) address(es), separated by space, "192.168.1.1 192.168.1.2 192.168.1.3"
  482. #endif
  483. #ifndef PZEM004T_READ_INTERVAL
  484. #define PZEM004T_READ_INTERVAL 1500 // Read interval between same device
  485. #endif
  486. #ifndef PZEM004T_MAX_DEVICES
  487. #define PZEM004T_MAX_DEVICES 3
  488. #endif
  489. //------------------------------------------------------------------------------
  490. // SDS011 particulates sensor
  491. // Enable support by passing SDS011_SUPPORT=1 build flag
  492. //------------------------------------------------------------------------------
  493. #ifndef SDS011_SUPPORT
  494. #define SDS011_SUPPORT 0
  495. #endif
  496. #ifndef SDS011_RX_PIN
  497. #define SDS011_RX_PIN 14
  498. #endif
  499. #ifndef SDS011_TX_PIN
  500. #define SDS011_TX_PIN 12
  501. #endif
  502. //------------------------------------------------------------------------------
  503. // SenseAir CO2 sensor
  504. // Enable support by passing SENSEAIR_SUPPORT=1 build flag
  505. //------------------------------------------------------------------------------
  506. #ifndef SENSEAIR_SUPPORT
  507. #define SENSEAIR_SUPPORT 0
  508. #endif
  509. #ifndef SENSEAIR_RX_PIN
  510. #define SENSEAIR_RX_PIN 0
  511. #endif
  512. #ifndef SENSEAIR_TX_PIN
  513. #define SENSEAIR_TX_PIN 2
  514. #endif
  515. //------------------------------------------------------------------------------
  516. // SHT3X I2C (Wemos) temperature & humidity sensor
  517. // Enable support by passing SHT3X_I2C_SUPPORT=1 build flag
  518. //------------------------------------------------------------------------------
  519. #ifndef SHT3X_I2C_SUPPORT
  520. #define SHT3X_I2C_SUPPORT 0
  521. #endif
  522. #ifndef SHT3X_I2C_ADDRESS
  523. #define SHT3X_I2C_ADDRESS 0x00 // 0x00 means auto
  524. #endif
  525. //------------------------------------------------------------------------------
  526. // SI7021 temperature & humidity sensor
  527. // Enable support by passing SI7021_SUPPORT=1 build flag
  528. //------------------------------------------------------------------------------
  529. #ifndef SI7021_SUPPORT
  530. #define SI7021_SUPPORT 0
  531. #endif
  532. #ifndef SI7021_ADDRESS
  533. #define SI7021_ADDRESS 0x00 // 0x00 means auto
  534. #endif
  535. //------------------------------------------------------------------------------
  536. // Sonar
  537. // Enable support by passing SONAR_SUPPORT=1 build flag
  538. //------------------------------------------------------------------------------
  539. #ifndef SONAR_SUPPORT
  540. #define SONAR_SUPPORT 0
  541. #endif
  542. #ifndef SONAR_TRIGGER
  543. #define SONAR_TRIGGER 12 // GPIO for the trigger pin (output)
  544. #endif
  545. #ifndef SONAR_ECHO
  546. #define SONAR_ECHO 14 // GPIO for the echo pin (input)
  547. #endif
  548. #ifndef SONAR_MAX_DISTANCE
  549. #define SONAR_MAX_DISTANCE MAX_SENSOR_DISTANCE // Max sensor distance in cm
  550. #endif
  551. #ifndef SONAR_ITERATIONS
  552. #define SONAR_ITERATIONS 5 // Number of iterations to ping for
  553. #endif // error correction.
  554. //------------------------------------------------------------------------------
  555. // TMP3X analog temperature sensor
  556. // Enable support by passing TMP3X_SUPPORT=1 build flag
  557. //------------------------------------------------------------------------------
  558. #ifndef TMP3X_SUPPORT
  559. #define TMP3X_SUPPORT 0
  560. #endif
  561. #ifndef TMP3X_TYPE
  562. #define TMP3X_TYPE TMP3X_TMP35
  563. #endif
  564. //------------------------------------------------------------------------------
  565. // V9261F based power sensor
  566. // Enable support by passing SI7021_SUPPORT=1 build flag
  567. //------------------------------------------------------------------------------
  568. #ifndef V9261F_SUPPORT
  569. #define V9261F_SUPPORT 0
  570. #endif
  571. #ifndef V9261F_PIN
  572. #define V9261F_PIN 2 // TX pin from the V9261F
  573. #endif
  574. #ifndef V9261F_PIN_INVERSE
  575. #define V9261F_PIN_INVERSE 1 // Signal is inverted
  576. #endif
  577. #define V9261F_SYNC_INTERVAL 600 // Sync signal length (ms)
  578. #define V9261F_BAUDRATE 4800 // UART baudrate
  579. // Default ratios
  580. #define V9261F_CURRENT_FACTOR 79371434.0
  581. #define V9261F_VOLTAGE_FACTOR 4160651.0
  582. #define V9261F_POWER_FACTOR 153699.0
  583. #define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR
  584. //------------------------------------------------------------------------------
  585. // VEML6075 based power sensor
  586. // Enable support by passing VEML6075_SUPPORT=1 build flag
  587. //------------------------------------------------------------------------------
  588. #ifndef VEML6075_SUPPORT
  589. #define VEML6075_SUPPORT 0
  590. #endif
  591. #ifndef VEML6075_INTEGRATION_TIME
  592. #define VEML6075_INTEGRATION_TIME VEML6075::IT_100MS // The time, in milliseconds, allocated for a single
  593. #endif // measurement. A longer timing budget allows for more
  594. // accurate results at the cost of power.
  595. #ifndef VEML6075_DYNAMIC_MODE
  596. #define VEML6075_DYNAMIC_MODE VEML6075::DYNAMIC_NORMAL // The dynamic mode can either be normal or high. In high
  597. #endif // dynamic mode, the resolution increases by about two
  598. // times.
  599. // =============================================================================
  600. // Sensor helpers configuration - can't move to dependencies.h
  601. // =============================================================================
  602. #ifndef SENSOR_SUPPORT
  603. #define SENSOR_SUPPORT ( \
  604. AM2320_SUPPORT || \
  605. ANALOG_SUPPORT || \
  606. BH1750_SUPPORT || \
  607. BMX280_SUPPORT || \
  608. CSE7766_SUPPORT || \
  609. DALLAS_SUPPORT || \
  610. DHT_SUPPORT || \
  611. DIGITAL_SUPPORT || \
  612. ECH1560_SUPPORT || \
  613. EMON_ADC121_SUPPORT || \
  614. EMON_ADS1X15_SUPPORT || \
  615. EMON_ANALOG_SUPPORT || \
  616. EVENTS_SUPPORT || \
  617. GEIGER_SUPPORT || \
  618. GUVAS12SD_SUPPORT || \
  619. HLW8012_SUPPORT || \
  620. MICS2710_SUPPORT || \
  621. MICS5525_SUPPORT || \
  622. MHZ19_SUPPORT || \
  623. NTC_SUPPORT || \
  624. SDS011_SUPPORT || \
  625. SENSEAIR_SUPPORT || \
  626. PMSX003_SUPPORT || \
  627. PZEM004T_SUPPORT || \
  628. PULSEMETER_SUPPORT || \
  629. SHT3X_I2C_SUPPORT || \
  630. SI7021_SUPPORT || \
  631. SONAR_SUPPORT || \
  632. TMP3X_SUPPORT || \
  633. V9261F_SUPPORT || \
  634. VEML6075_SUPPORT || \
  635. VL53L1X_SUPPORT \
  636. )
  637. #endif
  638. // -----------------------------------------------------------------------------
  639. // ADC
  640. // -----------------------------------------------------------------------------
  641. // Default ADC mode is to monitor internal power supply
  642. #ifndef ADC_MODE_VALUE
  643. #define ADC_MODE_VALUE ADC_VCC
  644. #endif
  645. // -----------------------------------------------------------------------------
  646. // I2C
  647. // -----------------------------------------------------------------------------
  648. #ifndef I2C_SUPPORT
  649. #define I2C_SUPPORT 0 // I2C enabled (1.98Kb)
  650. #endif
  651. #define I2C_USE_BRZO 0 // Use brzo_i2c library or standard Wire
  652. #ifndef I2C_SDA_PIN
  653. #define I2C_SDA_PIN SDA // SDA GPIO (Sonoff => 4)
  654. #endif
  655. #ifndef I2C_SCL_PIN
  656. #define I2C_SCL_PIN SCL // SCL GPIO (Sonoff => 14)
  657. #endif
  658. #define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
  659. #define I2C_SCL_FREQUENCY 1000 // BRZO SCL frequency
  660. #define I2C_CLEAR_BUS 0 // Clear I2C bus on boot
  661. #define I2C_PERFORM_SCAN 1 // Perform a bus scan on boot
  662. //--------------------------------------------------------------------------------
  663. // Class loading
  664. //--------------------------------------------------------------------------------
  665. #if SENSOR_SUPPORT
  666. #if AM2320_SUPPORT
  667. #include "../sensors/AM2320Sensor.h"
  668. #endif
  669. #if ANALOG_SUPPORT
  670. #include "../sensors/AnalogSensor.h"
  671. #endif
  672. #if BH1750_SUPPORT
  673. #include "../sensors/BH1750Sensor.h"
  674. #endif
  675. #if BMX280_SUPPORT
  676. #include "../sensors/BMX280Sensor.h"
  677. #endif
  678. #if CSE7766_SUPPORT
  679. #include "../sensors/CSE7766Sensor.h"
  680. #endif
  681. #if DALLAS_SUPPORT
  682. #include "../sensors/DallasSensor.h"
  683. #endif
  684. #if DHT_SUPPORT
  685. #include "../sensors/DHTSensor.h"
  686. #endif
  687. #if DIGITAL_SUPPORT
  688. #include "../sensors/DigitalSensor.h"
  689. #endif
  690. #if ECH1560_SUPPORT
  691. #include "../sensors/ECH1560Sensor.h"
  692. #endif
  693. #if EMON_ADC121_SUPPORT
  694. #include "../sensors/EmonADC121Sensor.h"
  695. #endif
  696. #if EMON_ADS1X15_SUPPORT
  697. #include "../sensors/EmonADS1X15Sensor.h"
  698. #endif
  699. #if EMON_ANALOG_SUPPORT
  700. #include "../sensors/EmonAnalogSensor.h"
  701. #endif
  702. #if EVENTS_SUPPORT
  703. #include "../sensors/EventSensor.h"
  704. #endif
  705. #if GEIGER_SUPPORT
  706. #include "../sensors/GeigerSensor.h"
  707. #endif
  708. #if GUVAS12SD_SUPPORT
  709. #include "../sensors/GUVAS12SDSensor.h"
  710. #endif
  711. #if HLW8012_SUPPORT
  712. #include "../sensors/HLW8012Sensor.h"
  713. #endif
  714. #if MHZ19_SUPPORT
  715. #include "../sensors/MHZ19Sensor.h"
  716. #endif
  717. #if MICS2710_SUPPORT
  718. #include "../sensors/MICS2710Sensor.h"
  719. #endif
  720. #if MICS5525_SUPPORT
  721. #include "../sensors/MICS5525Sensor.h"
  722. #endif
  723. #if NTC_SUPPORT
  724. #include "../sensors/NTCSensor.h"
  725. #endif
  726. #if SDS011_SUPPORT
  727. #include "../sensors/SDS011Sensor.h"
  728. #endif
  729. #if SENSEAIR_SUPPORT
  730. #include "../sensors/SenseAirSensor.h"
  731. #endif
  732. #if PMSX003_SUPPORT
  733. #include "../sensors/PMSX003Sensor.h"
  734. #endif
  735. #if PULSEMETER_SUPPORT
  736. #include "../sensors/PulseMeterSensor.h"
  737. #endif
  738. #if PZEM004T_SUPPORT
  739. #include "../sensors/PZEM004TSensor.h"
  740. #endif
  741. #if SI7021_SUPPORT
  742. #include "../sensors/SI7021Sensor.h"
  743. #endif
  744. #if SHT3X_I2C_SUPPORT
  745. #include "../sensors/SHT3XI2CSensor.h"
  746. #endif
  747. #if SONAR_SUPPORT
  748. #include "../sensors/SonarSensor.h"
  749. #endif
  750. #if TMP3X_SUPPORT
  751. #include "../sensors/TMP3XSensor.h"
  752. #endif
  753. #if V9261F_SUPPORT
  754. #include "../sensors/V9261FSensor.h"
  755. #endif
  756. #if VEML6075_SUPPORT
  757. #include "../sensors/VEML6075Sensor.h"
  758. #endif
  759. #if VL53L1X_SUPPORT
  760. #include "../sensors/VL53L1XSensor.h"
  761. #endif
  762. #endif // SENSOR_SUPPORT