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.

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