Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Stig
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Stig

    @Stig

    1
    Reputation
    10
    Posts
    3
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Stig Follow

    Best posts made by Stig

    • RE: GatewayESP32MQTT with local sensor crashes

      Thanks, mfalkvidd! Whaddya know, that was the problem...

      Another thing I just thought of, is it correct to use send(temperatureMsg.set(temperature, 1)), etc., when the sensor is local, or is it treated by the gateway as any other remote sensor information coming in?
      Seems like it is not sending much useful date to the MQTT broker either. This is what is send every minute (according to the serial monitor)

      BME280 - Sensor module has some new values ready:
      BME280 - Sending the new temperature to the gateway.
      60093 GWT:TPS:TOPIC=mygateway1-out/0/1/1/0/0,MSG SENT
      BME280 - Sending the new humidity to the gateway.
      60106 GWT:TPS:TOPIC=mygateway1-out/0/2/1/0/1,MSG SENT
      BME280 - Sending the new pressure to the gateway.
      60116 GWT:TPS:TOPIC=mygateway1-out/0/3/1/0/4,MSG SENT
      BME280 - Measurement complete. Going to wait until next measurement.
      63579 GWT:TPC:IP=10.10.10.180
      63582 GWT:RMQ:CONNECTING...
      64290 GWT:RMQ:OK
      64291 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/18,MSG SENT
      64301 GWT:TPS:TOPIC=mygateway1-out/0/255/3/0/11,MSG SENT
      64308 GWT:TPS:TOPIC=mygateway1-out/0/255/3/0/12,MSG SENT
      64313 GWT:TPS:TOPIC=mygateway1-out/0/3/0/0/8,MSG SENT
      64319 GWT:TPS:TOPIC=mygateway1-out/0/1/0/0/6,MSG SENT
      64324 GWT:TPS:TOPIC=mygateway1-out/0/2/0/0/7,MSG SENT
      

      So far I only have the log from the MQTT broker (Mosquito) to look at and it looks like a lot of the messages aren't arriving at the broker. I may have to set up a MQTT client to look at the actual messages to get a better look at what is going out from the gateway.

      posted in Development
      Stig
      Stig

    Latest posts made by Stig

    • RE: PlatformIO, nRF52832 and MyBoardNRF5

      @electrik

      upload_port does not specify the target. It just selects if you'll use the gdb port or the uart port from the BMP. The target I'm talking about is what comes up when trying to do upload.

      Configuring upload protocol...
      AVAILABLE: blackmagic, cmsis-dap, jlink, nrfjprog, nrfutil, stlink
      CURRENT: upload_protocol = blackmagic
      Looking for BlackMagic port...
      Auto-detected: COM2
      Uploading .pio\build\MyBoardNRF5\firmware.hex
      Target voltage: 3.45V
      Available Targets:
      No. Att Driver
       1      Nordic nRF52 M3/M4
       2      Nordic nRF52 Access Port
      0x000020d8 in transportProcessFIFO() ()
      Loading section .text, size 0x895c lma 0x0
      Loading section .ARM.exidx, size 0x8 lma 0x895c
      Loading section .data, size 0x23c lma 0x8964
      Start address 0x32e0, load size 35744
      Transfer rate: 42 KB/sec, 916 bytes/write.
      Section .text, range 0x0 -- 0x895c: matched.
      Section .ARM.exidx, range 0x895c -- 0x8964: matched.
      Section .data, range 0x8964 -- 0x8ba0: matched.
      Kill the program being debugged? (y or n) [answered Y; input not from terminal]
      

      If I don't do

      #define MYBOARDNRF5
      

      then PlatformIO complains about undefined reference to 'g_ADigitalPinMap', which is in compat_pin_mapping.h and is called from MyBoardNRF5.cpp when MYBOARDNRF5 is defined. But I see that your variant.h/.cpp is different than the ones coming with ArduinoHwNRF5, which I'm using. Maybe try your version instead and see what happens...

      posted in Development
      Stig
      Stig
    • RE: PlatformIO, nRF52832 and MyBoardNRF5

      @electrik
      Thank you!

      I see that you don't define MYBOARDNRF5 anywhere, unless that happens in any of the MySensors files. Doesn't this exclude more or less everything from MyBoardNRF.cpp?

      Another thing, when I try to do upload (through PlatformIO), it comes up with 2 targets, but I can't see anywhere where I can specify the target to attach to. When I try to start arm-eabi-none-gdb manually, it fails with an internal error when I try to attach to a target manually.

      posted in Development
      Stig
      Stig
    • RE: PlatformIO, nRF52832 and MyBoardNRF5

      @electrik,

      Thanks. I had looked at this previously. He was using nrf52_dk, not MyBoardNRF5. I don't know if that makes it easier or harder. I'm not a programmer, which is probably part of why I'm struggling to get this to work... 🙂
      If you have a proper example to show, that would be great!

      Maybe just ditch PlatformIO for the nodes and use Arduino IDE instead, but I would prefer to continue using PlatformIO.

      posted in Development
      Stig
      Stig
    • RE: PlatformIO, nRF52832 and MyBoardNRF5

      Googling "platformio myboardnrf5 nrf52832" gives this thread as the first hit... 🙂

      I had already copied the variant.xxx files into the correct folder and MyBoardNRF5.h/cpp to src. Will they be automatically included during Build, or do I need to tell the compiler to include them somehow?
      Another thing, when doing this in the Arduino IDE, it seems several compiler directives (?) are set when you select the board and processor, which seems to not happen in PlatformIO, like MYBOARDNRF5 and MY_ARDUINO_CORE_NRF5. Is this something I need to do somehow in platformio.ini or do I add them in main.cpp? I tried to do it in main.cpp, and then it complained about missing syscalls.h (from variant.h)

      I had also seen the guide for beginners-thread previously, but it didn't get any clearer this time either.

      posted in Development
      Stig
      Stig
    • PlatformIO, nRF52832 and MyBoardNRF5

      Hi, all.

      I'm back with another problem... 🙂

      I've started trying to get some nodes up and running, and I've hit a roadblock. I'm using PlatformIO as my IDE and my nodes are using Rigado BMD-300 modules, which are based on nRF52832 chips. I managed to get them to work in Arduino IDE a couple of years ago, using MyBoardNRF5, but I'm struggling to get them to work in PlatformIO.

      I've managed to make a MyBoardNRF5.json file and put it in 'board' in my project folder and the files under variants in variants\MyBoardNRF5, but I'm struggling with where to put MyBoardNRF5.h/.cpp. I've tried to put them in 'variants\MyBoardNRF5', in include and in 'src', but it seems PlatformIO isn't picking them up, as I get an error message that the reference "g_ADigitalPinMap" is undefined, which happens in compat_pin_arduino.h. It also looks like I need to define MYBOARDNRF5 somewhere, so that the information from MyBoardNRF5.cpp is included if this file is loaded.

      Anyone using PlatformIO with a nRF52832 chip, using MyBoardNRF5, have a small project they're willing to share so I can see how it is built up and where the various files should be put?

      My platformio.ini:

      [env:MyBoardNRF5]
      platform		= nordicnrf52
      board			= MyBoardNRF5
      framework		= arduino
      board_build.mcu = nrf52832
      monitor_speed	= 115200
      monitor_port	= COM10
      upload_protocol	= blackmagic
      
      build_flags = 
      	-I variants/MyBoardNRF5
      lib_deps = 
      	mysensors/MySensors@^2.3.2
      	adafruit/Adafruit BME280 Library@^2.2.2
      
      
      posted in Development
      Stig
      Stig
    • RE: GatewayESP32MQTT with local sensor crashes

      @mfalkvidd,
      Personally, I think a string representation would make the most sense, as it is more human-readable than binary or hexadecimal, but if it was made selectable, developers could choose how they want to see it, best of both worlds... 🙂

      How far away is development from a new stable version? It's 3 years since last stable version.

      posted in Development
      Stig
      Stig
    • RE: GatewayESP32MQTT with local sensor crashes

      @mfalkvidd,

      I would have expected more to see the actual message, not "MSG SENT", especially since they are debug messages (on the serial monitor)...

      @electrik, MQTT Explorer worked good to see the messages from the broker. Thanks for the suggestion.

      Now the "fun" part starts, trying to get the custom nRF52 boards working with PlatformIO instead of Arduino IDE... 🙂

      posted in Development
      Stig
      Stig
    • RE: GatewayESP32MQTT with local sensor crashes

      Thanks, mfalkvidd! Whaddya know, that was the problem...

      Another thing I just thought of, is it correct to use send(temperatureMsg.set(temperature, 1)), etc., when the sensor is local, or is it treated by the gateway as any other remote sensor information coming in?
      Seems like it is not sending much useful date to the MQTT broker either. This is what is send every minute (according to the serial monitor)

      BME280 - Sensor module has some new values ready:
      BME280 - Sending the new temperature to the gateway.
      60093 GWT:TPS:TOPIC=mygateway1-out/0/1/1/0/0,MSG SENT
      BME280 - Sending the new humidity to the gateway.
      60106 GWT:TPS:TOPIC=mygateway1-out/0/2/1/0/1,MSG SENT
      BME280 - Sending the new pressure to the gateway.
      60116 GWT:TPS:TOPIC=mygateway1-out/0/3/1/0/4,MSG SENT
      BME280 - Measurement complete. Going to wait until next measurement.
      63579 GWT:TPC:IP=10.10.10.180
      63582 GWT:RMQ:CONNECTING...
      64290 GWT:RMQ:OK
      64291 GWT:TPS:TOPIC=mygateway1-out/0/255/0/0/18,MSG SENT
      64301 GWT:TPS:TOPIC=mygateway1-out/0/255/3/0/11,MSG SENT
      64308 GWT:TPS:TOPIC=mygateway1-out/0/255/3/0/12,MSG SENT
      64313 GWT:TPS:TOPIC=mygateway1-out/0/3/0/0/8,MSG SENT
      64319 GWT:TPS:TOPIC=mygateway1-out/0/1/0/0/6,MSG SENT
      64324 GWT:TPS:TOPIC=mygateway1-out/0/2/0/0/7,MSG SENT
      

      So far I only have the log from the MQTT broker (Mosquito) to look at and it looks like a lot of the messages aren't arriving at the broker. I may have to set up a MQTT client to look at the actual messages to get a better look at what is going out from the gateway.

      posted in Development
      Stig
      Stig
    • RE: GatewayESP32MQTT with local sensor crashes

      Thanks, ejlane.

      No, I have combined the code from the BME280 sensor example into the gateway code to have a local sensor on the gateway, which is supposed to be supported now. Btw, I'm using MySensors v2.3.2, not development branch. I have not started using any nodes so far, so just the ESP32 board is running.

      platformio.ini

      [env:lolin32]
      platform = espressif32
      board = lolin32
      framework = arduino
      monitor_speed = 115200
      lib_deps = 
      	mysensors/MySensors@^2.3.2
      	adafruit/Adafruit BME280 Library@^2.2.2
      
      

      main.cpp

      // Set Static Node ID
      #define MY_NODE_ID 12
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enables and select radio type (if attached)
      #define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      #define MY_GATEWAY_MQTT_CLIENT
      #define MY_GATEWAY_ESP32
      
      // Set this node's subscribe and publish topic prefix
      //#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
      //#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
      
      // Set MQTT client id
      //#define MY_MQTT_CLIENT_ID "mysensors-1"
      
      // Enable these if your MQTT broker requires usenrame/password
      //#define MY_MQTT_USER "username"
      //#define MY_MQTT_PASSWORD "password"
      
      // Set WIFI SSID and password
      //#define MY_WIFI_SSID "MySSID"
      //#define MY_WIFI_PASSWORD "MyVerySecretPassword"
      
      // Set the hostname for the WiFi Client. This is the hostname
      // passed to the DHCP server if not static.
      //#define MY_HOSTNAME "ESP32_MQTT_GW"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      //#define MY_IP_ADDRESS 192,168,178,87
      
      // If using static ip you can define Gateway and Subnet address as well
      //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
      //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // MQTT broker ip address.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 5
      
      // The MQTT broker port to to open
      #define MY_PORT 1883
      
      #include <Arduino.h>
      #include <secrets.h>
      #include <MySensors.h>
      #include <SPI.h>                                  // A communication backbone, the Serial Peripheral Interface.
      #include <Wire.h>                                 // Enables the Wire communication protocol.
      #include <Adafruit_BME280.h>                    // alternative library you could try (DIY; no code for this is in here yet).
      
      // VARIABLES YOU CAN CHANGE
      const float ALTITUDE = 160;                        // Change this value to your location's altitude (in m). Use your smartphone GPS to get an accurate value, or use an online map.
      unsigned long BME280measurementInterval = 60000;  // Sleep time between reads for the BME sensor (in ms). Keep this value at 60000 if you have enabled the forecast feature, as the forecast algorithm needs a sample every minute.
      #define COMPARE_TEMP 0                            // Send temperature only if it changed? 1 = Yes 0 = No. Can save battery.
      float tempThreshold = 0.1;                        // How big a temperature difference has to minimally  be before an update is sent. Makes the sensor less precise, but also less jittery, and can save battery.
      #define COMPARE_HUM 0                             // Send humidity only if changed? 1 = Yes 0 = No. Can save battery.
      float humThreshold = 0.1;                         // How big a humidity difference has to minimally be before an update is sent. Makes the sensor less precise, but also less jittery, and can save battery.
      #define COMPARE_BARO 0                            // Send barometric pressure only if changed? 1 = Yes 0 = No. Can save battery.
      float presThreshold = 0.1;                        // How big a barometric difference has to minimally be before an update is sent. Makes the sensor less precise, but also less jittery, and can save battery.
                  
      
      // VARIABLES YOU PROBABLY SHOULDN'T CHANGE
      #define TEMP_CHILD_ID 1        // for MySensors. Within this node each sensortype should have its own ID number.
      #define HUM_CHILD_ID 2        // for MySensors. Within this node each sensortype should have its own ID number.
      #define BARO_CHILD_ID 3       // for MySensors. Within this node each sensortype should have its own ID number.
      float lastTemperature = -1;     // Stores the previous measurement, so it can be compared with a new measurement.
      float lastHumidity = -1;      // Stores the previous measurement, so it can be compared with a new measurement.
      float lastPressure = -1;      // Stores the previous measurement, so it can be compared with a new measurement.
      unsigned long BME280measurementSleepTime = 0;   // variable to store the calculated Sleep time if the node is battery powered.
      bool metric = true;       // Variable that stores if the sensor will output the temperature in Fahrenheit of Celsius. The gateway sends this preference to the node, so you dont need to change it here.
      bool receivedConfig = false;      // The MySensors gateway will tell the node if it should output in metric or not.
      
      // MYSENSORS COMMUNICATION VARIABLES
      MyMessage temperatureMsg(TEMP_CHILD_ID, V_TEMP);
      MyMessage humidityMsg(HUM_CHILD_ID, V_HUM);
      MyMessage pressureMsg(BARO_CHILD_ID, V_PRESSURE);
      #ifdef GENERATE_FORECAST
      MyMessage forecastMsg(BARO_CHILD_ID, V_FORECAST);
      #endif
      
      Adafruit_BME280 bme;         //I2C
      
      void setup() {
        Wire.begin(); // Wire.begin(sda, scl) // starts the wire communication protocol, used to chat with the BME280 sensor.
        Serial.begin(115200); // for serial debugging over USB.
        Serial.println("Hello world, I am a Gateway with sensor.");
      }
      
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Gateway_with_Sensor", "1.1");
      
        // Tell the MySensors gateway what kind of sensors this node has, and what their ID's on the node are, as defined in the code above.
        present(BARO_CHILD_ID, S_BARO);
        present(TEMP_CHILD_ID, S_TEMP);
        present(HUM_CHILD_ID, S_HUM);
      }
      
      
      void loop() {
      
        // You should not change these variables:
        static unsigned long previousBME280Millis = 0;  // Used to remember the time that the BME280 sensor was asked for a measurement.
        unsigned long currentMillis = millis();         // The time since the sensor started, counted in milliseconds. This script tries to avoid using the Sleep function, so that it could at the same time be a MySensors repeater.
        static boolean BME280shouldAsk = true;          // This is true when the time is right for a new measurement to be made.
        static boolean BME280justAsked = false;         // This indicates whether we have just asked the sensor module for a measurement, so the receiving part of the code (part 2) should be primed. This two-part construction helps to bridge the time where the BME280 module is busy, without blocking the entire node from doing anything else (like being a repeater, or working with other connected sensor modules).
      
      
        // PART 1. If enough time has passed, a new measurement should be taken:
        if (BME280shouldAsk == true && currentMillis - previousBME280Millis >= BME280measurementInterval) {
          previousBME280Millis = currentMillis; // store the current time as the previous measurement start time.
          BME280shouldAsk = false;
          Serial.println("");
          Serial.println("BME280 - Requesting new data from sensor module.");
      //    bme.readCoefficients();             // Read NVM compensation parameters
      //    BME280.readCompensationParams();    // Need to read the NVM compensation parameters.
      
          // Normal mode for regular automatic samples
          Serial.println("Just before setSampling");
          bme.setSampling(Adafruit_BME280::MODE_NORMAL,       //normal mode
                          Adafruit_BME280::SAMPLING_X8,       //temperature x8
                          Adafruit_BME280::SAMPLING_X16,      //pressure x16
                          Adafruit_BME280::SAMPLING_X8,       //humidity x8
                          Adafruit_BME280::FILTER_OFF,        //IIR Filter coefficient
                          Adafruit_BME280::STANDBY_MS_0_5);   //tsb = 0.5ms
      //    BME280.writeStandbyTime(tsb_0p5ms);         // tsb = 0.5ms
      //    BME280.writeFilterCoefficient(fc_off);       // IIR Filter coefficient 16
      //    BME280.writeOversamplingPressure(os1x);    // pressure x16
      //    BME280.writeOversamplingTemperature(os1x);  // temperature x8
      //    BME280.writeOversamplingHumidity(os1x);     // humidity x8
      //    BME280.writeMode(smNormal);
      
          // As we exit part 1, in theory BME280.isMeasuring() should now be true.
          Serial.println("Just after setSampling");
          BME280justAsked = true;   
        }
      
      
        // Part 2. This will trigger if the sensor has just been asked for a measurement, and is also just done figuring out those measurements.
      //  if(BME280justAsked == true && BME280.isMeasuring() == false) { // 
      Serial.println("Just before isMeasuring");
        if(BME280justAsked == true && bme.isMeasuring() == false) { // 
          Serial.println("After isMeasuring");
          BME280justAsked = false; // makes sure we don't do this part again in the next pass through the main loop.
          Serial.println("BME280 - Sensor module has some new values ready:");
            
          // Read out the data - must do this before calling the getxxxxx routines
      
          float temperature = bme.readTemperature();                    // Must get the temperature first.
          float humidity = bme.readHumidity();        // Get the humidity.
          float pressure_local = bme.readPressure();                    // Get pressure at current location
      //    float temperature = BME280.getTemperatureMostAccurate();                    // Must get the temperature first.
      //    float humidity = BME280.getHumidityMostAccurate();        // Get the humidity.
      //    float pressure_local = BME280.getPressureMostAccurate();                    // Get pressure at current location
          float pressure = pressure_local/pow((1.0 - ( ALTITUDE / 44330.0 )), 5.255); // Adjust to sea level pressure using user altitude
      
          // Now, let's send the measurements to the gateway.
      
          // Send temperature
          if (COMPARE_TEMP == 1 && abs(temperature - lastTemperature) < tempThreshold) { // is the temperature difference bigger than the threshold?
            Serial.print(temperature - lastTemperature);
            Serial.print("- BME280 - Temperature difference too small, so not sending the new measurement to the gateway.\n");
          } else {
            Serial.print("BME280 - Sending the new temperature to the gateway.\n");
            send(temperatureMsg.set(temperature, 1));
            lastTemperature = temperature; // Save new temperatures to be able to compare in the next round.
          } 
      
          // Send humidity
          if (COMPARE_HUM == 1 && abs(humidity - lastHumidity) < humThreshold) { // is the humidity difference bigger than the threshold?
            Serial.print(humidity - lastHumidity);
            Serial.println("- BME280 - Humidity difference too small, so not sending the new measurement to the gateway.");
          } else {
            Serial.println("BME280 - Sending the new humidity to the gateway.");
            send(humidityMsg.set(humidity, 1));
            lastHumidity = humidity; // Save new humidity to be able to compare in the next round.
          }
      
          // Send pressure
          if (COMPARE_BARO == 1 && abs(pressure - lastPressure) < presThreshold) { // is the pressure difference bigger than the threshold?
            Serial.print(pressure - lastPressure);
            Serial.println("- BME280 - Pressure difference too small, so not sending the new measurement to the gateway.");
          } else {
            Serial.println("BME280 - Sending the new pressure to the gateway.");
            send(pressureMsg.set(pressure, 1));
            lastPressure = pressure; // Save new pressure to be able to compare in the next round.
          }
          Serial.println("BME280 - Measurement complete. Going to wait until next measurement.");
          BME280shouldAsk = true; // Ready for the new round.
        }
      }
      
      

      Some of the Serial.println are for debugging purposes to find where the code is crashing... 🙂

      Not sure if I should have a static node ID for the gateway. If so, it would probably be ID 1.
      The various usernames and passwords, etc. are included in the secrets.h-file, which I think should have been default with MySensors.

      posted in Development
      Stig
      Stig
    • GatewayESP32MQTT with local sensor crashes

      Hi, all.

      I'm not a programmer and new to MySensors, so my problem may be something silly.

      My plan is to, eventually, get a network of, mostly, temperature nodes using some Rigado BMD-300 modules (nRF52832-based) with an ESP32 (Wemos Lolin32 / NRF24) running as a MQTT gateway.

      I'm starting with trying to get the gateway up and running, with a local BME280 sensor. I've used GatewayESP32MQTTClient as a starting point and added code from the MySensors BME280 sketch. The sketch was using a library which seems to not be available in PlatformIO, so I've modified it to use Adafruit_BME280 library (modified with code from Sparkfun to get isMeasuring).

      My modifications to the BME280 library look like this
      Adafruit_BME280.h

      bool isMeasuring(void);
      

      Adafruit_BME280.cpp

      bool Adafruit_BME280::isMeasuring(void)	{
        uint8_t stat = read8(0xF3);
        return(stat & (1<<3));	//If measuring bit (3) is set, return true
      }
      

      When the gateway code and the BME280 code are combined, the gateway runs fine until a minute has passed and it want to do a sampling from the local sensor. It then crashes and reboots when it wants to set the parameters for the BME280, with the message "Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled."

      The code which caused the crash is

          bme.setSampling(Adafruit_BME280::MODE_NORMAL,       //normal mode
                          Adafruit_BME280::SAMPLING_X8,       //temperature x8
                          Adafruit_BME280::SAMPLING_X16,      //pressure x16
                          Adafruit_BME280::SAMPLING_X8,       //humidity x8
                          Adafruit_BME280::FILTER_OFF,        //IIR Filter coefficient
                          Adafruit_BME280::STANDBY_MS_0_5);   //tsb = 0.5ms
      
      

      When I comment out the above section, it crashes when it reaches the next instance where it accesses the Adafruit_BME280-library, so it looks like it doesn't like this library. Anyone else used the same library with success?

      Anyone who have any ideas where I've goofed up, other than using the Adafruit_BME280-library?

      posted in Development
      Stig
      Stig