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.

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