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.

379 lines
13 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
  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 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 1
  64. #endif
  65. #if ANALOG_SUPPORT
  66. #undef ADC_VCC_ENABLED
  67. #define ADC_VCC_ENABLED 0
  68. #endif
  69. //--------------------------------------------------------------------------------
  70. // BME280/BMP280
  71. // Enable support by passing BMX280_SUPPORT=1 build flag
  72. //--------------------------------------------------------------------------------
  73. #ifndef BMX280_SUPPORT
  74. #define BMX280_SUPPORT 1
  75. #endif
  76. #ifndef BMX280_ADDRESS
  77. #define BMX280_ADDRESS 0x00 // 0x00 means auto
  78. #endif
  79. #define BMX280_MODE 1 // 1 for forced mode, 3 for normal mode
  80. #define BMX280_TEMPERATURE 1 // Oversampling for temperature (set to 0 to disable magnitude)
  81. #define BMX280_HUMIDITY 1 // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
  82. #define BMX280_PRESSURE 1 // Oversampling for pressure (set to 0 to disable magnitude)
  83. #if BMX280_SUPPORT
  84. #undef I2C_SUPPORT
  85. #define I2C_SUPPORT 1
  86. #endif
  87. //--------------------------------------------------------------------------------
  88. // Dallas OneWire temperature sensors
  89. // Enable support by passing DALLAS_SUPPORT=1 build flag
  90. //--------------------------------------------------------------------------------
  91. #ifndef DALLAS_SUPPORT
  92. #define DALLAS_SUPPORT 0
  93. #endif
  94. #ifndef DALLAS_PIN
  95. #define DALLAS_PIN 13
  96. #endif
  97. #define DALLAS_RESOLUTION 9 // Not used atm
  98. //--------------------------------------------------------------------------------
  99. // DHTXX temperature/humidity sensor
  100. // Enable support by passing DHT_SUPPORT=1 build flag
  101. //--------------------------------------------------------------------------------
  102. #ifndef DHT_SUPPORT
  103. #define DHT_SUPPORT 0
  104. #endif
  105. #ifndef DHT_PIN
  106. #define DHT_PIN 13
  107. #endif
  108. #ifndef DHT_TYPE
  109. #define DHT_TYPE DHT22
  110. #endif
  111. //--------------------------------------------------------------------------------
  112. // Digital sensor
  113. // Enable support by passing DIGITAL_SUPPORT=1 build flag
  114. //--------------------------------------------------------------------------------
  115. #ifndef DIGITAL_SUPPORT
  116. #define DIGITAL_SUPPORT 0
  117. #endif
  118. #ifndef DIGITAL_PIN
  119. #define DIGITAL_PIN 2
  120. #endif
  121. #ifndef DIGITAL_PIN_MODE
  122. #define DIGITAL_PIN_MODE INPUT_PULLUP
  123. #endif
  124. #ifndef DIGITAL_DEFAULT_STATE
  125. #define DIGITAL_DEFAULT_STATE 1
  126. #endif
  127. //--------------------------------------------------------------------------------
  128. // Energy Monitor general settings
  129. //--------------------------------------------------------------------------------
  130. #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
  131. #define EMON_MAX_TIME 250 // Max time in ms to sample
  132. #define EMON_FILTER_SPEED 512 // Mobile average filter speed
  133. #define EMON_MAINS_VOLTAGE 230 // Mains voltage
  134. #define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
  135. #define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
  136. #define EMON_REPORT_CURRENT 0 // Report current
  137. #define EMON_REPORT_POWER 1 // Report power
  138. #define EMON_REPORT_ENERGY 1 // Report energy
  139. //--------------------------------------------------------------------------------
  140. // Energy Monitor based on ADC121
  141. // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
  142. //--------------------------------------------------------------------------------
  143. #ifndef EMON_ADC121_SUPPORT
  144. #define EMON_ADC121_SUPPORT 0 // Do not build support by default
  145. #endif
  146. #define EMON_ADC121_I2C_ADDRESS 0x00 // 0x00 means auto
  147. #if EMON_ADC121_SUPPORT
  148. #undef I2C_SUPPORT
  149. #define I2C_SUPPORT 1
  150. #endif
  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 0x00 // 0x00 means auto
  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. #if EMON_ADS1X15_SUPPORT
  163. #undef I2C_SUPPORT
  164. #define I2C_SUPPORT 1
  165. #endif
  166. //--------------------------------------------------------------------------------
  167. // Energy Monitor based on interval analog GPIO
  168. // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
  169. //--------------------------------------------------------------------------------
  170. #ifndef EMON_ANALOG_SUPPORT
  171. #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
  172. #endif
  173. #if EMON_ANALOG_SUPPORT
  174. #undef ADC_VCC_ENABLED
  175. #define ADC_VCC_ENABLED 0
  176. #endif
  177. //--------------------------------------------------------------------------------
  178. // Counter sensor
  179. // Enable support by passing EVENTS_SUPPORT=1 build flag
  180. //--------------------------------------------------------------------------------
  181. #ifndef EVENTS_SUPPORT
  182. #define EVENTS_SUPPORT 0 // Do not build with counter support by default
  183. #endif
  184. #ifndef EVENTS_PIN
  185. #define EVENTS_PIN 2 // GPIO to monitor
  186. #endif
  187. #ifndef EVENTS_PIN_MODE
  188. #define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
  189. #endif
  190. #ifndef EVENTS_INTERRUPT_MODE
  191. #define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, BOTH
  192. #endif
  193. #define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
  194. //--------------------------------------------------------------------------------
  195. // MHZ19 CO2 sensor
  196. // Enable support by passing MHZ19_SUPPORT=1 build flag
  197. //--------------------------------------------------------------------------------
  198. #ifndef MHZ19_SUPPORT
  199. #define MHZ19_SUPPORT 0
  200. #endif
  201. #define MHZ19_RX_PIN 13
  202. #define MHZ19_TX_PIN 15
  203. //--------------------------------------------------------------------------------
  204. // Particle Monitor based on Plantower PMSX003
  205. // Enable support by passing PMSX003_SUPPORT=1 build flag
  206. //--------------------------------------------------------------------------------
  207. #ifndef PMSX003_SUPPORT
  208. #define PMSX003_SUPPORT 0
  209. #endif
  210. #define PMS_RX_PIN 13
  211. #define PMS_TX_PIN 15
  212. //--------------------------------------------------------------------------------
  213. // SI7021 temperature & humidity sensor
  214. // Enable support by passing SI7021_SUPPORT=1 build flag
  215. //--------------------------------------------------------------------------------
  216. #ifndef SI7021_SUPPORT
  217. #define SI7021_SUPPORT 0
  218. #endif
  219. #ifndef SI7021_ADDRESS
  220. #define SI7021_ADDRESS 0x00 // 0x00 means auto
  221. #endif
  222. #if SI7021_SUPPORT
  223. #undef I2C_SUPPORT
  224. #define I2C_SUPPORT 1
  225. #endif
  226. // -----------------------------------------------------------------------------
  227. // I2C
  228. // -----------------------------------------------------------------------------
  229. #ifndef I2C_SUPPORT
  230. #define I2C_SUPPORT 0 // I2C enabled (1.98Kb)
  231. #endif
  232. #define I2C_USE_BRZO 0 // Use brzo_i2c library or standard Wire
  233. #ifndef I2C_SDA_PIN
  234. #define I2C_SDA_PIN SDA // SDA GPIO (Sonoff => 4)
  235. #endif
  236. #ifndef I2C_SCL_PIN
  237. #define I2C_SCL_PIN SCL // SCL GPIO (Sonoff => 14)
  238. #endif
  239. #define I2C_CLOCK_STRETCH_TIME 200 // BRZO clock stretch time
  240. #define I2C_SCL_FREQUENCY 1000 // BRZO SCL frequency
  241. #define I2C_CLEAR_BUS 0 // Clear I2C bus at boot
  242. //--------------------------------------------------------------------------------
  243. // Internal power monitor
  244. // Enable support by passing ADC_VCC_ENABLED=1 build flag
  245. // Do not enable this if using the analog GPIO for any other thing
  246. //--------------------------------------------------------------------------------
  247. #ifndef ADC_VCC_ENABLED
  248. #define ADC_VCC_ENABLED 1
  249. #endif
  250. #if ADC_VCC_ENABLED
  251. ADC_MODE(ADC_VCC);
  252. #endif
  253. //--------------------------------------------------------------------------------
  254. // Class loading
  255. //--------------------------------------------------------------------------------
  256. #include "sensors/BaseSensor.h"
  257. #if ANALOG_SUPPORT
  258. #include "sensors/AnalogSensor.h"
  259. #endif
  260. #if BMX280_SUPPORT
  261. #include <SparkFunBME280.h>
  262. #include "sensors/BMX280Sensor.h"
  263. #endif
  264. #if DALLAS_SUPPORT
  265. #include <OneWire.h>
  266. #include "sensors/DallasSensor.h"
  267. #endif
  268. #if DHT_SUPPORT
  269. #include "sensors/DHTSensor.h"
  270. #endif
  271. #if DIGITAL_SUPPORT
  272. #include "sensors/DigitalSensor.h"
  273. #endif
  274. #if EMON_ADC121_SUPPORT
  275. #include "sensors/EmonADC121Sensor.h"
  276. #endif
  277. #if EMON_ADS1X15_SUPPORT
  278. #include "sensors/EmonADS1X15Sensor.h"
  279. #endif
  280. #if EMON_ANALOG_SUPPORT
  281. #include "sensors/EmonAnalogSensor.h"
  282. #endif
  283. #if EVENTS_SUPPORT
  284. #include "sensors/EventSensor.h"
  285. #endif
  286. #if MHZ19_SUPPORT
  287. #include <SoftwareSerial.h>
  288. #include "sensors/MHZ19Sensor.h"
  289. #endif
  290. #if PMSX003_SUPPORT
  291. #include <SoftwareSerial.h>
  292. #include <PMS.h>
  293. #include "sensors/PMSX003Sensor.h"
  294. #endif
  295. #if SI7021_SUPPORT
  296. #include "sensors/SI7021Sensor.h"
  297. #endif