Navigation

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

    Posts made by maddhin

    • Low power sketch burns batteries

      Hi Everybody,

      I built a temp/hum sensor based on the My Slim node (https://forum.mysensors.org/topic/2745/my-slim-2aa-battery-node?_=1664381788684).
      The first prototype I built is running perfectly for about 1 year now without any battery change.

      But then I started playing with the sketch as I want the battery to report the level. But my sketch seems to have an error somewhere as it seems to drain the batteries really fast. I cannot find the error.

      Can anybody spot the issue? It seems that either the battery level is published too often or the process of measureing the battery level is burning elctricity.

      The commented out part is something I tried but it didn't work.

      Any help is highly appreciated!!

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * v1.0: Yveaux
       * v1.01: Maddhin
       * v1.02: changed to Adafruit HTU21D library, minor bugs and updates
       * v1.03: first production version
       * v1.04: change debug serial.print handling, minor modifications
       * v1.05 29.12.2021: modifikations to battery reporting adding heartbeat battery reporting
       * v1.06 20.01.2022: revision to simple v4 battery reporting
       * 
       * DESCRIPTION
       * This sketch provides an example of how to implement a humidity/temperature
       * sensor using a HTU21D sensor.
       *  
       *   */
      
      #define SKETCH_NAME "TempSen_HTU21D_v6"     //<--------- UPDATE sketch name!!!
      #define SKETCH_VERSION "1.06"               //<--------- UPDATE version nummer!!!
      
      // Enable debug prints
      //#define MY_DEBUG                   //<--------- switch DEBUG mode on/off
      
      // Enable REPORT_BATTERY_LEVEL to measure battery level and send changes to gateway
      #define REPORT_BATTERY_LEVEL
      
      // Enable and select radio type attached 
      #define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      //#define MY_RS485
      
      #define MY_NODE_ID 105
      //#define MY_PARENT_NODE_ID 0
      //#define MY_PARENT_NODE_IS_STATIC
      //#define MY_RF24_PA_LEVEL RF24_PA_MAX
      
      #include <MySensors.h>  
      
      #define CHILD_ID_HUM  0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_VOLT 2
      
      static MyMessage msgHum( CHILD_ID_HUM,  V_HUM );      // Node humidity
      static MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);      // Node temperature
      static MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);   // Node voltage
      
      // Sleep time between sensor updates (in milliseconds)
      static const char SLEEP = 5;
      static const uint64_t UPDATE_INTERVAL = SLEEP*60000;      // x * 1 min
      //static const uint64_t UPDATE_INTERVAL = 5000;       //for debugging: 5s intervall
      
      #include "Adafruit_HTU21DF.h"
      Adafruit_HTU21DF sensor = Adafruit_HTU21DF();
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      #ifdef REPORT_BATTERY_LEVEL
        #include <Vcc.h>
        static uint8_t oldBatteryPcnt = 200;  // Initialize to 200 to assure first time value will be sent.
        const float VccMin        = 1.8;      // Minimum expected Vcc level, in Volts: Brownout at 1.8V    -> 0%
        const float VccMax        = 2.0*1.6;  // Maximum expected Vcc level, in Volts: 2xAA fresh Alkaline -> 100%
        const float VccCorrection = 1.03;      // Measured Vcc by multimeter divided by reported Vcc
        static Vcc vcc(VccCorrection); 
        int irtCounter = 0;
        #define BATTERY_REPORT_BY_IRT_CYCLE 24*60/SLEEP  // Make a battery report after this many trips. Here once per day = 24h * 60min / update interval (ms) / 60000ms (calc in minutes)
      #endif
      
      #ifdef MY_DEBUG
       #define DEBUG_PRINT(x)    Serial.print (x)
       #define DEBUG_PRINTDEC(x) Serial.print (x, DEC)
       #define DEBUG_PRINTLN(x)  Serial.println (x)
      #else
       #define DEBUG_PRINT(x)
       #define DEBUG_PRINTDEC(x)
       #define DEBUG_PRINTLN(x)
      #endif
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway and Controller
        DEBUG_PRINT("SKETCH NAME: "); 
        DEBUG_PRINT(SKETCH_NAME);
        DEBUG_PRINT(", VERSION: ");
        DEBUG_PRINTLN(SKETCH_VERSION); 
        
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
        //show reporting cycles until battery report is triggered
        DEBUG_PRINT("Battery reporting cycles: "); 
        DEBUG_PRINTLN(BATTERY_REPORT_BY_IRT_CYCLE);
        
        // Present sensors as children to gateway
        present(CHILD_ID_HUM, S_HUM,   "Humidity");
        present(CHILD_ID_TEMP, S_TEMP, "Temperature");
        present(CHILD_ID_VOLT, S_MULTIMETER, "Voltage");
      }
      
      void setup()
      {
        while (!sensor.begin())
        {
          DEBUG_PRINTLN(F("Sensor not detected!"));
          while(1);
          delay(5000);
        }
      }
      
      
      void loop()      
      {  
        // Read temperature & humidity from sensor.
          const float temperature = float( sensor.readTemperature() );
          const float humidity    = float( sensor.readHumidity() );
      
          DEBUG_PRINT(F("Temp "));
          DEBUG_PRINT(temperature);
          DEBUG_PRINT(F("\tHum "));
          DEBUG_PRINTLN(humidity);
      
          send(msgTemp.set(temperature, 1));
          send(msgHum.set(humidity, 1));
      
        // Battery Reporting
        #ifdef REPORT_BATTERY_LEVEL
          const uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax));
      
          DEBUG_PRINT(F("Vbat "));
          DEBUG_PRINT(vcc.Read_Volts());
          DEBUG_PRINT(F("\tPerc "));
          DEBUG_PRINTLN(batteryPcnt);
      
      //    irtCounter++;
      //    // Battery readout should only go down. So report only when new value is smaller than previous one.
      //    if ( batteryPcnt < oldBatteryPcnt )
      //    {
      //      send(msgVolt.set(vcc.Read_Volts(),2));
      //      sendBatteryLevel(batteryPcnt);
      //      oldBatteryPcnt = batteryPcnt;
      //      irtCounter=0;
      //    }
      //    // Report battery in intervals (typically every 24h)
      //    else {
      //      if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
      //      irtCounter=0;
      //      send(msgVolt.set(vcc.Read_Volts(),2));
      //      sendBatteryLevel(batteryPcnt);
      //    }
      //    }
          // Battery readout should only go down. So report only when new value is smaller than previous one.
          if ( batteryPcnt < oldBatteryPcnt )
          {
            send(msgVolt.set(vcc.Read_Volts(),2));
            sendBatteryLevel(batteryPcnt);
            oldBatteryPcnt = batteryPcnt;
          }
          #endif
      
        // Sleep until next update to save energy
          sleep(UPDATE_INTERVAL); 
      }
      
      posted in Development
      maddhin
      maddhin
    • Outdoor (neg temp) sensor for battery power project

      Hi,

      I have successfully built temp sensors based on "my slim node" here in the forum (2xAA battery, ATMega328P, NRF24l01). I love these little things!

      But now I would like to build a sensor for outdoors to measure the outside temperature. And fail. All of the usual suspects like HTU21D cannot measure temperatures below 0. Then there is the Dallas D18B20, which can do below 0 but needs 3+V to operate.

      How would you solve this? Go with the D18B20 and use a booster? Or is there another sensor I missed?

      Any input is much appreciated!

      posted in General Discussion
      maddhin
      maddhin
    • RE: 💬 Building a WiFi Gateway using ESP8266

      Hi,
      I would like to add sendSketchInfo to my gateway.
      I added

      const char* sketch_name = "GatewayESP8266OTA_v3";
      const char* rev = "1.01";

      at the beginning of the sketch and

      sendSketchInfo(sketch_name, rev);

      in the presentation part.

      but this doesn't seem to work. Am I doing anything wrong? Any suggestion on how to do it right? Many thanks in advance!

      posted in Announcements
      maddhin
      maddhin
    • RE: can't get D1 mini gateway sketch to work

      I fixed the issue by using the ESP8266 2.7.4 board software and installing https://github.com/espressif/esptool/archive/v3.0.zip and https://github.com/pyserial/pyserial/archive/v3.4.zip and replacing the esptool and pyserial folders in ~/Library/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/

      If anybody has a fix for 3.0.2, it would be very much welcome!

      posted in Troubleshooting
      maddhin
      maddhin
    • RE: can't get D1 mini gateway sketch to work

      I did more googling and think it has something to do with the MacOS Big Sur and Arduino v3 of the ESP8266 board software do not play together with mysensors. I'm currently try to find a fix.

      The sketch is literally the original sktech with my wifi / IP settings. A number of other original mysensors sketches are also not working, so it seems a mysensor issue.

      posted in Troubleshooting
      maddhin
      maddhin
    • can't get D1 mini gateway sketch to work

      Hi,

      I have an embarrassing question:

      I have a D1 mini with RF24 radio. The gateway (and sketch) worked fine in the past but as I moved apartments and switched routers, I have to upload a revised sketch in order to change the wifi settings.

      Sadly, I also switched laptops and changed to a Mac and have Arduino freshly installed now. I installed the ESP8266 boards and the mysensors library.

      Now, for some reason, the mysensors OTA Gateway sketch uploads but "nothing happens". I.e. the serial monitor stays blank (except for the gibberish that comes from restarting the D1 mini). I checked the baud rate and I checked the wifi but no new device appears. Strange.

      I uploaded a few other sketches like blink or the wifi scanner and those sketches work fine on the same D1 mini...

      Does anybody have an idea what I am doing wrong or what I forgot? This drives me crazy...

      Any help is much appreciated!!!

      posted in Troubleshooting
      maddhin
      maddhin
    • RE: Which magnetic door/window switch for battery powered projects?

      @skywatch said in Which magnetic door/window switch for battery powered projects?:

      @maddhin You attach the 'large resistor' on the ATmega board from ground to input pin used for interrupt. Then connect the same input pin to 3V via the reed relay switch contacts that are OPEN when the door/window/letterbox is in the untripped (closed) position. If you use the sketch on here you need to reverse the tripped/untripped (open/closed) as the basic sketch is negative triggered and this way it is positive triggered -

      sorry, it took me a while to get back to this project as finally all parts for my slim nodes arrived and I first had to tinker with the temp sensor:)

      The NC door switch is working now - although I did connect the large resistor with VCC and pin and connected the switch with pin and GND. The other way around didn't seem to work for me.

      Here is my sketch for other people having similar issue or for comments (improvements always welcome!).

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
      *******************************
       * 
       * DESCRIPTION
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND.
       * http://www.mysensors.org/build/binary
       * 
       * Connect normally closed (NC) door sensor:
       * VCC <--> 3.3M ohm resistor <--> pin D3
       * GND <--> NC door sensor <--> pin D3
       * REVISION HISTORY
       * v1.0: Example at https://www.mysensors.org/build/binary
       * v1.01: Maddhin
       * v1.03: first working version
       * 
       */ 
       
      
      #define SKETCH_NAME "DoorSen_NC"
      #define SKETCH_VERSION "1.03"        //<--------- UPDATE version nummer!!!
      
      // Enable debug prints
      #define MY_DEBUG                   //<--------- switch DEBUG mode on/off
      
      // Enable REPORT_BATTERY_LEVEL to measure battery level and send changes to gateway
      #define REPORT_BATTERY_LEVEL
      
      // Enable and select radio type attached 
      #define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      //#define MY_RS485
      
      #define MY_NODE_ID 101
      //#define MY_PARENT_NODE_ID 0
      //#define MY_PARENT_NODE_IS_STATIC
      //#define MY_RF24_PA_LEVEL RF24_PA_MAX
      
      #include <MySensors.h>  
      //#include <Bounce2.h>  
      
      //#define CHILD_ID_HUM  0
      //#define CHILD_ID_TEMP 1
      #define CHILD_ID_VOLT 2
      
      //Door sensor
      #define CHILD_ID_DOOR 3
      #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
      #define ONE_DAY_SLEEP_TIME  86400000  // report battery status each day at least once
      //Bounce debouncer = Bounce(); 
      int oldValue=-1;
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID_DOOR,V_TRIPPED);
      
      
      // Sleep time between sensor updates (in milliseconds)
      static const uint64_t UPDATE_INTERVAL = 5*60000; // x * 1 min
      //for debugging:
      //static const uint64_t UPDATE_INTERVAL = 5000;
      
      /*#include "Adafruit_HTU21DF.h"
      Adafruit_HTU21DF sensor = Adafruit_HTU21DF();
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      */
      
      #ifdef REPORT_BATTERY_LEVEL
      #include <Vcc.h>
      static uint8_t oldBatteryPcnt = 200;  // Initialize to 200 to assure first time value will be sent.
      const float VccMin        = 1.8;      // Minimum expected Vcc level, in Volts: Brownout at 1.8V    -> 0%
      const float VccMax        = 2.0*1.6;  // Maximum expected Vcc level, in Volts: 2xAA fresh Alkaline -> 100%
      const float VccCorrection = 1.0;      // Measured Vcc by multimeter divided by reported Vcc
      static Vcc vcc(VccCorrection); 
      #endif
      
      #ifdef MY_DEBUG
       #define DEBUG_PRINT(x)    Serial.print (x)
       #define DEBUG_PRINTDEC(x) Serial.print (x, DEC)
       #define DEBUG_PRINTLN(x)  Serial.println (x)
      #else
       #define DEBUG_PRINT(x)
       #define DEBUG_PRINTDEC(x)
       #define DEBUG_PRINTLN(x)
      #endif
      
      
      
      void setup()
      {
        
        /*// Temp Hum Sensor
        while (!sensor.begin())
        {
          DEBUG_PRINTLN(F("Sensor not detected!"));
          while(1);
          delay(5000);
        }*/
      
        //Door Sensor
        // Setup the button
        pinMode(BUTTON_PIN,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN,HIGH);
        
        /*// After setting up the button, setup debouncer
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);
        */
      }
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway and Controller
        DEBUG_PRINT("SKETCH NAME: "); 
        DEBUG_PRINT(SKETCH_NAME);
        DEBUG_PRINT(", VERSION: ");
        DEBUG_PRINTLN(SKETCH_VERSION); 
        
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        
        // Present sensors as children to gateway
        //present(CHILD_ID_HUM, S_HUM,   "Humidity");
        //present(CHILD_ID_TEMP, S_TEMP, "Temperature");
        present(CHILD_ID_VOLT, S_MULTIMETER, "Voltage");
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        present(CHILD_ID_DOOR, S_DOOR);  
      }
      
      void loop()      
      {  
        /*// Read temperature & humidity from sensor.
        const float temperature = float( sensor.readTemperature() );
        const float humidity    = float( sensor.readHumidity() );
      
        DEBUG_PRINT(F("Temp "));
        DEBUG_PRINT(temperature);
        DEBUG_PRINT(F("\tHum "));
        DEBUG_PRINTLN(humidity);
      
        static MyMessage msgHum( CHILD_ID_HUM,  V_HUM );
        static MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
        send(msgTemp.set(temperature, 1));
        send(msgHum.set(humidity, 1));
      */
      
        //Door sensor
        /* debouncer.update();
        // Get the update value
        int value = debouncer.read();
        */
        int value = digitalRead(BUTTON_PIN);
        //DEBUG_PRINT("digitalRead PIN: ");
        //DEBUG_PRINTLN(value);
        wait(50); // "debouncing"
        //if (value != oldValue) {
        if (value != oldValue) { 
           // Send in the new value
           DEBUG_PRINT(F("DOOR SENSOR: "));
           DEBUG_PRINTLN(value==HIGH ? 1 : 0);
           send(msg.set(value==HIGH ? 1 : 0));
           oldValue = value;
        }
      
      #ifdef REPORT_BATTERY_LEVEL
        const uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax));
        
        static MyMessage MsgVolt(CHILD_ID_VOLT, V_VOLTAGE);  // Node voltage
      
        DEBUG_PRINT(F("Vbat "));
        DEBUG_PRINT(vcc.Read_Volts());
        DEBUG_PRINT(F("\tPerc "));
        DEBUG_PRINTLN(batteryPcnt);
      
      
        // Battery readout should only go down. So report only when new value is smaller than previous one.
        if ( batteryPcnt < oldBatteryPcnt )
        {
            send(MsgVolt.set(vcc.Read_Volts(),2));
            sendBatteryLevel(batteryPcnt);
            oldBatteryPcnt = batteryPcnt;
        }
        #endif
      
        // Sleep until next update to save energy
        //sleep(UPDATE_INTERVAL); 
        sleep(BUTTON_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
      }
      

      Now, I'll look into adding a second door switch onto the same 328P and hope I have a neat letterbox sensor up and running soon...

      Power consumption I will have to monitor though. But I don't really know how to measure the sleep / send current. I guess I should build some INA219 based monitor or similar. I guess, for the moment, I just "hope" the setup is good and I'll see how long the batteries will last. After running for ~24h and having triggered a bunch of times, the voltage didn't seem to have changed, so I guess that is good news... 🙂

      Thanks for your help, guys!

      posted in Hardware
      maddhin
      maddhin
    • RE: My Slim 2AA Battery Node

      Hi,

      this is an awesome project and after waiting for weeks to get all parts, I finally started building.

      The problem I am facing is that it seems that I cannot get the board working if I use such a 8-pin connector socket. I am generally OK with NOT using such a socket for sensors that "go into production" but for some sensors where space is not an issue or for boards which I want to use for testing different NRF24s etc, I would like to make the socket work.

      Does anybody have any tipps on how to make the radio reliably work with a socket? That would be awesome!

      posted in My Project
      maddhin
      maddhin
    • RE: HTU21D Humidity/Temperature Sensor

      Hi, I have built a Slim Node (see https://forum.mysensors.org/topic/3049/slim-node-si7021-sensor-example/137?_=1619862122302) but it seems most of the sketch examples here do not work with mysensors.h (I think the v2 of MySensors).
      Does anybody have a working sketch for mysensors.h for the HTU21D with battery monitoring?

      Alternatively: can anybody point me in the right direction on how to "convert" v1 skteches to v2?

      Thanks a bunch!

      posted in Hardware
      maddhin
      maddhin
    • RE: while (!sensor.begin()) error

      @BearWithBeard said in while (!sensor.begin()) error:

      In other words: SparkFun doesn't test if the sensor has been initialized properly, so you can't either.

      awesome answer, @BearWithBeard!! This explains everything and this makes a whole lot of sense. I guess I need to further up my programming skills/understanding 😉 Thank you so much!

      posted in Troubleshooting
      maddhin
      maddhin
    • RE: while (!sensor.begin()) error

      @Yveaux said in while (!sensor.begin()) error:

      @maddhin you need to pass a Wire instance in the call to begin(). Search the net for an example.

      I did some rearching but I think the problem is that I don't really understand what that means 🙂

      I tried adjusting the code close to the official Sparkfun example code with include wire.h etc. but that didn't work either.

      #include <Wire.h>
      #include "SparkFunHTU21D.h"
      
      //Create an instance of the object
      HTU21D myHumidity;
      
      void setup()
      {
        Serial.begin(9600);
        Serial.println("HTU21D Example!");
      
        myHumidity.begin();
      }
      

      I'll search some more tomorrow but, I guess, I leave out the while/if as this seems to be too complicated for a "simple" error handler 🙂

      posted in Troubleshooting
      maddhin
      maddhin
    • while (!sensor.begin()) error

      Hi,

      I'm sorry, this must be a really stupid question to most of you but I failed to get a solution elsewhere:(

      I try to run this sketch

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0: Yveaux
       * 
       * DESCRIPTION
       * This sketch provides an example of how to implement a humidity/temperature
       * sensor using a HTU21D sensor.
       *  
       * 
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable REPORT_BATTERY_LEVEL to measure battery level and send changes to gateway
      //#define REPORT_BATTERY_LEVEL
      
      // Enable and select radio type attached 
      #define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      //#define MY_RS485
      
      #include <MySensors.h>  
      
      #define CHILD_ID_HUM  0
      #define CHILD_ID_TEMP 1
      
      static bool metric = true;
      
      // Sleep time between sensor updates (in milliseconds)
      //static const uint64_t UPDATE_INTERVAL = 60000;
      //for debugging:
      static const uint64_t UPDATE_INTERVAL = 5000;
      
      #include <SparkFunHTU21D.h>
      static HTU21D sensor;
      
      #ifdef REPORT_BATTERY_LEVEL
      #include <Vcc.h>
      static uint8_t oldBatteryPcnt = 200;  // Initialize to 200 to assure first time value will be sent.
      const float VccMin        = 1.8;      // Minimum expected Vcc level, in Volts: Brownout at 1.8V    -> 0%
      const float VccMax        = 2.0*1.6;  // Maximum expected Vcc level, in Volts: 2xAA fresh Alkaline -> 100%
      const float VccCorrection = 1.0;      // Measured Vcc by multimeter divided by reported Vcc
      static Vcc vcc(VccCorrection); 
      #endif
      
      void presentation()  
      { 
        // Send the sketch info to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.0");
      
        // Present sensors as children to gateway
        present(CHILD_ID_HUM, S_HUM,   "Humidity");
        present(CHILD_ID_TEMP, S_TEMP, "Temperature");
      
        //metric = getControllerConfig().isMetric; //Erase later
      }
      
      void setup()
      {
        while (!sensor.begin())
        {
          Serial.println(F("Sensor not detected!"));
          delay(5000);
        }
      }
      
      
      void loop()      
      {  
        // Read temperature & humidity from sensor.
        const float temperature = float( sensor.readTemperature() ) / 100.0;
        const float humidity    = float( sensor.readHumidity() ) / 100.0;
      
      #ifdef MY_DEBUG
        Serial.print(F("Temp "));
        Serial.print(temperature);
        Serial.print(metric ? 'C' : 'F');
        Serial.print(F("\tHum "));
        Serial.println(humidity);
      #endif
      
        static MyMessage msgHum( CHILD_ID_HUM,  V_HUM );
        static MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
        send(msgTemp.set(temperature, 2));
        send(msgHum.set(humidity, 2));
      
      #ifdef REPORT_BATTERY_LEVEL
        const uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax));
      
      #ifdef MY_DEBUG
        Serial.print(F("Vbat "));
        Serial.print(vcc.Read_Volts());
        Serial.print(F("\tPerc "));
        Serial.println(batteryPcnt);
      #endif
      
        // Battery readout should only go down. So report only when new value is smaller than previous one.
        if ( batteryPcnt < oldBatteryPcnt )
        {
            sendBatteryLevel(batteryPcnt);
            oldBatteryPcnt = batteryPcnt;
        }
      #endif
      
        // Sleep until next update to save energy
        sleep(UPDATE_INTERVAL); 
      }
      

      but the compiler always complains about this line:

        while (!sensor.begin())
        {
          Serial.println(F("Sensor not detected!"));
          delay(5000);
        }
      

      it says:

      D:\XX\Mysensors\TempSen_HTU21D\TempSen_HTU21D.ino: In function 'void setup()':
      TempSen_HTU21D:89:24: error: could not convert 'sensor.HTU21D::begin((* & Wire))' from 'void' to 'bool'
         while (!sensor.begin())
                              ^
      TempSen_HTU21D:89:24: error: in argument to unary !
      
      

      Does anybody know where the problem is? I also tried IF and all kinds of other stuff but it seems the problem is actually not this line but some other issue...

      I'd be super glad if anybody can point me in the right direction...

      posted in Troubleshooting
      maddhin
      maddhin
    • RE: Wemos Di Mini v3 not connecting to wifi but classic D1 Mini does...

      it seems like I got a bad batch of D1 Mini v3.0.0s. I ran the sample wifi connect and wifi scan sketches on all 5 purchased boards and all had issues connecting or showing all/most available wifis. One was plain broken and wouldn't even cooperate with Win10... Some Wemos D1 Mini v2 and PROs ran the same sketches just fine. So it seems to be a manufacturer error rather than a problem with the v3 of the D1 Mini...
      So, if you have the choice, stick with the v2 "classic" D1 Mini. Although I didn't buy from a dodgy source, there still seem to be issues with producing the new versions reliably...

      posted in Troubleshooting
      maddhin
      maddhin
    • Wemos Di Mini v3 not connecting to wifi but classic D1 Mini does...

      Hi,

      I built a gateway with a Wemos D1 Mini "Classic" - and everything works well.

      But now I flashed the exacty same code on a new Wemos D1 Mini v3.0.0 and I always get the message "cannot find network XXX" (I am paraphrasing) and the gateway is not working. I tried this on 2 new v3 D1 Minis with same result.

      Did anybody experience anything like this? Is there an issue with the v3 D1 Minis? Is there any change in the code necessary? I did some research but I could not find anything particular why the D1 Mini v3 should need different code than the D1 Mini "Classic"

      Any help would be greatly appreciated!!!

      posted in Troubleshooting
      maddhin
      maddhin
    • RE: Which magnetic door/window switch for battery powered projects?

      @skywatch awesome! Once all my parts arrive, I'll test as well! I'm planning a letterbox sensor, so usage will be minimal (1-3 events a day), hence my concern with the power consumption NO vs. NC. But if battery life (out of 2 x AA) is 2 years+, it shall be ok 🙂
      I guess, I just need to build and test...
      One issue I'll be facing is that the cable between ATMEGA328P and the sensor will be 50-60cm. I read that this could cause issues with the large resistor method:(

      posted in Hardware
      maddhin
      maddhin
    • RE: Which magnetic door/window switch for battery powered projects?

      @skywatch said in Which magnetic door/window switch for battery powered projects?:

      @maddhin You need to look for "changeover reed relay" - they are cheap and allow you to reverse the logic in the door/window sketch and get a much longer battery life.

      Awesome, thank you for this. I came across those switches but I would find it troublesome to install them if I can find ready-to-install sets for similar price.

      I found a useful answer over at stackexchange, where they recommend your and @Richard_Ske's solution as well: connect Vcc with a large resistor (3.3MOhm) and input pin and input pin/resistor with switch and grd. According to that post, the power consumption is not much higher than a NO setup.

      Would that be about right? You write "much longer battery life" for NO setup. If there is a large difference in power consumption, I would go and try to find NO switches, which exist, but are significantly more expensive (relatively speaking). It is very hard for me to judge this as my skills are limited. I would love to operate a bunch of SlimNodes with 2 x AA batteries.

      posted in Hardware
      maddhin
      maddhin
    • Which magnetic door/window switch for battery powered projects?

      Hi,
      I am new to MySensors and planning to build battery powered window/door sensors based on a "raw" ATMEGA328P with 2xAA batteries.

      I am opting for the usual, cheap white Ali door switches (e.g. https://www.aliexpress.com/item/32255861885.html?spm=a2g0o.productlist.0.0.29ec3a95TEE6We&algo_pvid=48234541-eff1-4f39-96ee-284b1da18796&algo_expid=48234541-eff1-4f39-96ee-284b1da18796-1&btsid=2100bde316181377232332753e08a1&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_).

      But the thing confusing me is the "Normally Closed"/NC and "normally open" /NO.

      In my understanding NC means that the circuit is closed = current can flow. So for a battery project I think it is best to use NO switches, which only connect when the door/window is opened and therefore wake up the sensor to send a message.

      But, NO switches seem to be hard to come by at Ali.

      Am I missing something or do I misunderstand something? What would be the best setup for a battery powered project?

      posted in Hardware
      maddhin
      maddhin