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.

352 lines
12 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
7 years ago
  1. // -----------------------------------------------------------------------------
  2. // SENSORS
  3. // -----------------------------------------------------------------------------
  4. #define SENSOR_DEBUG 0 // Debug sensors (always to 0 in prod)
  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 SENSOR_TEMPERATURE_DECIMALS 1
  22. #define SENSOR_HUMIDITY_DECIMALS 0
  23. #define SENSOR_PRESSURE_DECIMALS 2
  24. #define SENSOR_ANALOG_DECIMALS 0
  25. #define SENSOR_EVENTS_DECIMALS 0
  26. #define SENSOR_CURRENT_DECIMALS 3
  27. #define SENSOR_VOLTAGE_DECIMALS 0
  28. #define SENSOR_POWER_DECIMALS 0
  29. #define SENSOR_POWER_FACTOR_DECIMALS 0
  30. #define SENSOR_ENERGY_DECIMALS 0
  31. #define SENSOR_PM1dot0_DECIMALS 0
  32. #define SENSOR_PM2dot5_DECIMALS 0
  33. #define SENSOR_PM10_DECIMALS 0
  34. #define SENSOR_CO2_DECIMALS 0
  35. #define SENSOR_UNKNOWN_TOPIC "unknown"
  36. #define SENSOR_TEMPERATURE_TOPIC "temperature"
  37. #define SENSOR_HUMIDITY_TOPIC "humidity"
  38. #define SENSOR_PRESSURE_TOPIC "pressure"
  39. #define SENSOR_CURRENT_TOPIC "current"
  40. #define SENSOR_VOLTAGE_TOPIC "voltage"
  41. #define SENSOR_ACTIVE_POWER_TOPIC "power"
  42. #define SENSOR_APPARENT_POWER_TOPIC "apparent"
  43. #define SENSOR_REACTIVE_POWER_TOPIC "reactive"
  44. #define SENSOR_POWER_FACTOR_TOPIC "factor"
  45. #define SENSOR_ENERGY_TOPIC "energy"
  46. #define SENSOR_ENERGY_DELTA_TOPIC "energy_delta"
  47. #define SENSOR_PM1dot0_TOPIC "pm1dot0"
  48. #define SENSOR_PM2dot5_TOPIC "pm2dot5"
  49. #define SENSOR_PM10_TOPIC "pm10"
  50. #define SENSOR_ANALOG_TOPIC "analog"
  51. #define SENSOR_DIGITAL_TOPIC "digital"
  52. #define SENSOR_EVENTS_TOPIC "events"
  53. #define SENSOR_CO2_TOPIC "co2"
  54. #define HUMIDITY_NORMAL 0
  55. #define HUMIDITY_COMFORTABLE 1
  56. #define HUMIDITY_DRY 2
  57. #define HUMIDITY_WET 3
  58. //--------------------------------------------------------------------------------
  59. // Analog sensor
  60. // Enable support by passing ANALOG_SUPPORT=1 build flag
  61. //--------------------------------------------------------------------------------
  62. #ifndef ANALOG_SUPPORT
  63. #define ANALOG_SUPPORT 0
  64. #endif
  65. #ifndef ANALOG_PIN
  66. #define ANALOG_PIN 0
  67. #endif
  68. #ifndef ANALOG_PIN_MODE
  69. #define ANALOG_PIN_MODE INPUT
  70. #endif
  71. #if ANALOG_SUPPORT
  72. #undef ADC_VCC_ENABLED
  73. #define ADC_VCC_ENABLED 0
  74. #endif
  75. //--------------------------------------------------------------------------------
  76. // BME280/BMP280
  77. // Enable support by passing BMX280_SUPPORT=1 build flag
  78. //--------------------------------------------------------------------------------
  79. #ifndef BMX280_SUPPORT
  80. #define BMX280_SUPPORT 0
  81. #endif
  82. #ifndef BMX280_ADDRESS
  83. #define BMX280_ADDRESS 0
  84. #endif
  85. #define BMX280_MODE 1 // 1 for forced mode, 3 for normal mode
  86. #define BMX280_TEMPERATURE 1 // Oversampling for temperature (set to 0 to disable magnitude)
  87. #define BMX280_HUMIDITY 1 // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
  88. #define BMX280_PRESSURE 1 // Oversampling for pressure (set to 0 to disable magnitude)
  89. //--------------------------------------------------------------------------------
  90. // Dallas OneWire temperature sensors
  91. // Enable support by passing DALLAS_SUPPORT=1 build flag
  92. //--------------------------------------------------------------------------------
  93. #ifndef DALLAS_SUPPORT
  94. #define DALLAS_SUPPORT 0
  95. #endif
  96. #ifndef DALLAS_PIN
  97. #define DALLAS_PIN 13
  98. #endif
  99. #ifndef DALLAS_PULLUP
  100. #define DALLAS_PULLUP 1
  101. #endif
  102. #define DALLAS_RESOLUTION 9 // Not used atm
  103. //--------------------------------------------------------------------------------
  104. // DHTXX temperature/humidity sensor
  105. // Enable support by passing DHT_SUPPORT=1 build flag
  106. //--------------------------------------------------------------------------------
  107. #ifndef DHT_SUPPORT
  108. #define DHT_SUPPORT 0
  109. #endif
  110. #ifndef DHT_PIN
  111. #define DHT_PIN 13
  112. #endif
  113. #ifndef DHT_TYPE
  114. #define DHT_TYPE DHT22
  115. #endif
  116. //--------------------------------------------------------------------------------
  117. // Digital sensor
  118. // Enable support by passing DIGITAL_SUPPORT=1 build flag
  119. //--------------------------------------------------------------------------------
  120. #ifndef DIGITAL_SUPPORT
  121. #define DIGITAL_SUPPORT 0
  122. #endif
  123. #ifndef DIGITAL_PIN
  124. #define DIGITAL_PIN 2
  125. #endif
  126. #ifndef DIGITAL_PIN_MODE
  127. #define DIGITAL_PIN_MODE INPUT_PULLUP
  128. #endif
  129. #ifndef DIGITAL_DEFAULT_STATE
  130. #define DIGITAL_DEFAULT_STATE 1
  131. #endif
  132. //--------------------------------------------------------------------------------
  133. // Energy Monitor general settings
  134. //--------------------------------------------------------------------------------
  135. #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
  136. #define EMON_MAX_TIME 250 // Max time in ms to sample
  137. #define EMON_FILTER_SPEED 512 // Mobile average filter speed
  138. #define EMON_MAINS_VOLTAGE 230 // Mains voltage
  139. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  140. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  141. #define EMON_REPORT_CURRENT 0 // Report current
  142. #define EMON_REPORT_POWER 1 // Report power
  143. #define EMON_REPORT_ENERGY 1 // Report energy
  144. //--------------------------------------------------------------------------------
  145. // Energy Monitor based on ADC121
  146. // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
  147. //--------------------------------------------------------------------------------
  148. #ifndef EMON_ADC121_SUPPORT
  149. #define EMON_ADC121_SUPPORT 0 // Do not build support by default
  150. #endif
  151. #define EMON_ADC121_I2C_ADDRESS 0x50 // I2C address of the ADC121
  152. //--------------------------------------------------------------------------------
  153. // Energy Monitor based on ADS1X15
  154. // Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
  155. //--------------------------------------------------------------------------------
  156. #ifndef EMON_ADS1X15_SUPPORT
  157. #define EMON_ADS1X15_SUPPORT 0 // Do not build support by default
  158. #endif
  159. #define EMON_ADS1X15_I2C_ADDRESS 0x48 // I2C address of the ADS1115
  160. #define EMON_ADS1X15_TYPE ADS1X15_CHIP_ADS1115
  161. #define EMON_ADS1X15_GAIN ADS1X15_REG_CONFIG_PGA_4_096V
  162. #define EMON_ADS1X15_MASK 0x0F // A0=1 A1=2 A2=4 A4=8
  163. //--------------------------------------------------------------------------------
  164. // Energy Monitor based on interval analog GPIO
  165. // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
  166. //--------------------------------------------------------------------------------
  167. #ifndef EMON_ANALOG_SUPPORT
  168. #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
  169. #endif
  170. #if EMON_ANALOG_SUPPORT
  171. #undef ADC_VCC_ENABLED
  172. #define ADC_VCC_ENABLED 0
  173. #endif
  174. //--------------------------------------------------------------------------------
  175. // Counter sensor
  176. // Enable support by passing EVENTS_SUPPORT=1 build flag
  177. //--------------------------------------------------------------------------------
  178. #ifndef EVENTS_SUPPORT
  179. #define EVENTS_SUPPORT 0 // Do not build with counter support by default
  180. #endif
  181. #ifndef EVENTS_PIN
  182. #define EVENTS_PIN 2 // GPIO to monitor
  183. #endif
  184. #ifndef EVENTS_PIN_MODE
  185. #define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  186. #endif
  187. #ifndef EVENTS_INTERRUPT_MODE
  188. #define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
  189. #endif
  190. #define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
  191. //--------------------------------------------------------------------------------
  192. // MHZ19 CO2 sensor
  193. // Enable support by passing MHZ19_SUPPORT=1 build flag
  194. //--------------------------------------------------------------------------------
  195. #ifndef MHZ19_SUPPORT
  196. #define MHZ19_SUPPORT 0
  197. #endif
  198. #define MHZ19_RX_PIN 13
  199. #define MHZ19_TX_PIN 15
  200. //--------------------------------------------------------------------------------
  201. // Particle Monitor based on Plantower PMSX003
  202. // Enable support by passing PMSX003_SUPPORT=1 build flag
  203. //--------------------------------------------------------------------------------
  204. #ifndef PMSX003_SUPPORT
  205. #define PMSX003_SUPPORT 0
  206. #endif
  207. #define PMS_RX_PIN 13
  208. #define PMS_TX_PIN 15
  209. //--------------------------------------------------------------------------------
  210. // SI7021 temperature & humidity sensor
  211. // Enable support by passing SI7021_SUPPORT=1 build flag
  212. //--------------------------------------------------------------------------------
  213. #ifndef SI7021_SUPPORT
  214. #define SI7021_SUPPORT 0
  215. #endif
  216. #ifndef SI7021_ADDRESS
  217. #define SI7021_ADDRESS 0x40
  218. #endif
  219. //--------------------------------------------------------------------------------
  220. // Internal power monitor
  221. // Enable support by passing ADC_VCC_ENABLED=1 build flag
  222. // Do not enable this if using the analog GPIO for any other thing
  223. //--------------------------------------------------------------------------------
  224. #ifndef ADC_VCC_ENABLED
  225. #define ADC_VCC_ENABLED 1
  226. #endif
  227. #if ADC_VCC_ENABLED
  228. ADC_MODE(ADC_VCC);
  229. #endif
  230. //--------------------------------------------------------------------------------
  231. // Class loading
  232. //--------------------------------------------------------------------------------
  233. // Embarrasing...
  234. unsigned char i2cFindFirst(size_t size, unsigned char * addresses);
  235. #include "sensors/BaseSensor.h"
  236. #if ANALOG_SUPPORT
  237. #include "sensors/AnalogSensor.h"
  238. #endif
  239. #if BMX280_SUPPORT
  240. #include <SparkFunBME280.h>
  241. #include "sensors/BMX280Sensor.h"
  242. #endif
  243. #if DALLAS_SUPPORT
  244. #include <OneWire.h>
  245. #include "sensors/DallasSensor.h"
  246. #endif
  247. #if DHT_SUPPORT
  248. #include "sensors/DHTSensor.h"
  249. #endif
  250. #if DIGITAL_SUPPORT
  251. #include "sensors/DigitalSensor.h"
  252. #endif
  253. #if EMON_ADC121_SUPPORT
  254. #include "sensors/EmonADC121Sensor.h"
  255. #endif
  256. #if EMON_ADS1X15_SUPPORT
  257. #include "sensors/EmonADS1X15Sensor.h"
  258. #endif
  259. #if EMON_ANALOG_SUPPORT
  260. #include "sensors/EmonAnalogSensor.h"
  261. #endif
  262. #if EVENTS_SUPPORT
  263. #include "sensors/EventSensor.h"
  264. #endif
  265. #if MHZ19_SUPPORT
  266. #include <SoftwareSerial.h>
  267. #include "sensors/MHZ19Sensor.h"
  268. #endif
  269. #if PMSX003_SUPPORT
  270. #include <SoftwareSerial.h>
  271. #include <PMS.h>
  272. #include "sensors/PMSX003Sensor.h"
  273. #endif
  274. #if SI7021_SUPPORT
  275. #include "sensors/SI7021Sensor.h"
  276. #endif