Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Setting up an MQTT system for Weather Sensing and Astro Control


Gina

Recommended Posts

Reading the github library advanced section for weather...

    bme.setSampling(Adafruit_BME280::MODE_FORCED,
                    Adafruit_BME280::SAMPLING_X1, // temperature
                    Adafruit_BME280::SAMPLING_X1, // pressure
                    Adafruit_BME280::SAMPLING_X1, // humidity
                    Adafruit_BME280::FILTER_OFF   );

This is what I'm using except for the pressure, which I'm not reading anyway.

Edited by Gina
Link to comment
Share on other sites

The spikes in the temperature history are bad!  OTOH I'm not sure I need the history for inside the obsy - a single current reading should be sufficient.

1789654040_Screenshotfrom2020-08-2009-57-47.png.41ed9027c3fe1417d477fccacfbad331.png

Link to comment
Share on other sites

I've put the obsy sensor unit back out in the obsy, plugged the outside BME280 in and powered up.  The outside pressure isn't working and I'm not sure about the inside (obsy) readings.  The Living Room unit is working fine.  There are no spikes showing (without Forced Mode).  I'm not too worried about the outside pressure as I have the indoor pressure and that's sufficient.  Think I'll now do some tidying up of the display as a lot of it was just for testing.

1191850188_Screenshotfrom2020-08-2011-07-18.png.f6af6da3091ecc87b8040d344b246464.png

Link to comment
Share on other sites

Changed the display.  I think this is better.  I don't think the Observatory inside sensor is working properly though.  The Observatory Roof controls are just "place holders" ATM as I haven't got an ESP32 connected for controlling the ROR yet.

1760714054_Screenshotfrom2020-08-2011-39-26.png.5bdc8907c2a32e602622eb064dd34728.png

  • Like 1
Link to comment
Share on other sites

Yes, that makes sense and that's what I'm doing.

Now trying to get a sensible layout in the Dashboard.  There must be some way to position the widgets but I haven't found it yet!  Still working on the sizes.

1778446478_Screenshotfrom2020-08-2011-57-55.thumb.png.8fca9c074d0719a1ccb1e320bef6e40a.png

Link to comment
Share on other sites

The second BME280 set to address 0x77 does not seem to be working.  Wondering if using one on I2C bus and other on SPI bus would be better that both on I2C with different addresses.  Or maybe I'm doing it wrong.

I'm setting the two sensors as

Adafruit_BME280 bme; // I2C (0x76)
Adafruit_BME280 bme2; // I2C (0x77)

Setting them going with :-

void setup() {
  Serial.begin(115200);
  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  //status = bme.begin();  
  if (!bme.begin(0x76) and (!bme2.begin(0x77))) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

Then reading by :-

    temperature = bme.readTemperature();   

    obsT = bme2.readTemperature();

What I'm unsure of is whether

  if (!bme.begin(0x76) and (!bme2.begin(0x77))) {

Really does begin both.

Link to comment
Share on other sites

I think I'll try splitting the if and the begin operations

  bool status1 = bme.begin(0x76);  
  bool status2 = bme.begin(0x77);  
  if (!status1 and !status2) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

 

Link to comment
Share on other sites

You do need a separate bme object per device otherwise you will always read he one you have stored the address for last.

e.g

BME280 bme76;

BME280 bme77; 

status1 = bme76.begin( 0x76 ); etc. 

Where is wire being initialised and set to use the right pins ?

 

Link to comment
Share on other sites

9 minutes ago, skybadger said:

You do need a separate bme object per device otherwise you will always read he one you have stored the address for last.

e.g

BME280 bme76;

BME280 bme77; 

status1 = bme76.begin( 0x76 ); etc. 

Where is wire being initialised and set to use the right pins ?

 

I'm using the Adafruit library which works fine with one BME280 but do I need the Wire library as well if I want to use two with different addresses?

Link to comment
Share on other sites

Don't think there's any reason not to use I2C for both. Adding I2C and SPI will complicate both software and hardware.

In your sketch extract, you started the the same bme twice - maybe you've spotted this. I also don't like using 'and' in this context because it won't trap  if one of the sensors fails. How about:

 bool status1, status2;

// Assumes that Adafruit_BME280.begin() returns 0 on fail, <>0 on success?
if (!(status1 = bme.begin(0x76) )
{ Serial.println("Could not find BME280 sensor on 0x76, check wiring!"); }

if (!(status2 = bme2.begin(0x77) )
{ Serial.println("Could not find BME280 sensor on 0x77, check wiring!"); }
 
  if (!(status1 and status2)) { // traps if either sensor fails.
    Serial.println("Sensors not connected!");
    while (1);
  }
Link to comment
Share on other sites

On the Esp you can have two wires (maybe more) running and point each instance at a set of pins. 

You do need to do Wire.begin( SCL=x, SDA=Y, optionalLocalMasterAdd) in setup but Adafruit sometimes hides this inside the library because its a bit noddy and assumes you only have one device. I pull these bits out and do something like bme280.begin( address, twowire& myref) so I can tell it what wire interface to use. Otherwise these libraries often assume default pins and only one instance. 

Link to comment
Share on other sites

Possibly starting a coding war, but using status1 && status 2 will fail if status1 is not TRUE. because the compiler spec is to check them in order and fail as necessary. For clarity and the next person, obtain the status of the things you are interested in first and then do the logic and reporting. 

Link to comment
Share on other sites

I am now getting the status first and then checking it but I think I may have found the problem

void setup() {
  Serial.begin(115200);
  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  //status = bme.begin();  
  bool status1 = bme.begin(0x76);  
  bool status2 = bme.begin(0x77);  
  if (!status1 and !status2) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

I think this should be

void setup() {
  Serial.begin(115200);
  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  //status = bme.begin();  
  bool status1 = bme.begin(0x76);  
  bool status2 = bme2.begin(0x77);  //  THIS LINE WAS WRONG!!!!
  if (!status1 and !status2) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

 

Link to comment
Share on other sites

Seems to be working correctly now having corrected that silly mistake!  I'll let it run for a while and then post a screenshot.

Edited by Gina
Link to comment
Share on other sites

At last I've discovered how to move the widgets around on the Dashboard.  There's a Layout tab for the Dashboard with dropdowns for the widgets.  Grab and move them into the required order.

803744261_Screenshotfrom2020-08-2014-53-12.png.cc9c128a5797c501704537ae4d1c4937.png

Link to comment
Share on other sites

I'm still getting some strange effects which I don't understand.  For instance, in the History graphs, instead of getting the full history from when the device was started, it sometimes gets cut short sometimes the same minute at start and finish.  Then gradually the time covered increases. This is not global, I mean not all graphs are affected in the same way.  Also, it only happens occasionally.

 

Link to comment
Share on other sites

Just happened again and this time all histories reset to 18:30.  If I can't stop this happening the histories will often be useless.  In actual fact only the atmospheric pressure trend really means anything.  Maybe a better idea is to store older values in the ESP32 and compare with current reading to determine the trend and display that as a Gauge. 

514137691_Screenshotfrom2020-08-2018-33-17.thumb.png.30228ce056dad60b736a6b10424f8836.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.