Skip to content

Commit 37d5b91

Browse files
authored
Merge branch 'dev' into mergedev_210222
2 parents 76e269e + 5c6cb41 commit 37d5b91

35 files changed

+3202
-1588
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
### Development versions after 0.11.1 release
44

5+
#### Build 2102050
6+
7+
- Version bump to 0.12.0-a0 "Hikari"
8+
- Added FPS indication in info
9+
- Bumped max outputs from 7 to 10 busses for ESP32
10+
11+
#### Build 2101310
12+
13+
- First alpha configurable multipin
14+
515
#### Build 2101130
616

717
- Added color transitions for all segments and slots and for segment brightness

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wled",
3-
"version": "0.11.1",
3+
"version": "0.12.0-a0",
44
"description": "Tools for WLED project",
55
"main": "tools/cdata.js",
66
"directories": {

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
default_envs = travis_esp8266, travis_esp32
1313

1414
# Release binaries
15-
; default_envs = nodemcuv2, esp01_1m_full, esp32dev, custom_WS2801, custom_APA102, custom_LEDPIN_16, custom_LEDPIN_4, custom_LEDPIN_3, custom32_LEDPIN_16, custom32_APA102
15+
; default_envs = nodemcuv2, esp01_1m_full, esp32dev
1616

1717
# Single binaries (uncomment your board)
1818
; default_envs = nodemcuv2

tools/cdata.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
398398
method: "plaintext",
399399
filter: "html-minify",
400400
},
401+
{
402+
file: "liveviewws.htm",
403+
name: "PAGE_liveviewws",
404+
prepend: "=====(",
405+
append: ")=====",
406+
method: "plaintext",
407+
filter: "html-minify",
408+
},
401409
{
402410
file: "404.htm",
403411
name: "PAGE_404",

usermods/BME280_v2/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Hello! I have written a v2 usermod for the BME280/BMP280 sensor based on the [existing v1 usermod](https://github.com/Aircoookie/WLED/blob/master/usermods/Wemos_D1_mini%2BWemos32_mini_shield/usermod_bme280.cpp). It is not just a refactor, there are many changes which I made to fit my use case, and I hope they will fit the use cases of others as well! Most notably, this usermod is *just* for the BME280 and does not control a display like in the v1 usermod designed for the WeMos shield.
2+
3+
- Requires libraries `BME280@~3.0.0` (by [finitespace](https://github.com/finitespace/BME280)) and `Wire`. Please add these under `lib_deps` in your `platform.ini` (or `platform_override.ini`).
4+
- Data is published over MQTT so make sure you've enabled the MQTT sync interface.
5+
- This usermod also writes to serial (GPIO1 on ESP8266). Please make sure nothing else listening on the serial TX pin of your board will get confused by log messages!
6+
7+
To enable, compile with `USERMOD_BME280` defined (i.e. `platformio_override.ini`)
8+
```ini
9+
build_flags =
10+
${common.build_flags_esp8266}
11+
-D USERMOD_BME280
12+
```
13+
or define `USERMOD_BME280` in `my_config.h`
14+
```c++
15+
#define USERMOD_BME280
16+
```
17+
18+
Changes include:
19+
- Adjustable measure intervals
20+
- Temperature and pressure have separate intervals due to pressure not frequently changing at any constant altitude
21+
- Adjustment of number of decimal places in published sensor values
22+
- Separate adjustment for temperature, humidity and pressure values
23+
- Values are rounded to the specified number of decimal places
24+
- Pressure measured in units of hPa instead of Pa
25+
- Calculation of heat index (apparent temperature) and dew point
26+
- These, along with humidity measurements, are disabled if the sensor is a BMP280
27+
- 16x oversampling of sensor during measurement
28+
- Values are only published if they are different from the previous value
29+
- Values are published on startup (continually until the MQTT broker acknowledges a successful publication)
30+
31+
Adjustments are made through preprocessor definitions at the start of the class definition.
32+
33+
MQTT topics are as follows:
34+
Measurement type | MQTT topic
35+
--- | ---
36+
Temperature | `<deviceTopic>/temperature`
37+
Humidity | `<deviceTopic>/humidity`
38+
Pressure | `<deviceTopic>/pressure`
39+
Heat index | `<deviceTopic>/heat_index`
40+
Dew point | `<deviceTopic>/dew_point`
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#pragma once
2+
3+
#include "wled.h"
4+
#include <Arduino.h>
5+
#include <Wire.h>
6+
#include <BME280I2C.h> // BME280 sensor
7+
#include <EnvironmentCalculations.h> // BME280 extended measurements
8+
9+
class UsermodBME280 : public Usermod
10+
{
11+
private:
12+
// User-defined configuration
13+
#define Celsius // Show temperature mesaurement in Celcius. Comment out for Fahrenheit
14+
#define TemperatureDecimals 1 // Number of decimal places in published temperaure values
15+
#define HumidityDecimals 0 // Number of decimal places in published humidity values
16+
#define PressureDecimals 2 // Number of decimal places in published pressure values
17+
#define TemperatureInterval 5 // Interval to measure temperature (and humidity, dew point if available) in seconds
18+
#define PressureInterval 300 // Interval to measure pressure in seconds
19+
20+
// Sanity checks
21+
#if !defined(TemperatureDecimals) || TemperatureDecimals < 0
22+
#define TemperatureDecimals 0
23+
#endif
24+
#if !defined(HumidityDecimals) || HumidityDecimals < 0
25+
#define HumidityDecimals 0
26+
#endif
27+
#if !defined(PressureDecimals) || PressureDecimals < 0
28+
#define PressureDecimals 0
29+
#endif
30+
#if !defined(TemperatureInterval) || TemperatureInterval < 0
31+
#define TemperatureInterval 1
32+
#endif
33+
#if !defined(PressureInterval) || PressureInterval < 0
34+
#define PressureInterval TemperatureInterval
35+
#endif
36+
37+
#ifdef ARDUINO_ARCH_ESP32 // ESP32 boards
38+
uint8_t SCL_PIN = 22;
39+
uint8_t SDA_PIN = 21;
40+
#else // ESP8266 boards
41+
uint8_t SCL_PIN = 5;
42+
uint8_t SDA_PIN = 4;
43+
//uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8
44+
#endif
45+
46+
// BME280 sensor settings
47+
BME280I2C::Settings settings{
48+
BME280::OSR_X16, // Temperature oversampling x16
49+
BME280::OSR_X16, // Humidity oversampling x16
50+
BME280::OSR_X16, // Pressure oversampling x16
51+
// Defaults
52+
BME280::Mode_Forced,
53+
BME280::StandbyTime_1000ms,
54+
BME280::Filter_Off,
55+
BME280::SpiEnable_False,
56+
BME280I2C::I2CAddr_0x76 // I2C address. I2C specific. Default 0x76
57+
};
58+
59+
BME280I2C bme{settings};
60+
61+
uint8_t SensorType;
62+
63+
// Measurement timers
64+
long timer;
65+
long lastTemperatureMeasure = 0;
66+
long lastPressureMeasure = 0;
67+
68+
// Current sensor values
69+
float SensorTemperature;
70+
float SensorHumidity;
71+
float SensorHeatIndex;
72+
float SensorDewPoint;
73+
float SensorPressure;
74+
// Track previous sensor values
75+
float lastTemperature;
76+
float lastHumidity;
77+
float lastHeatIndex;
78+
float lastDewPoint;
79+
float lastPressure;
80+
81+
// Store packet IDs of MQTT publications
82+
uint16_t mqttTemperaturePub = 0;
83+
uint16_t mqttPressurePub = 0;
84+
85+
void UpdateBME280Data(int SensorType)
86+
{
87+
float _temperature, _humidity, _pressure;
88+
#ifdef Celsius
89+
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
90+
EnvironmentCalculations::TempUnit envTempUnit(EnvironmentCalculations::TempUnit_Celsius);
91+
#else
92+
BME280::TempUnit tempUnit(BME280::TempUnit_Fahrenheit);
93+
EnvironmentCalculations::TempUnit envTempUnit(EnvironmentCalculations::TempUnit_Fahrenheit);
94+
#endif
95+
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
96+
97+
bme.read(_pressure, _temperature, _humidity, tempUnit, presUnit);
98+
99+
SensorTemperature = _temperature;
100+
SensorHumidity = _humidity;
101+
SensorPressure = _pressure;
102+
if (SensorType == 1)
103+
{
104+
SensorHeatIndex = EnvironmentCalculations::HeatIndex(_temperature, _humidity, envTempUnit);
105+
SensorDewPoint = EnvironmentCalculations::DewPoint(_temperature, _humidity, envTempUnit);
106+
}
107+
}
108+
109+
public:
110+
void setup()
111+
{
112+
Wire.begin(SDA_PIN, SCL_PIN);
113+
114+
if (!bme.begin())
115+
{
116+
SensorType = 0;
117+
Serial.println("Could not find BME280I2C sensor!");
118+
}
119+
else
120+
{
121+
switch (bme.chipModel())
122+
{
123+
case BME280::ChipModel_BME280:
124+
SensorType = 1;
125+
Serial.println("Found BME280 sensor! Success.");
126+
break;
127+
case BME280::ChipModel_BMP280:
128+
SensorType = 2;
129+
Serial.println("Found BMP280 sensor! No Humidity available.");
130+
break;
131+
default:
132+
SensorType = 0;
133+
Serial.println("Found UNKNOWN sensor! Error!");
134+
}
135+
}
136+
}
137+
138+
void loop()
139+
{
140+
// BME280 sensor MQTT publishing
141+
// Check if sensor present and MQTT Connected, otherwise it will crash the MCU
142+
if (SensorType != 0 && mqtt != nullptr)
143+
{
144+
// Timer to fetch new temperature, humidity and pressure data at intervals
145+
timer = millis();
146+
147+
if (timer - lastTemperatureMeasure >= TemperatureInterval * 1000 || mqttTemperaturePub == 0)
148+
{
149+
lastTemperatureMeasure = timer;
150+
151+
UpdateBME280Data(SensorType);
152+
153+
float Temperature = roundf(SensorTemperature * pow(10, TemperatureDecimals)) / pow(10, TemperatureDecimals);
154+
float Humidity, HeatIndex, DewPoint;
155+
156+
// If temperature has changed since last measure, create string populated with device topic
157+
// from the UI and values read from sensor, then publish to broker
158+
if (Temperature != lastTemperature)
159+
{
160+
String topic = String(mqttDeviceTopic) + "/temperature";
161+
mqttTemperaturePub = mqtt->publish(topic.c_str(), 0, false, String(Temperature, TemperatureDecimals).c_str());
162+
}
163+
164+
lastTemperature = Temperature; // Update last sensor temperature for next loop
165+
166+
if (SensorType == 1) // Only if sensor is a BME280
167+
{
168+
Humidity = roundf(SensorHumidity * pow(10, HumidityDecimals)) / pow(10, HumidityDecimals);
169+
HeatIndex = roundf(SensorHeatIndex * pow(10, TemperatureDecimals)) / pow(10, TemperatureDecimals);
170+
DewPoint = roundf(SensorDewPoint * pow(10, TemperatureDecimals)) / pow(10, TemperatureDecimals);
171+
172+
if (Humidity != lastHumidity)
173+
{
174+
String topic = String(mqttDeviceTopic) + "/humidity";
175+
mqtt->publish(topic.c_str(), 0, false, String(Humidity, HumidityDecimals).c_str());
176+
}
177+
178+
if (HeatIndex != lastHeatIndex)
179+
{
180+
String topic = String(mqttDeviceTopic) + "/heat_index";
181+
mqtt->publish(topic.c_str(), 0, false, String(HeatIndex, TemperatureDecimals).c_str());
182+
}
183+
184+
if (DewPoint != lastDewPoint)
185+
{
186+
String topic = String(mqttDeviceTopic) + "/dew_point";
187+
mqtt->publish(topic.c_str(), 0, false, String(DewPoint, TemperatureDecimals).c_str());
188+
}
189+
190+
lastHumidity = Humidity;
191+
lastHeatIndex = HeatIndex;
192+
lastDewPoint = DewPoint;
193+
}
194+
}
195+
196+
if (timer - lastPressureMeasure >= PressureInterval * 1000 || mqttPressurePub == 0)
197+
{
198+
lastPressureMeasure = timer;
199+
200+
float Pressure = roundf(SensorPressure * pow(10, PressureDecimals)) / pow(10, PressureDecimals);
201+
202+
if (Pressure != lastPressure)
203+
{
204+
String topic = String(mqttDeviceTopic) + "/pressure";
205+
mqttPressurePub = mqtt->publish(topic.c_str(), 0, true, String(Pressure, PressureDecimals).c_str());
206+
}
207+
208+
lastPressure = Pressure;
209+
}
210+
}
211+
}
212+
};

0 commit comments

Comments
 (0)