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.

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