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.

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