Skip to content

Commit

Permalink
Use fixed version of expressif library to prevent linker error.
Browse files Browse the repository at this point in the history
Log if taking a measurement with the BME280 sensor has failed.
Formatting
  • Loading branch information
luebbe committed Aug 19, 2023
1 parent a00e781 commit b30fcb7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
10 changes: 6 additions & 4 deletions examples/demo-relay-contact-nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ void setup()
<< endl;

// Set callback for contact node here, just to show alternative
contactNode.onChange([](bool open)
{
// Pass 0 in timeout for infinite "on"
relay1.setRelay(open, 0); });
contactNode.onChange(
[](bool open)
{
// Pass 0 in timeout for infinite "on"
relay1.setRelay(open, 0);
});

// Set default configuration values before Homie.setup()
relay1.beforeHomieSetup();
Expand Down
14 changes: 10 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ serial_speed = 74880
display = DISPLAY_SERIAL

[env]
platform = espressif8266
platform = espressif8266@4.1.0 ; July 2023: newer expressif platform versions cause a linker error.
framework = arduino
build_flags = -D ${defines.display} -D SERIAL_SPEED=${defines.serial_speed}
; (Un)comment the libraries that you do (not) have installed in your global library storage.
lib_deps =
; User homie directly, because the official release is not compatible with ESP8266 3.x
https://github.com/homieiot/homie-esp8266.git
; Use homie directly, because the official release is not compatible with ESP8266 3.x
https://github.com/luebbe/homie-esp8266.git
; Homie
Adafruit BusIO
Adafruit Unified Sensor
Expand All @@ -47,5 +47,11 @@ upload_speed = 230400

[env:d1_mini]
board = d1_mini
; upload_port = 192.168.0.58
upload_speed = 460800 ;230400
; upload_port = 192.168.0.99
; upload_protocol = espota

; [env:esp_adc]
; board = esp12e
; #512 kb for ESP-ADC (in-circuit)
; build_flags = ${env.build_flags} -Wl,-Tesp8266.flash.512k64.ld -D HOMIE_MDNS=0 -D HOMIE_CONFIG=0
25 changes: 16 additions & 9 deletions src/BME280Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,22 @@ void BME280Node::send()

void BME280Node::takeMeasurement()
{
bme.takeForcedMeasurement(); // has no effect in normal mode

temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100;
// has no effect in normal mode
if (bme.takeForcedMeasurement())
{
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100;

fixRange(&temperature, cMinTemp, cMaxTemp);
fixRange(&humidity, cMinHumid, cMaxHumid);
fixRange(&pressure, cMinPress, cMaxPress);
fixRange(&temperature, cMinTemp, cMaxTemp);
fixRange(&humidity, cMinHumid, cMaxHumid);
fixRange(&pressure, cMinPress, cMaxPress);
}
else
{
printCaption();
Homie.getLogger() << cIndent << F("Failed to take measurement") << endl;
}
}

void BME280Node::beforeHomieSetup()
Expand All @@ -114,7 +121,7 @@ void BME280Node::setup()
if (bme.begin(_i2cAddress))
{
_sensorFound = true;
Homie.getLogger() << cIndent << F("found. Reading interval: ") << readInterval() << " ms" << endl;
Homie.getLogger() << cIndent << F("found. Reading interval: ") << readInterval() << F(" ms") << endl;
// Parameters taken from the weather station monitoring example (advancedsettings.ino) in
// the Adafruit BME280 library
bme.setSampling(Adafruit_BME280::MODE_FORCED, _tempSampling, _pressSampling, _humSampling, _filter);
Expand Down

0 comments on commit b30fcb7

Please sign in to comment.