Jump to content

Gina

Beyond the Event Horizon
  • Posts

    45,326
  • Joined

  • Last visited

  • Days Won

    120

Posts posted by Gina

  1. Strange things still happening with the dashboard display.  Every so often it disappears altogether, sometimes some or all of the widgets disappear, sometimes these only show the last few seconds or minutes and most of the time shows everything correctly with full histories. 

    I have the Pressure History set to 4 days and data has been retained in the RPi since it was last powered up yesterday (Friday) at about 10am, so it's been holding data for over 24 hours now.  The RPi is being powered by a Raspberry PSU plugged into the UPS system so power has been on continuously.  Seems the data is being held in the RPi and disconnecting sensors makes no difference except that no data is logged while they're off.  Nor does disconnecting the RPi from the Mint box.  So data must be held by either the broker, Node-RED or Dashboard.

  2. Been looking at the Met Office definitions of Mean and Gust speeds:-

    Quote

    The gust speed and direction are defined by the maximum three second average wind speed occurring in any period…overall wind intensity is defined by the average speed and direction over the ten-minute period leading up to the reporting time. Mean wind over other averaging periods may also be calculated.” Met Office

    With Gust being wind speed in a 3s period, this seems to be what I should use as the Interval.  If I were to use a 10m period for the Mean wind speed, I think I would like a rolling average so that it doesn't produce big changes in the displayed Mean Wind Speed.  Looks like the wind ESP32 will be doing quite a lot of work, processing all this data but it does seem to be a fast processor.  We shall see!

  3. Gone back to my calculations of the relationship of wind speed to pps from the Hall sensor.  With 4 magnets it worked out at a little under 1mph per pps, so with 2 magnets it's mph for counts in a 2s period.  Actually, the figure has come out as 2.3.  If I use 4.6s as the interval between readings I can divide by 2 for mph.  I thought of using just one magnet but that would unbalance the anemometer, though admittedly with those small magnets close to the axis, maybe not much.

    Alternatively, maybe a 2.3s interval would be alright and would simplify the calculations.  It doesn't necessarily mean that messages are sent at that rate.  I'm reluctant to send messages over MQTT too often but I may be over cautious..

  4. I think this might work.  (Password removed,)

    /*********
      Rui Santos
      Complete project details at https://randomnerdtutorials.com  
    ********
    Modified and added to by Gina 2020-08-21
    ********
    */
    
    const int intervalSeconds = 4;  //  Set sampling interval in seconds
    
    // Set GPIO for Hall Sensor
    const int HallSensorPin = 27;
    int PulseCount = 0;
    
    #include <WiFi.h>
    #include <PubSubClient.h>
    #include <Wire.h>
    
    // Replace the next variables with your SSID/Password combination
    const char* ssid = "Ubiquity";
    const char* password = "--------";
    
    const char* mqtt_server = "192.168.1.250";
    
    WiFiClient windClient;
    PubSubClient client(windClient);
    long lastMsg = 0;
    char msg[50];
    int value = 0;
    
    // Checks if Hall sensor was triggered
    void IRAM_ATTR HallTriggered() {
    //  Serial.println("Hall Triggered");
      ++PulseCount; // Increment count
    }
    
    void setup() {
      Serial.begin(115200);
      setup_wifi();
      client.setServer(mqtt_server, 1883);
      client.setCallback(callback);
      
      // Hall Sensor mode INPUT_PULLUP
      pinMode(HallSensorPin, INPUT_PULLUP);
      // Set HallSensor pin as interrupt, assign interrupt function and set FALLING mode
      attachInterrupt(digitalPinToInterrupt(HallSensorPin), HallTriggered, FALLING);
    }
    
    void setup_wifi() {
      delay(10);
      // We start by connecting to a WiFi network
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);
    
      WiFi.begin(ssid, password);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    }
    
    void callback(char* topic, byte* message, unsigned int length) {
      Serial.print("Message arrived on topic: ");
      Serial.print(topic);
      Serial.print(". Message: ");
      String messageTemp;
      
      for (int i = 0; i < length; i++) {
        Serial.print((char)message[i]);
        messageTemp += (char)message[i];
      }
      Serial.println();
    
      // Feel free to add more if statements to control more GPIOs with MQTT
    
    }
    
    void reconnect() {
      // Loop until we're reconnected
      while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (client.connect("windClient")) {
          Serial.println("connected");
          // Subscribe
    //      client.subscribe("esp32/output");
    //      client.subscribe("esp32/roof");
        } else {
          Serial.print("failed, rc=");
          Serial.print(client.state());
          Serial.println(" try again in 5 seconds");
          // Wait 5 seconds before retrying
          delay(5000);
        }
      }
    }
    void loop() {
      if (!client.connected()) {
        reconnect();
      }
      client.loop();
    
      long now = millis();
      if(now - lastMsg > (intervalSeconds*1000)) {
        Serial.println("PulseCount :- ");
        lastMsg = now;
        
        // Convert the value to a char array
        char countString[8];
        dtostrf(PulseCount, 1, 0, countString);
        Serial.print("Count: ");
        Serial.println(countString);
        client.publish("wind/speed", countString);
        PulseCount = 0;
      }
    }

     

  5. This is the code for the Hall sensor interrupt setup with Serial Monitor for testing..

    /*********
      Rui Santos
      Complete project details at https://randomnerdtutorials.com  
    ********
    * Modifued by Gina for Wind Sensors
    */
    
    const int intervalSeconds = 4;  //  Set sampling interval in seconds
    
    // Set GPIO for Hall Sensor
    const int HallSensorPin = 27;
    int PulseCount = 0;
    
    // Timer: Auxiliary variables
    unsigned long now = millis();
    unsigned long lastMsg = millis();
    
    // Checks if Hall sensor was triggered
    void IRAM_ATTR HallTriggered() {
    //  Serial.println("Hall Triggered");
      ++PulseCount; // Increment count
    }
    
    void setup() {
      // Serial port for debugging purposes
      Serial.begin(115200);
      
      // Hall Sensor mode INPUT_PULLUP
      pinMode(HallSensorPin, INPUT_PULLUP);
      // Set HallSensor pin as interrupt, assign interrupt function and set FALLING mode
      attachInterrupt(digitalPinToInterrupt(HallSensorPin), HallTriggered, FALLING);
    }
    
    void loop() {
      // Current time
      now = millis();
      // 
      if(now - lastMsg > (intervalSeconds*1000)) {
        Serial.println("PulseCount :- ");
        PulseCount = 0;
        lastMsg = now;
      }
    }

     

  6. While the Button sketch is fairly close to the operation I want it's not right but that and another example using a PIR device to cause an interrupt have given me the information I need.

    The Hall sensor will trigger an interrupt and the ISR will count the pulses.  In the Loop I will time the period using millis as with the other MQTT sketches.  This will produce a timing loop which will take the count and send it to the broker then reset the count. 

  7. I'm now looking at the wind sensors unit.  Anemometer and wind vane.

    The anemometer has a Hall device which has an open collector output and Schmitt trigger incorporated so the o/p is digital.  This would look the same as a button to the ESP32.  The rotating part has two magnets giving 2 pulses per revolution.  I've worked out that this would give one pulse per mph with a 2s counting time.  The usual sampling period for the other sensors is 5s so I might go for 4s period rather than 2s.  Anyway, I can decide that later.  The signal from the Hall sensor will trigger an interrupt to count pulses while the time in between will read the wind vane and do some calculations for wind direction.

    This is a sketch I have found for ESP32 interrupt processing.

    struct Button {
      const uint8_t PIN;
      uint32_t numberKeyPresses;
      bool pressed;
    };
    
    Button button1 = {18, 0, false};
    
    void IRAM_ATTR isr() {
      button1.numberKeyPresses += 1;
      button1.pressed = true;
    }
    
    void setup() {
      Serial.begin(115200);
      pinMode(button1.PIN, INPUT_PULLUP);
      attachInterrupt(button1.PIN, isr, FALLING);
    }
    
    void loop() {
      if (button1.pressed) {
          Serial.printf("Button 1 has been pressed %u times\n", button1.numberKeyPresses);
          button1.pressed = false;
      }
    
      //Detach Interrupt after 1 Minute
      static uint32_t lastMillis = 0;
      if (millis() - lastMillis > 60000) {
        lastMillis = millis();
        detachInterrupt(button1.PIN);
      Serial.println("Interrupt Detached!");
      }
    }

    I doubt there would be any reason to detach the interrupt in my case.  Instead there would be procedures called every so often from the void loop to process the count and the wind direction.  This code will be integrated into the MQTT sketch.  The button.pressed state will need moving to the ISR I think.  I'll think about that.

  8. Yes, I'm hoping to.  I have an Arduino which was set up for data logging on an SD card, some years ago.  Maybe I can connect that into my MQTT network.  OTOH I don't know if I still have the sketch I used.  I don't think there's any way of recovering the sketch from the Arduino as the code is compiled before uploading.  May be quicker/easier to just start anew.  The data was stored as a text file with one line per data point.

    • Like 1
  9. 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.

     

  10. 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);
      }

     

  11. 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?

×
×
  • 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.