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.

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