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.

412 lines
14 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
  1. // =============================================================================
  2. // SENSORS - General data
  3. // =============================================================================
  4. #define SENSOR_DEBUG 0 // Debug sensors
  5. #define SENSOR_READ_INTERVAL 6000 // Read data from sensors every 6 seconds
  6. #define SENSOR_REPORT_EVERY 10 // Report every this many readings
  7. #define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0)
  8. // even if just one sensor (0 for backwards compatibility)
  9. #ifndef SENSOR_TEMPERATURE_UNITS
  10. #define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
  11. #endif
  12. #ifndef SENSOR_TEMPERATURE_CORRECTION
  13. #define SENSOR_TEMPERATURE_CORRECTION 0.0 // Offset correction
  14. #endif
  15. #ifndef TEMPERATURE_MIN_CHANGE
  16. #define TEMPERATURE_MIN_CHANGE 0.0 // Minimum temperature change to report
  17. #endif
  18. #ifndef HUMIDITY_MIN_CHANGE
  19. #define HUMIDITY_MIN_CHANGE 0 // Minimum humidity change to report
  20. #endif
  21. #define HUMIDITY_NORMAL 0
  22. #define HUMIDITY_COMFORTABLE 1
  23. #define HUMIDITY_DRY 2
  24. #define HUMIDITY_WET 3
  25. //--------------------------------------------------------------------------------
  26. // Magnitudes
  27. //--------------------------------------------------------------------------------
  28. #define MAGNITUDE_TEMPERATURE_DECIMALS 1
  29. #define MAGNITUDE_HUMIDITY_DECIMALS 0
  30. #define MAGNITUDE_PRESSURE_DECIMALS 2
  31. #define MAGNITUDE_ANALOG_DECIMALS 0
  32. #define MAGNITUDE_EVENTS_DECIMALS 0
  33. #define MAGNITUDE_CURRENT_DECIMALS 3
  34. #define MAGNITUDE_VOLTAGE_DECIMALS 0
  35. #define MAGNITUDE_POWER_DECIMALS 0
  36. #define MAGNITUDE_POWER_FACTOR_DECIMALS 0
  37. #define MAGNITUDE_ENERGY_DECIMALS 0
  38. #define MAGNITUDE_PM1dot0_DECIMALS 0
  39. #define MAGNITUDE_PM2dot5_DECIMALS 0
  40. #define MAGNITUDE_PM10_DECIMALS 0
  41. #define MAGNITUDE_CO2_DECIMALS 0
  42. #define MAGNITUDE_UNKNOWN_TOPIC "unknown"
  43. #define MAGNITUDE_TEMPERATURE_TOPIC "temperature"
  44. #define MAGNITUDE_HUMIDITY_TOPIC "humidity"
  45. #define MAGNITUDE_PRESSURE_TOPIC "pressure"
  46. #define MAGNITUDE_CURRENT_TOPIC "current"
  47. #define MAGNITUDE_VOLTAGE_TOPIC "voltage"
  48. #define MAGNITUDE_ACTIVE_POWER_TOPIC "power"
  49. #define MAGNITUDE_APPARENT_POWER_TOPIC "apparent"
  50. #define MAGNITUDE_REACTIVE_POWER_TOPIC "reactive"
  51. #define MAGNITUDE_POWER_FACTOR_TOPIC "factor"
  52. #define MAGNITUDE_ENERGY_TOPIC "energy"
  53. #define MAGNITUDE_ENERGY_DELTA_TOPIC "energy_delta"
  54. #define MAGNITUDE_PM1dot0_TOPIC "pm1dot0"
  55. #define MAGNITUDE_PM2dot5_TOPIC "pm2dot5"
  56. #define MAGNITUDE_PM10_TOPIC "pm10"
  57. #define MAGNITUDE_ANALOG_TOPIC "analog"
  58. #define MAGNITUDE_DIGITAL_TOPIC "digital"
  59. #define MAGNITUDE_EVENTS_TOPIC "events"
  60. #define MAGNITUDE_CO2_TOPIC "co2"
  61. //--------------------------------------------------------------------------------
  62. // Sensor ID
  63. // These should remain over time, do not modify them, only add new ones at the end
  64. //--------------------------------------------------------------------------------
  65. #define SENSOR_DHT_ID 0x01
  66. #define SENSOR_DALLAS_ID 0x02
  67. #define SENSOR_EMON_ANALOG_ID 0x03
  68. #define SENSOR_EMON_ADC121_ID 0x04
  69. #define SENSOR_EMON_ADS1X15_ID 0x05
  70. #define SENSOR_HLW8012_ID 0x06
  71. #define SENSOR_V9261F_ID 0x07
  72. #define SENSOR_ECH1560_ID 0x08
  73. #define SENSOR_ANALOG_ID 0x09
  74. #define SENSOR_DIGITAL_ID 0x10
  75. #define SENSOR_EVENTS_ID 0x11
  76. #define SENSOR_PMSX003_ID 0x12
  77. #define SENSOR_BMX280_ID 0x13
  78. #define SENSOR_MHZ19_ID 0x14
  79. #define SENSOR_SI7021_ID 0x15
  80. // =============================================================================
  81. // Specific data for each sensor
  82. // =============================================================================
  83. //------------------------------------------------------------------------------
  84. // Analog sensor
  85. // Enable support by passing ANALOG_SUPPORT=1 build flag
  86. //--------------------------------------------------------------------------------
  87. #ifndef ANALOG_SUPPORT
  88. #define ANALOG_SUPPORT 0
  89. #endif
  90. #if ANALOG_SUPPORT
  91. #undef ADC_VCC_ENABLED
  92. #define ADC_VCC_ENABLED 0
  93. #endif
  94. //------------------------------------------------------------------------------
  95. // BME280/BMP280
  96. // Enable support by passing BMX280_SUPPORT=1 build flag
  97. //------------------------------------------------------------------------------
  98. #ifndef BMX280_SUPPORT
  99. #define BMX280_SUPPORT 0
  100. #endif
  101. #ifndef BMX280_ADDRESS
  102. #define BMX280_ADDRESS 0x00 // 0x00 means auto
  103. #endif
  104. #define BMX280_MODE 1 // 1 for forced mode, 3 for normal mode
  105. #define BMX280_TEMPERATURE 1 // Oversampling for temperature (set to 0 to disable magnitude)
  106. #define BMX280_HUMIDITY 1 // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
  107. #define BMX280_PRESSURE 1 // Oversampling for pressure (set to 0 to disable magnitude)
  108. #if BMX280_SUPPORT
  109. #undef I2C_SUPPORT
  110. #define I2C_SUPPORT 1
  111. #endif
  112. //------------------------------------------------------------------------------
  113. // Dallas OneWire temperature sensors
  114. // Enable support by passing DALLAS_SUPPORT=1 build flag
  115. //------------------------------------------------------------------------------
  116. #ifndef DALLAS_SUPPORT
  117. #define DALLAS_SUPPORT 0
  118. #endif
  119. #ifndef DALLAS_PIN
  120. #define DALLAS_PIN 13
  121. #endif
  122. #define DALLAS_RESOLUTION 9 // Not used atm
  123. //------------------------------------------------------------------------------
  124. // DHTXX temperature/humidity sensor
  125. // Enable support by passing DHT_SUPPORT=1 build flag
  126. //------------------------------------------------------------------------------
  127. #ifndef DHT_SUPPORT
  128. #define DHT_SUPPORT 0
  129. #endif
  130. #ifndef DHT_PIN
  131. #define DHT_PIN 13
  132. #endif
  133. #ifndef DHT_TYPE
  134. #define DHT_TYPE DHT_CHIP_DHT22
  135. #endif
  136. //------------------------------------------------------------------------------
  137. // Digital sensor
  138. // Enable support by passing DIGITAL_SUPPORT=1 build flag
  139. //------------------------------------------------------------------------------
  140. #ifndef DIGITAL_SUPPORT
  141. #define DIGITAL_SUPPORT 0
  142. #endif
  143. #ifndef DIGITAL_PIN
  144. #define DIGITAL_PIN 2
  145. #endif
  146. #ifndef DIGITAL_PIN_MODE
  147. #define DIGITAL_PIN_MODE INPUT_PULLUP
  148. #endif
  149. #ifndef DIGITAL_DEFAULT_STATE
  150. #define DIGITAL_DEFAULT_STATE 1
  151. #endif
  152. //------------------------------------------------------------------------------
  153. // Energy Monitor general settings
  154. //------------------------------------------------------------------------------
  155. #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
  156. #define EMON_MAX_TIME 250 // Max time in ms to sample
  157. #define EMON_FILTER_SPEED 512 // Mobile average filter speed
  158. #define EMON_MAINS_VOLTAGE 230 // Mains voltage
  159. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  160. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  161. #define EMON_REPORT_CURRENT 0 // Report current
  162. #define EMON_REPORT_POWER 1 // Report power
  163. #define EMON_REPORT_ENERGY 1 // Report energy
  164. //------------------------------------------------------------------------------
  165. // Energy Monitor based on ADC121
  166. // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
  167. //------------------------------------------------------------------------------
  168. #ifndef EMON_ADC121_SUPPORT
  169. #define EMON_ADC121_SUPPORT 0 // Do not build support by default
  170. #endif
  171. #define EMON_ADC121_I2C_ADDRESS 0x00 // 0x00 means auto
  172. #if EMON_ADC121_SUPPORT
  173. #undef I2C_SUPPORT
  174. #define I2C_SUPPORT 1
  175. #endif
  176. //------------------------------------------------------------------------------
  177. // Energy Monitor based on ADS1X15
  178. // Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
  179. //------------------------------------------------------------------------------
  180. #ifndef EMON_ADS1X15_SUPPORT
  181. #define EMON_ADS1X15_SUPPORT 0 // Do not build support by default
  182. #endif
  183. #define EMON_ADS1X15_I2C_ADDRESS 0x00 // 0x00 means auto
  184. #define EMON_ADS1X15_TYPE ADS1X15_CHIP_ADS1115
  185. #define EMON_ADS1X15_GAIN ADS1X15_REG_CONFIG_PGA_4_096V
  186. #define EMON_ADS1X15_MASK 0x0F // A0=1 A1=2 A2=4 A4=8
  187. #if EMON_ADS1X15_SUPPORT
  188. #undef I2C_SUPPORT
  189. #define I2C_SUPPORT 1
  190. #endif
  191. //------------------------------------------------------------------------------
  192. // Energy Monitor based on interval analog GPIO
  193. // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
  194. //------------------------------------------------------------------------------
  195. #ifndef EMON_ANALOG_SUPPORT
  196. #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
  197. #endif
  198. #if EMON_ANALOG_SUPPORT
  199. #undef ADC_VCC_ENABLED
  200. #define ADC_VCC_ENABLED 0
  201. #endif
  202. //------------------------------------------------------------------------------
  203. // Counter sensor
  204. // Enable support by passing EVENTS_SUPPORT=1 build flag
  205. //------------------------------------------------------------------------------
  206. #ifndef EVENTS_SUPPORT
  207. #define EVENTS_SUPPORT 0 // Do not build with counter support by default
  208. #endif
  209. #ifndef EVENTS_PIN
  210. #define EVENTS_PIN 2 // GPIO to monitor
  211. #endif
  212. #ifndef EVENTS_PIN_MODE
  213. #define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  214. #endif
  215. #ifndef EVENTS_INTERRUPT_MODE
  216. #define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
  217. #endif
  218. #define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
  219. //------------------------------------------------------------------------------
  220. // MHZ19 CO2 sensor
  221. // Enable support by passing MHZ19_SUPPORT=1 build flag
  222. //------------------------------------------------------------------------------
  223. #ifndef MHZ19_SUPPORT
  224. #define MHZ19_SUPPORT 0
  225. #endif
  226. #define MHZ19_RX_PIN 13
  227. #define MHZ19_TX_PIN 15
  228. //------------------------------------------------------------------------------
  229. // Particle Monitor based on Plantower PMSX003
  230. // Enable support by passing PMSX003_SUPPORT=1 build flag
  231. //------------------------------------------------------------------------------
  232. #ifndef PMSX003_SUPPORT
  233. #define PMSX003_SUPPORT 0
  234. #endif
  235. #define PMS_RX_PIN 13
  236. #define PMS_TX_PIN 15
  237. //------------------------------------------------------------------------------
  238. // SI7021 temperature & humidity sensor
  239. // Enable support by passing SI7021_SUPPORT=1 build flag
  240. //------------------------------------------------------------------------------
  241. #ifndef SI7021_SUPPORT
  242. #define SI7021_SUPPORT 0
  243. #endif
  244. #ifndef SI7021_ADDRESS
  245. #define SI7021_ADDRESS 0x00 // 0x00 means auto
  246. #endif
  247. #if SI7021_SUPPORT
  248. #undef I2C_SUPPORT
  249. #define I2C_SUPPORT 1
  250. #endif
  251. // =============================================================================
  252. // Sensor helpers configuration
  253. // =============================================================================
  254. // -----------------------------------------------------------------------------
  255. // I2C
  256. // -----------------------------------------------------------------------------
  257. #ifndef I2C_SUPPORT
  258. #define I2C_SUPPORT 0 // I2C enabled (1.98Kb)
  259. #endif
  260. #define I2C_USE_BRZO 0 // Use brzo_i2c library or standard Wire
  261. #ifndef I2C_SDA_PIN
  262. #define I2C_SDA_PIN SDA // SDA GPIO (Sonoff => 4)
  263. #endif
  264. #ifndef I2C_SCL_PIN
  265. #define I2C_SCL_PIN SCL // SCL GPIO (Sonoff => 14)
  266. #endif
  267. #define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
  268. #define I2C_SCL_FREQUENCY 1000 // BRZO SCL frequency
  269. #define I2C_CLEAR_BUS 0 // Clear I2C bus at boot
  270. //--------------------------------------------------------------------------------
  271. // Internal power monitor
  272. // Enable support by passing ADC_VCC_ENABLED=1 build flag
  273. // Do not enable this if using the analog GPIO for any other thing
  274. //--------------------------------------------------------------------------------
  275. #ifndef ADC_VCC_ENABLED
  276. #define ADC_VCC_ENABLED 1
  277. #endif
  278. #if ADC_VCC_ENABLED
  279. ADC_MODE(ADC_VCC);
  280. #endif
  281. //--------------------------------------------------------------------------------
  282. // Class loading
  283. //--------------------------------------------------------------------------------
  284. #include "sensors/BaseSensor.h"
  285. #if ANALOG_SUPPORT
  286. #include "sensors/AnalogSensor.h"
  287. #endif
  288. #if BMX280_SUPPORT
  289. #include <SparkFunBME280.h>
  290. #include "sensors/BMX280Sensor.h"
  291. #endif
  292. #if DALLAS_SUPPORT
  293. #include <OneWire.h>
  294. #include "sensors/DallasSensor.h"
  295. #endif
  296. #if DHT_SUPPORT
  297. #include "sensors/DHTSensor.h"
  298. #endif
  299. #if DIGITAL_SUPPORT
  300. #include "sensors/DigitalSensor.h"
  301. #endif
  302. #if EMON_ADC121_SUPPORT
  303. #include "sensors/EmonADC121Sensor.h"
  304. #endif
  305. #if EMON_ADS1X15_SUPPORT
  306. #include "sensors/EmonADS1X15Sensor.h"
  307. #endif
  308. #if EMON_ANALOG_SUPPORT
  309. #include "sensors/EmonAnalogSensor.h"
  310. #endif
  311. #if EVENTS_SUPPORT
  312. #include "sensors/EventSensor.h"
  313. #endif
  314. #if MHZ19_SUPPORT
  315. #include <SoftwareSerial.h>
  316. #include "sensors/MHZ19Sensor.h"
  317. #endif
  318. #if PMSX003_SUPPORT
  319. #include <SoftwareSerial.h>
  320. #include <PMS.h>
  321. #include "sensors/PMSX003Sensor.h"
  322. #endif
  323. #if SI7021_SUPPORT
  324. #include "sensors/SI7021Sensor.h"
  325. #endif