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.

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