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.

819 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
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. //--------------------------------------------------------------------------------
  93. // Magnitudes
  94. //--------------------------------------------------------------------------------
  95. #define MAGNITUDE_NONE 0
  96. #define MAGNITUDE_TEMPERATURE 1
  97. #define MAGNITUDE_HUMIDITY 2
  98. #define MAGNITUDE_PRESSURE 3
  99. #define MAGNITUDE_CURRENT 4
  100. #define MAGNITUDE_VOLTAGE 5
  101. #define MAGNITUDE_POWER_ACTIVE 6
  102. #define MAGNITUDE_POWER_APPARENT 7
  103. #define MAGNITUDE_POWER_REACTIVE 8
  104. #define MAGNITUDE_POWER_FACTOR 9
  105. #define MAGNITUDE_ENERGY 10
  106. #define MAGNITUDE_ENERGY_DELTA 11
  107. #define MAGNITUDE_ANALOG 12
  108. #define MAGNITUDE_DIGITAL 13
  109. #define MAGNITUDE_EVENTS 14
  110. #define MAGNITUDE_PM1dot0 15
  111. #define MAGNITUDE_PM2dot5 16
  112. #define MAGNITUDE_PM10 17
  113. #define MAGNITUDE_CO2 18
  114. #define MAGNITUDE_LUX 19
  115. #define MAGNITUDE_UV 20
  116. #define MAGNITUDE_MAX 21
  117. // =============================================================================
  118. // Specific data for each sensor
  119. // =============================================================================
  120. //------------------------------------------------------------------------------
  121. // Analog sensor
  122. // Enable support by passing ANALOG_SUPPORT=1 build flag
  123. //--------------------------------------------------------------------------------
  124. #ifndef ANALOG_SUPPORT
  125. #define ANALOG_SUPPORT 0
  126. #endif
  127. #if ANALOG_SUPPORT
  128. #undef ADC_VCC_ENABLED
  129. #define ADC_VCC_ENABLED 0
  130. #endif
  131. //------------------------------------------------------------------------------
  132. // BH1750
  133. // Enable support by passing BH1750_SUPPORT=1 build flag
  134. // http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf
  135. //------------------------------------------------------------------------------
  136. #ifndef BH1750_SUPPORT
  137. #define BH1750_SUPPORT 0
  138. #endif
  139. #ifndef BH1750_ADDRESS
  140. #define BH1750_ADDRESS 0x00 // 0x00 means auto
  141. #endif
  142. #define BH1750_MODE BH1750_CONTINUOUS_HIGH_RES_MODE
  143. #if BH1750_SUPPORT
  144. #undef I2C_SUPPORT
  145. #define I2C_SUPPORT 1
  146. #endif
  147. //------------------------------------------------------------------------------
  148. // BME280/BMP280
  149. // Enable support by passing BMX280_SUPPORT=1 build flag
  150. //------------------------------------------------------------------------------
  151. #ifndef BMX280_SUPPORT
  152. #define BMX280_SUPPORT 0
  153. #endif
  154. #ifndef BMX280_ADDRESS
  155. #define BMX280_ADDRESS 0x00 // 0x00 means auto
  156. #endif
  157. #define BMX280_MODE 1 // 0 for sleep mode, 1 or 2 for forced mode, 3 for normal mode
  158. #define BMX280_STANDBY 0 // 0 for 0.5ms, 1 for 62.5ms, 2 for 125ms
  159. // 3 for 250ms, 4 for 500ms, 5 for 1000ms
  160. // 6 for 10ms, 7 for 20ms
  161. #define BMX280_FILTER 0 // 0 for OFF, 1 for 2 values, 2 for 4 values, 3 for 8 values and 4 for 16 values
  162. #define BMX280_TEMPERATURE 1 // Oversampling for temperature (set to 0 to disable magnitude)
  163. #define BMX280_HUMIDITY 1 // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
  164. #define BMX280_PRESSURE 1 // Oversampling for pressure (set to 0 to disable magnitude)
  165. #if BMX280_SUPPORT
  166. #undef I2C_SUPPORT
  167. #define I2C_SUPPORT 1
  168. #endif
  169. //------------------------------------------------------------------------------
  170. // Dallas OneWire temperature sensors
  171. // Enable support by passing DALLAS_SUPPORT=1 build flag
  172. //------------------------------------------------------------------------------
  173. #ifndef DALLAS_SUPPORT
  174. #define DALLAS_SUPPORT 0
  175. #endif
  176. #ifndef DALLAS_PIN
  177. #define DALLAS_PIN 14
  178. #endif
  179. #define DALLAS_RESOLUTION 9 // Not used atm
  180. #define DALLAS_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
  181. //------------------------------------------------------------------------------
  182. // DHTXX temperature/humidity sensor
  183. // Enable support by passing DHT_SUPPORT=1 build flag
  184. //------------------------------------------------------------------------------
  185. #ifndef DHT_SUPPORT
  186. #define DHT_SUPPORT 0
  187. #endif
  188. #ifndef DHT_PIN
  189. #define DHT_PIN 14
  190. #endif
  191. #ifndef DHT_TYPE
  192. #define DHT_TYPE DHT_CHIP_DHT22
  193. #endif
  194. //------------------------------------------------------------------------------
  195. // CSE7766 based power sensor
  196. // Enable support by passing CSE7766_SUPPORT=1 build flag
  197. //------------------------------------------------------------------------------
  198. #ifndef CSE7766_SUPPORT
  199. #define CSE7766_SUPPORT 0
  200. #endif
  201. #ifndef CSE7766_PIN
  202. #define CSE7766_PIN 1 // TX pin from the CSE7766
  203. #endif
  204. #ifndef CSE7766_PIN_INVERSE
  205. #define CSE7766_PIN_INVERSE 0 // Signal is inverted
  206. #endif
  207. #define CSE7766_SYNC_INTERVAL 300 // Safe time between transmissions (ms)
  208. #define CSE7766_BAUDRATE 4800 // UART baudrate
  209. #define CSE7766_V1R 1.0 // 1mR current resistor
  210. #define CSE7766_V2R 1.0 // 1M voltage resistor
  211. //------------------------------------------------------------------------------
  212. // Digital sensor
  213. // Enable support by passing DIGITAL_SUPPORT=1 build flag
  214. //------------------------------------------------------------------------------
  215. #ifndef DIGITAL_SUPPORT
  216. #define DIGITAL_SUPPORT 0
  217. #endif
  218. #ifndef DIGITAL_PIN
  219. #define DIGITAL_PIN 2
  220. #endif
  221. #ifndef DIGITAL_PIN_MODE
  222. #define DIGITAL_PIN_MODE INPUT_PULLUP
  223. #endif
  224. #ifndef DIGITAL_DEFAULT_STATE
  225. #define DIGITAL_DEFAULT_STATE 1
  226. #endif
  227. //------------------------------------------------------------------------------
  228. // ECH1560 based power sensor
  229. // Enable support by passing ECH1560_SUPPORT=1 build flag
  230. //------------------------------------------------------------------------------
  231. #ifndef ECH1560_SUPPORT
  232. #define ECH1560_SUPPORT 0
  233. #endif
  234. #ifndef ECH1560_CLK_PIN
  235. #define ECH1560_CLK_PIN 4 // CLK pin for the ECH1560
  236. #endif
  237. #ifndef ECH1560_MISO_PIN
  238. #define ECH1560_MISO_PIN 5 // MISO pin for the ECH1560
  239. #endif
  240. #ifndef ECH1560_INVERTED
  241. #define ECH1560_INVERTED 0 // Signal is inverted
  242. #endif
  243. //------------------------------------------------------------------------------
  244. // Energy Monitor general settings
  245. //------------------------------------------------------------------------------
  246. #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
  247. #define EMON_MAX_TIME 250 // Max time in ms to sample
  248. #define EMON_FILTER_SPEED 512 // Mobile average filter speed
  249. #define EMON_MAINS_VOLTAGE 230 // Mains voltage
  250. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  251. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  252. #define EMON_REPORT_CURRENT 0 // Report current
  253. #define EMON_REPORT_POWER 1 // Report power
  254. #define EMON_REPORT_ENERGY 1 // Report energy
  255. //------------------------------------------------------------------------------
  256. // Energy Monitor based on ADC121
  257. // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
  258. //------------------------------------------------------------------------------
  259. #ifndef EMON_ADC121_SUPPORT
  260. #define EMON_ADC121_SUPPORT 0 // Do not build support by default
  261. #endif
  262. #define EMON_ADC121_I2C_ADDRESS 0x00 // 0x00 means auto
  263. #if EMON_ADC121_SUPPORT
  264. #undef I2C_SUPPORT
  265. #define I2C_SUPPORT 1
  266. #endif
  267. //------------------------------------------------------------------------------
  268. // Energy Monitor based on ADS1X15
  269. // Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
  270. //------------------------------------------------------------------------------
  271. #ifndef EMON_ADS1X15_SUPPORT
  272. #define EMON_ADS1X15_SUPPORT 0 // Do not build support by default
  273. #endif
  274. #define EMON_ADS1X15_I2C_ADDRESS 0x00 // 0x00 means auto
  275. #define EMON_ADS1X15_TYPE ADS1X15_CHIP_ADS1115
  276. #define EMON_ADS1X15_GAIN ADS1X15_REG_CONFIG_PGA_4_096V
  277. #define EMON_ADS1X15_MASK 0x0F // A0=1 A1=2 A2=4 A3=8
  278. #if EMON_ADS1X15_SUPPORT
  279. #undef I2C_SUPPORT
  280. #define I2C_SUPPORT 1
  281. #endif
  282. //------------------------------------------------------------------------------
  283. // Energy Monitor based on interval analog GPIO
  284. // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
  285. //------------------------------------------------------------------------------
  286. #ifndef EMON_ANALOG_SUPPORT
  287. #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
  288. #endif
  289. #if EMON_ANALOG_SUPPORT
  290. #undef ADC_VCC_ENABLED
  291. #define ADC_VCC_ENABLED 0
  292. #endif
  293. //------------------------------------------------------------------------------
  294. // Counter sensor
  295. // Enable support by passing EVENTS_SUPPORT=1 build flag
  296. //------------------------------------------------------------------------------
  297. #ifndef EVENTS_SUPPORT
  298. #define EVENTS_SUPPORT 0 // Do not build with counter support by default
  299. #endif
  300. #ifndef EVENTS_PIN
  301. #define EVENTS_PIN 2 // GPIO to monitor
  302. #endif
  303. #ifndef EVENTS_PIN_MODE
  304. #define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  305. #endif
  306. #ifndef EVENTS_INTERRUPT_MODE
  307. #define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
  308. #endif
  309. #define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
  310. //------------------------------------------------------------------------------
  311. // HLW8012 Energy monitor IC
  312. // Enable support by passing HLW8012_SUPPORT=1 build flag
  313. //------------------------------------------------------------------------------
  314. #ifndef HLW8012_SUPPORT
  315. #define HLW8012_SUPPORT 0
  316. #endif
  317. #ifndef HLW8012_SEL_PIN
  318. #define HLW8012_SEL_PIN 5
  319. #endif
  320. #ifndef HLW8012_CF1_PIN
  321. #define HLW8012_CF1_PIN 13
  322. #endif
  323. #ifndef HLW8012_CF_PIN
  324. #define HLW8012_CF_PIN 14
  325. #endif
  326. #ifndef HLW8012_SEL_CURRENT
  327. #define HLW8012_SEL_CURRENT HIGH // SEL pin to HIGH to measure current
  328. #endif
  329. #ifndef HLW8012_CURRENT_R
  330. #define HLW8012_CURRENT_R 0.001 // Current resistor
  331. #endif
  332. #ifndef HLW8012_VOLTAGE_R_UP
  333. #define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Upstream voltage resistor
  334. #endif
  335. #ifndef HLW8012_VOLTAGE_R_DOWN
  336. #define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor
  337. #endif
  338. #define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
  339. //------------------------------------------------------------------------------
  340. // MHZ19 CO2 sensor
  341. // Enable support by passing MHZ19_SUPPORT=1 build flag
  342. //------------------------------------------------------------------------------
  343. #ifndef MHZ19_SUPPORT
  344. #define MHZ19_SUPPORT 0
  345. #endif
  346. #define MHZ19_RX_PIN 13
  347. #define MHZ19_TX_PIN 15
  348. //------------------------------------------------------------------------------
  349. // Particle Monitor based on Plantower PMSX003
  350. // Enable support by passing PMSX003_SUPPORT=1 build flag
  351. //------------------------------------------------------------------------------
  352. #ifndef PMSX003_SUPPORT
  353. #define PMSX003_SUPPORT 0
  354. #endif
  355. #define PMS_RX_PIN 13
  356. #define PMS_TX_PIN 15
  357. //------------------------------------------------------------------------------
  358. // PZEM004T based power monitor
  359. // Enable support by passing PZEM004T_SUPPORT=1 build flag
  360. //------------------------------------------------------------------------------
  361. #ifndef PZEM004T_SUPPORT
  362. #define PZEM004T_SUPPORT 0
  363. #endif
  364. #ifndef PZEM004T_USE_SOFT
  365. #define PZEM004T_USE_SOFT 1 // Use software serial
  366. #endif
  367. #ifndef PZEM004T_RX_PIN
  368. #define PZEM004T_RX_PIN 13 // Software serial RX GPIO (if PZEM004T_USE_SOFT == 1)
  369. #endif
  370. #ifndef PZEM004T_TX_PIN
  371. #define PZEM004T_TX_PIN 15 // Software serial TX GPIO (if PZEM004T_USE_SOFT == 1)
  372. #endif
  373. #ifndef PZEM004T_HW_PORT
  374. #define PZEM004T_HW_PORT Serial1 // Hardware serial port (if PZEM004T_USE_SOFT == 0)
  375. #endif
  376. //------------------------------------------------------------------------------
  377. // SHT3X I2C (Wemos) temperature & humidity sensor
  378. // Enable support by passing SHT3X_SUPPORT=1 build flag
  379. //------------------------------------------------------------------------------
  380. #ifndef SHT3X_I2C_SUPPORT
  381. #define SHT3X_I2C_SUPPORT 0
  382. #endif
  383. #ifndef SHT3X_I2C_ADDRESS
  384. #define SHT3X_I2C_ADDRESS 0x00 // 0x00 means auto
  385. #endif
  386. #if SHT3X_I2C_SUPPORT
  387. #undef I2C_SUPPORT
  388. #define I2C_SUPPORT 1
  389. #endif
  390. //------------------------------------------------------------------------------
  391. // SI7021 temperature & humidity sensor
  392. // Enable support by passing SI7021_SUPPORT=1 build flag
  393. //------------------------------------------------------------------------------
  394. #ifndef SI7021_SUPPORT
  395. #define SI7021_SUPPORT 0
  396. #endif
  397. #ifndef SI7021_ADDRESS
  398. #define SI7021_ADDRESS 0x00 // 0x00 means auto
  399. #endif
  400. #if SI7021_SUPPORT
  401. #undef I2C_SUPPORT
  402. #define I2C_SUPPORT 1
  403. #endif
  404. //------------------------------------------------------------------------------
  405. // TMP3X analog temperature sensor
  406. // Enable support by passing TMP3X_SUPPORT=1 build flag
  407. //------------------------------------------------------------------------------
  408. #ifndef TMP3X_SUPPORT
  409. #define TMP3X_SUPPORT 0
  410. #endif
  411. #ifndef TMP3X_TYPE
  412. #define TMP3X_TYPE TMP3X_TMP35
  413. #endif
  414. #if TMP3X_SUPPORT
  415. #undef ADC_VCC_ENABLED
  416. #define ADC_VCC_ENABLED 0
  417. #endif
  418. //------------------------------------------------------------------------------
  419. // V9261F based power sensor
  420. // Enable support by passing SI7021_SUPPORT=1 build flag
  421. //------------------------------------------------------------------------------
  422. #ifndef V9261F_SUPPORT
  423. #define V9261F_SUPPORT 0
  424. #endif
  425. #ifndef V9261F_PIN
  426. #define V9261F_PIN 2 // TX pin from the V9261F
  427. #endif
  428. #ifndef V9261F_PIN_INVERSE
  429. #define V9261F_PIN_INVERSE 1 // Signal is inverted
  430. #endif
  431. #define V9261F_SYNC_INTERVAL 600 // Sync signal length (ms)
  432. #define V9261F_BAUDRATE 4800 // UART baudrate
  433. // Default ratios
  434. #define V9261F_CURRENT_FACTOR 79371434.0
  435. #define V9261F_VOLTAGE_FACTOR 4160651.0
  436. #define V9261F_POWER_FACTOR 153699.0
  437. #define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR
  438. //------------------------------------------------------------------------------
  439. // AM2320 Humidity & Temperature sensor over I2C
  440. // Enable support by passing AM2320_SUPPORT=1 build flag
  441. //------------------------------------------------------------------------------
  442. #ifndef AM2320_SUPPORT
  443. #define AM2320_SUPPORT 0
  444. #endif
  445. #ifndef AM2320_ADDRESS
  446. #define AM2320_ADDRESS 0x00 // 0x00 means auto
  447. #endif
  448. #if AM2320_SUPPORT
  449. #undef I2C_SUPPORT
  450. #define I2C_SUPPORT 1
  451. #endif
  452. //------------------------------------------------------------------------------
  453. // GUVAS12SD UV Sensor (analog)
  454. // Enable support by passing GUVAS12SD_SUPPORT=1 build flag
  455. //------------------------------------------------------------------------------
  456. #ifndef GUVAS12SD_SUPPORT
  457. #define GUVAS12SD_SUPPORT 0
  458. #endif
  459. #ifndef GUVAS12SD_PIN
  460. #define GUVAS12SD_PIN 14
  461. #endif
  462. // =============================================================================
  463. // Sensor helpers configuration
  464. // =============================================================================
  465. #ifndef SENSOR_SUPPORT
  466. #if ANALOG_SUPPORT || BH1750_SUPPORT || BMX280_SUPPORT || DALLAS_SUPPORT \
  467. || DHT_SUPPORT || DIGITAL_SUPPORT || ECH1560_SUPPORT \
  468. || EMON_ADC121_SUPPORT || EMON_ADS1X15_SUPPORT \
  469. || EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \
  470. || MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \
  471. || SI7021_SUPPORT || V9261F_SUPPORT || AM2320_SUPPORT \
  472. || GUVAS12SD_SUPPORT || CSE7766_SUPPORT || TMP3X_SUPPORT
  473. #define SENSOR_SUPPORT 1
  474. #else
  475. #define SENSOR_SUPPORT 0
  476. #endif
  477. #endif
  478. // -----------------------------------------------------------------------------
  479. // I2C
  480. // -----------------------------------------------------------------------------
  481. #ifndef I2C_SUPPORT
  482. #define I2C_SUPPORT 0 // I2C enabled (1.98Kb)
  483. #endif
  484. #define I2C_USE_BRZO 0 // Use brzo_i2c library or standard Wire
  485. #ifndef I2C_SDA_PIN
  486. #define I2C_SDA_PIN SDA // SDA GPIO (Sonoff => 4)
  487. #endif
  488. #ifndef I2C_SCL_PIN
  489. #define I2C_SCL_PIN SCL // SCL GPIO (Sonoff => 14)
  490. #endif
  491. #define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
  492. #define I2C_SCL_FREQUENCY 1000 // BRZO SCL frequency
  493. #define I2C_CLEAR_BUS 0 // Clear I2C bus on boot
  494. #define I2C_PERFORM_SCAN 1 // Perform a bus scan on boot
  495. //--------------------------------------------------------------------------------
  496. // Internal power monitor
  497. // Enable support by passing ADC_VCC_ENABLED=1 build flag
  498. // Do not enable this if using the analog GPIO for any other thing
  499. //--------------------------------------------------------------------------------
  500. #ifndef ADC_VCC_ENABLED
  501. #define ADC_VCC_ENABLED 1
  502. #endif
  503. #if ADC_VCC_ENABLED
  504. ADC_MODE(ADC_VCC);
  505. #endif
  506. //--------------------------------------------------------------------------------
  507. // Class loading
  508. //--------------------------------------------------------------------------------
  509. #if SENSOR_SUPPORT
  510. PROGMEM const unsigned char magnitude_decimals[] = {
  511. 0,
  512. 1, 0, 2,
  513. 3, 0, 0, 0, 0, 0, 0, 0,
  514. 0, 0, 0,
  515. 0, 0, 0,
  516. 0, 0
  517. };
  518. PROGMEM const char magnitude_unknown_topic[] = "unknown";
  519. PROGMEM const char magnitude_temperature_topic[] = "temperature";
  520. PROGMEM const char magnitude_humidity_topic[] = "humidity";
  521. PROGMEM const char magnitude_pressure_topic[] = "pressure";
  522. PROGMEM const char magnitude_current_topic[] = "current";
  523. PROGMEM const char magnitude_voltage_topic[] = "voltage";
  524. PROGMEM const char magnitude_active_power_topic[] = "power";
  525. PROGMEM const char magnitude_apparent_power_topic[] = "apparent";
  526. PROGMEM const char magnitude_reactive_power_topic[] = "reactive";
  527. PROGMEM const char magnitude_power_factor_topic[] = "factor";
  528. PROGMEM const char magnitude_energy_topic[] = "energy";
  529. PROGMEM const char magnitude_energy_delta_topic[] = "energy_delta";
  530. PROGMEM const char magnitude_analog_topic[] = "analog";
  531. PROGMEM const char magnitude_digital_topic[] = "digital";
  532. PROGMEM const char magnitude_events_topic[] = "events";
  533. PROGMEM const char magnitude_pm1dot0_topic[] = "pm1dot0";
  534. PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5";
  535. PROGMEM const char magnitude_pm10_topic[] = "pm10";
  536. PROGMEM const char magnitude_co2_topic[] = "co2";
  537. PROGMEM const char magnitude_lux_topic[] = "lux";
  538. PROGMEM const char magnitude_uv_topic[] = "uv";
  539. PROGMEM const char* const magnitude_topics[] = {
  540. magnitude_unknown_topic, magnitude_temperature_topic, magnitude_humidity_topic,
  541. magnitude_pressure_topic, magnitude_current_topic, magnitude_voltage_topic,
  542. magnitude_active_power_topic, magnitude_apparent_power_topic, magnitude_reactive_power_topic,
  543. magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
  544. magnitude_analog_topic, magnitude_digital_topic, magnitude_events_topic,
  545. magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic,
  546. magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic
  547. };
  548. PROGMEM const char magnitude_empty[] = "";
  549. PROGMEM const char magnitude_celsius[] = "C";
  550. PROGMEM const char magnitude_fahrenheit[] = "F";
  551. PROGMEM const char magnitude_percentage[] = "%";
  552. PROGMEM const char magnitude_hectopascals[] = "hPa";
  553. PROGMEM const char magnitude_amperes[] = "A";
  554. PROGMEM const char magnitude_volts[] = "V";
  555. PROGMEM const char magnitude_watts[] = "W";
  556. PROGMEM const char magnitude_kw[] = "kW";
  557. PROGMEM const char magnitude_joules[] = "J";
  558. PROGMEM const char magnitude_kwh[] = "kWh";
  559. PROGMEM const char magnitude_ugm3[] = "µg/m3";
  560. PROGMEM const char magnitude_ppm[] = "ppm";
  561. PROGMEM const char magnitude_lux[] = "lux";
  562. PROGMEM const char magnitude_uv[] = "uv";
  563. PROGMEM const char* const magnitude_units[] = {
  564. magnitude_empty, magnitude_celsius, magnitude_percentage,
  565. magnitude_hectopascals, magnitude_amperes, magnitude_volts,
  566. magnitude_watts, magnitude_watts, magnitude_watts,
  567. magnitude_percentage, magnitude_joules, magnitude_joules,
  568. magnitude_empty, magnitude_empty, magnitude_empty,
  569. magnitude_ugm3, magnitude_ugm3, magnitude_ugm3,
  570. magnitude_ppm, magnitude_lux, magnitude_uv
  571. };
  572. #include "../sensors/BaseSensor.h"
  573. #if AM2320_SUPPORT
  574. #include "../sensors/AM2320Sensor.h"
  575. #endif
  576. #if ANALOG_SUPPORT
  577. #include "../sensors/AnalogSensor.h"
  578. #endif
  579. #if BH1750_SUPPORT
  580. #include "../sensors/BH1750Sensor.h"
  581. #endif
  582. #if BMX280_SUPPORT
  583. #include "../sensors/BMX280Sensor.h"
  584. #endif
  585. #if CSE7766_SUPPORT
  586. #include <SoftwareSerial.h>
  587. #include "../sensors/CSE7766Sensor.h"
  588. #endif
  589. #if DALLAS_SUPPORT
  590. #include <OneWire.h>
  591. #include "../sensors/DallasSensor.h"
  592. #endif
  593. #if DHT_SUPPORT
  594. #include "../sensors/DHTSensor.h"
  595. #endif
  596. #if DIGITAL_SUPPORT
  597. #include "../sensors/DigitalSensor.h"
  598. #endif
  599. #if ECH1560_SUPPORT
  600. #include "../sensors/ECH1560Sensor.h"
  601. #endif
  602. #if EMON_ADC121_SUPPORT
  603. #include "../sensors/EmonADC121Sensor.h"
  604. #endif
  605. #if EMON_ADS1X15_SUPPORT
  606. #include "../sensors/EmonADS1X15Sensor.h"
  607. #endif
  608. #if EMON_ANALOG_SUPPORT
  609. #include "../sensors/EmonAnalogSensor.h"
  610. #endif
  611. #if EVENTS_SUPPORT
  612. #include "../sensors/EventSensor.h"
  613. #endif
  614. #if GUVAS12SD_SUPPORT
  615. #include "../sensors/GUVAS12SDSensor.h"
  616. #endif
  617. #if HLW8012_SUPPORT
  618. #include <HLW8012.h>
  619. #include "../sensors/HLW8012Sensor.h"
  620. #endif
  621. #if MHZ19_SUPPORT
  622. #include <SoftwareSerial.h>
  623. #include "../sensors/MHZ19Sensor.h"
  624. #endif
  625. #if PMSX003_SUPPORT
  626. #include <SoftwareSerial.h>
  627. #include <PMS.h>
  628. #include "../sensors/PMSX003Sensor.h"
  629. #endif
  630. #if PZEM004T_SUPPORT
  631. #include <SoftwareSerial.h>
  632. #include "../sensors/PZEM004TSensor.h"
  633. #endif
  634. #if SI7021_SUPPORT
  635. #include "../sensors/SI7021Sensor.h"
  636. #endif
  637. #if SHT3X_I2C_SUPPORT
  638. #include "../sensors/SHT3XI2CSensor.h"
  639. #endif
  640. #if TMP3X_SUPPORT
  641. #include "../sensors/TMP3XSensor.h"
  642. #endif
  643. #if V9261F_SUPPORT
  644. #include <SoftwareSerial.h>
  645. #include "../sensors/V9261FSensor.h"
  646. #endif
  647. #endif // SENSOR_SUPPORT