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.

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