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.

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