Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
T

Tommas

@Tommas
About
Posts
93
Topics
17
Shares
0
Groups
0
Followers
0
Following
1

Posts

Recent Best Controversial

  • 💬 USB RF Gateway
    T Tommas

    Could i buy it assembled?

    OpenHardware.io usb rfm69 nrf24 gateway dfu stm32 usb device

  • Raspberry as mysensors gateway connection refused
    T Tommas

    Ok. Sorry. Working
    --my-transport=rf24 --my-gateway=ethernet --my-port=5003 --my-gateway=ethernet

    Troubleshooting

  • Raspberry as mysensors gateway connection refused
    T Tommas

    Hi,

    I follow the instruction but i got
    Sep 01 15:26:49 DEBUG GWT:TPS:ETH OK
    Sep 01 15:26:49 ERROR connect: Connection refused
    Sep 01 15:26:49 ERROR failed to connect
    Sep 01 15:26:49 DEBUG GWT:TPS:ETH OK
    Sep 01 15:26:49 ERROR connect: Connection refused
    Sep 01 15:26:49 ERROR failed to connect
    Sep 01 15:26:49 DEBUG GWT:TPS:ETH OK
    Sep 01 15:26:49 ERROR connect: Connection refused
    Sep 01 15:26:49 ERROR failed to connect
    Sep 01 15:26:49 DEBUG GWT:TPS:ETH OK
    Sep 01 15:26:49 ERROR connect: Connection refused
    Sep 01 15:26:49 ERROR failed to connect
    Sep 01 15:26:49 DEBUG GWT:TPS:ETH OK

    error.
    The configuration was:
    ./configure --my-transport=rf24 --my-gateway=ethernet --my-controller-url-address=xxx.xxx.xxx.xxx

    My controller is a VM and it has worked with an arduino gateway, but that go wrong, and i thought i try to use my rpi3 as an ethernet gateway. I connected the nrf24l01+ /pa/lna to it (5v, but i use an adapter for it such like this https://www.addicore.com/1x-nRF24L01-Adapter-p/ad279.htm )

    please help

    Troubleshooting

  • WakeOnLan over nrf24 radio
    T Tommas

    Hi!

    I would like to wake up my pc over lan.
    I thought that i make an arduino node with nrf24l01 and a ethernet w5100 to wake up my pc.
    I need a sketch for it.
    Does Anybody have it?

    Thanks
    T

    Development

  • Child X not present in node X
    T Tommas

    Dear All!

    I dont know what might be the problem.
    Openhab2 2.4.0
    Mysensors 2.3.0 binding
    All other nodes are OK except my NoDE 3. Previously it had been OK until I upgraded to openhab2 2.3 , but Im not sure that the upgrade the main problem.
    Please give me suggestion what should i try to fix this issue.

    Message from gateway received: 3;1;1;0;0;5.2
    2018-07-06 19:58:24.834 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Node 3 found in gateway
    2018-07-06 19:58:24.834 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Child 1 not present in node 3
    2018-07-06 19:58:24.845 [DEBUG] [rsAbstractConnection$MySensorsReader] - Message from gateway received: 3;2;1;0;1;69
    2018-07-06 19:58:24.845 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Node 3 found in gateway
    2018-07-06 19:58:24.845 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Child 2 not present in node 3
    

    Thanks in advance,
    Tamás

    OpenHAB

  • All things unitialized after upgrade openhab 2.3.0-snapshot
    T Tommas

    @tommas

    It seems to work with the older mysensors binding:
    org.openhab.binding.mysensors-2.2.0-SNAPSHOT.jar .

    3 of my 5 nodes updated the values in openhab2 (2.3.0~20180331153334-1)

    OpenHAB

  • All things unitialized after upgrade openhab 2.3.0-snapshot
    T Tommas

    @tommas

    I think this issue is almost the same:
    https://www.bountysource.com/issues/56097209-rfxcom-working-oh2-setup-stopped-working-after-reboot

    OpenHAB

  • All things unitialized after upgrade openhab 2.3.0-snapshot
    T Tommas

    Dear All!

    I updated openhab2 2.3.0 previous build (via apt-get) to 2.3.0-SNAPSHOT Build #1246 . 2.3.0~20180331153334-1
    Except one of my node the nodes values arent updated on the sitemap, and arent written to the database, but in the openhab log I see the sent values, but:
    Child X not present in node Y

    Another problem on the paperui:
    My mysensor ethernet gateway status on things page:
    Status: UNINITIALIZED - HANDLER_INITIALIZING_ERROR Unresolved compilation problems: The type org.eclipse.jdt.annotation.Nullable cannot be resolved. It is indirectly referenced from required .class files The type org.eclipse.jdt.annotation.NonNullByDefault cannot be resolved. It is indirectly referenced from required .class files .

    The strange is that one of my node's values are updating...

    MY mysensors addon:
    org.openhab.binding.mysensors-2.3.0-SNAPSHOT.jar

    What might be the problem?

    Please help,

    OpenHAB

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @korttoma

    Thank you very much, and sorry....

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @gohan

    Ok! After the "loop ended " the node should go to sleep. On the console I see these lines:
    Loop ended
    62763 MCO:SLP:MS=300000,SMS=0,I1=255,M1=255,I2=255,M2=255
    62773 MCO:SLP:TPD

    What does it mean?

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @gohan said in Arduino mini pro 3.3 battery optimization code:

    loop

    What kind of sleep is it? There are parameters out there. ADC_OFF and some and some... Is this sleep turn off adc?

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @gohan said in Arduino mini pro 3.3 battery optimization code:

    LiFePo4 AA

    THank You! I will try!

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @tommas

    Should I use any other sleep "code"? How I know that the nrf24L01 go to sleep?

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @tommas

    I did a new code, and it seems that it is do the job.
    My goal was, that I only send the battery voltage (percent) when:
    At least one of sensor value transmission occured + The battery report time is elapsed.

    What do you think about my code? IT IS NOT ONLY MY CODE and it is not clear yet Thank for @gohan , @sundberg84 and mysensors for the base.

    /**
     * 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: Henrik EKblad
     * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
     * 
     * DESCRIPTION
     * This sketch provides an example of how to implement a humidity/temperature
     * sensor using a DHT11/DHT-22.
     *  
     * For more information, please visit:
     * http://www.mysensors.org/build/humidity
     * 
     */
    #define MY_NODE_ID 6
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached 
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    #include <MySensors.h>  
    #include <Wire.h>
    #include <SI7021.h>
    #include <SPI.h>
    #include <RunningAverage.h>
    #include <BH1750.h> //BH1750
    #include <Math.h>
    #define DEBUG
    
    #ifdef DEBUG
    #define DEBUG_SERIAL(x) Serial.begin(x)
    #define DEBUG_PRINT(x) Serial.print(x)
    #define DEBUG_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_SERIAL(x)
    #define DEBUG_PRINT(x) 
    #define DEBUG_PRINTLN(x) 
    #endif
    
    #define NODE_ID 6             // <<<<<<<<<<<<<<<<<<<<<<<<<<<   Enter Node_ID
    #define CHILD_ID_TEMP 0
    #define CHILD_ID_HUM 1
    #define CHILD_ID_LIGHT 2 //BH1750
    #define CHILD_ID_VBAT 254
    
    /*BATTERY*/
    // BATTERY MEASURER
    // VOLTAGE DIVIDER SETUP
    // 1M, 470K divider across battery and using internal ADC ref of 1.1V
    // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
    // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
    // 3.44/1023 = Volts per bit = 0.003363075
    #define VBAT_PER_BITS 0.003363075
    #define VMIN 2.1                                  //  Vmin (radio Min Volt)=1.9V (564v)
    #define VMAX 3.1                                  //  Vmax = (2xAA bat)=3.0V (892v)
    int batteryPcnt = 0;                              // Calc value for battery %
    int battAveragePcnt;
    int battSumPcnt = 0; 
    int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
    float VbatAverage=0;
    float VbatSum=0;
    //=========================
    /*BATTERY*/
    
    //#define SLEEP_TIME 180000   // 3 min
    //#define FORCE_TRANSMIT_CYCLE 10  // SLEEP_TIME*FORCE_TRANSMIT_CYCLE=Mindenképp küldi az értéket (Temp+HUM), különben akkor ha HUMI_TRANSMIT_THRESHOLD vagy TEMP_TRANSMIT_THRESHOLD igaz, 
    //#define BATT_MEASURE_CYCLE 10   // SLEEP_TIME/1000*BATTERY_Measure_CYCLE=Ennyi időnként Veszünk mintát (BATTERY)
    //#define BATT_REPORT_CYCLE 15   // SLEEP_TIME/1000*BATTERY_REPORT_CYCLE=Ennyi időnként küldi az értéket (BATTERY)
    #define SLEEP_TIME 300000   // 15sec
    #define FORCE_TRANSMIT_CYCLE 24  // 30sec SLEEP_TIME*FORCE_TRANSMIT_CYCLE=Mindenképp küldi az értéket (Temp+HUM), különben akkor ha HUMI_TRANSMIT_THRESHOLD vagy TEMP_TRANSMIT_THRESHOLD igaz, 
    #define BATT_MEASURE_CYCLE 2   // Hányszor vegyünk mintát a küldés előtt
    #define BATT_REPORT_CYCLE 60     // SLEEP_TIME/1000*BATTERY_REPORT_CYCLE*2=Ennyi időnként küldi az értéket (BATTERY)
    #define HUMI_TRANSMIT_THRESHOLD 3.0  // THRESHOLD tells how much the value should have changed since last time it was transmitted.
    #define TEMP_TRANSMIT_THRESHOLD 0.5
    #define LUX_TRANSMIT_THRESHOLD 10
    #define AVERAGES 2
    
    int measureCount = 0;
    int battreportCount=-2;
    float lastTemperature = -100;
    int lastHumidity = -100;
    int lastLux = 0; //BH1750
    boolean transmission_occured = false;
    RunningAverage raHum(AVERAGES);
    SI7021 humiditySensor;
    BH1750 lightSensor;
    
    //MySensor gw;
    MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP); // Initialize temperature message
    MyMessage msgHum(CHILD_ID_HUM,V_HUM);
    MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); //BH1750
    MyMessage msgVBat(CHILD_ID_VBAT, V_VOLTAGE); //BH1750
    
    
    void presentation(){
    
    sendSketchInfo("Node 6, Temp,Hum,Light", "1.1"); 
      present(CHILD_ID_TEMP, S_TEMP);   // Present sensor to controller
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); //BH1750
      present(CHILD_ID_VBAT, S_MULTIMETER); //BH1750
    }
    
    
    void setup() {
    
      DEBUG_SERIAL(115200);    
      DEBUG_PRINTLN("Serial started");
    
      delay(500); // Allow time for radio if power useed as reset
      
      raHum.clear();
      lightSensor.begin(); //BH1750
    
      
      /*BATTERY*/
       //=========================
      // BATTERY MEASURER
      //Set internal ref to internal to be able to measure bat 0-1v
      //Make sure this fits other sensors using analogRead()! 
      //If you have a sensor reporting 0-5v you need to change analogReference() before reading that sensor.
      
      analogReference(INTERNAL);
      //DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
      //INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
      //EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
      
      //Battery inital calc
      Serial.print("With Battery VMax (100%) = "); Serial.print(VMAX); Serial.print("volts and Vmin (0%) = "); Serial.print(VMIN); Serial.println(" volts");
      Serial.print("Battert Percent 25%/50%/75% should be: "); Serial.print(((VMAX - VMIN) / 4) + VMIN); Serial.print("/"); Serial.print(((VMAX - VMIN) / 2) + VMIN); Serial.print("/"); Serial.println(VMAX - ((VMAX - VMIN) / 4));
      delay(500);
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      delay(50);
      float Vbat  = sensorValue * VBAT_PER_BITS;
      int batteryPcnt = static_cast<int>(((Vbat - VMIN) / (VMAX - VMIN)) * 100.);
      Serial.print("Current battery are measured to (please confirm!): "); Serial.print(batteryPcnt); Serial.print(" % - Or "); Serial.print(Vbat); Serial.println(" Volts");
      //=========================
      /*BATTERY*/
    }
    
    void loop() {
      DEBUG_PRINTLN("Loop started"); 
      boolean forceTransmit = false;
      transmission_occured = false;
      battreportCount ++;
      measureCount ++;
      forceTransmit = false;
      
      if (measureCount == FORCE_TRANSMIT_CYCLE) {
      forceTransmit = true;
      measureCount = 0;
      }
      
      sendTempHumidityMeasurements(forceTransmit);
      sendLightMeasurements(forceTransmit);
    
      Serial.print("battreportCount");Serial.println(battreportCount);
        /*BATTERY*/
        //=========================
        // BATTERY MEASURER
        if(((transmission_occured) && (battreportCount>=BATT_REPORT_CYCLE)) || (battreportCount == -1)){
                Serial.print("----BATTERY SEND/Measure CYCLE---- ");
                MeasureBattery();
                send(msgVBat.set(VbatAverage, 3));
                sendBatteryLevel(battAveragePcnt);
                Serial.print("Battery Average (Send): "); Serial.print(battAveragePcnt); Serial.println(" %");
                Serial.print("Battery Average Voltage (Send): "); Serial.print(VbatAverage); Serial.println(" V");
                battreportCount=0; 
                battAveragePcnt=0;
                VbatAverage=0;
                VbatSum=0;
                battSumPcnt=0;
                measureCount=0;
                }
      //=========================
      /*BATTERY*/
      
      DEBUG_PRINTLN("Loop ended");
      sleep(SLEEP_TIME);
    }
    /*********************************************
     * * Sends temperature and humidity from Si7021 sensor
     * Parameters
     * - force : Forces transmission of a value (even if it's the same as previous measurement)
     *********************************************/
    void sendTempHumidityMeasurements(bool force) {
      bool tx = force;
      DEBUG_PRINTLN("Send TEMP and HUM started"); 
      si7021_env data = humiditySensor.getHumidityAndTemperature();
      float temperature = data.celsiusHundredths / 100.0;
      DEBUG_PRINT("T: ");DEBUG_PRINTLN(temperature);
      float diffTemp = abs(lastTemperature - temperature);
      DEBUG_PRINT(F("TempDiff :"));DEBUG_PRINTLN(diffTemp);
      if (diffTemp > TEMP_TRANSMIT_THRESHOLD || tx) {
        send(msgTemp.set(temperature, 1));
        lastTemperature = temperature;
        DEBUG_PRINTLN("TEMP sent!");
        transmission_occured = true;
       
        }
      
      int humidity = data.humidityPercent;
      DEBUG_PRINT("H: ");DEBUG_PRINTLN(humidity);
      raHum.addValue(humidity);
      humidity = raHum.getAverage();  // MA sample imply reasonable fast sample frequency
      float diffHum = abs(lastHumidity - humidity);  
      DEBUG_PRINT(F("HumDiff  :"));DEBUG_PRINTLN(diffHum); 
      if (diffHum > HUMI_TRANSMIT_THRESHOLD || tx) {
        send(msgHum.set(humidity, 1));
        lastHumidity = humidity;
        DEBUG_PRINTLN("HUM sent!");
        transmission_occured = true;
        
        }
    
    }
    
    //BH1750
    void sendLightMeasurements(bool force){
        bool tx = force;
        int lux = lightSensor.readLightLevel();// Get Lux value
        float diffLux = abs(lastLux - lux);
        //Serial.println(lux);
        DEBUG_PRINT("LUX: ");DEBUG_PRINTLN(lux);
        DEBUG_PRINT("LuxDiff: ");DEBUG_PRINTLN(diffLux);
        if (diffLux > LUX_TRANSMIT_THRESHOLD || tx) {
          send(msgLight.set(lux));
          lastLux = lux;
          DEBUG_PRINTLN("LUX sent!");
          transmission_occured = true;
          }
    }
    //BH1750
    
    /*BATTERY*/
    //=========================
    // BATTERY MEASURER
    void MeasureBattery() //The battery calculations
    {
      
      
      
     if (batteryPcnt > 100) {
         batteryPcnt = 100;
        }
          for (int i = 1 ; i <= BATT_MEASURE_CYCLE; i++)
          {
            delay(500);
            // Battery monitoring reading
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            delay(500);
            // Calculate the battery in %
            float Vbat  = sensorValue * VBAT_PER_BITS;
            int batteryPcnt = static_cast<int>(((Vbat - VMIN) / (VMAX - VMIN)) * 100.);
            Serial.print("I: ");Serial.println(i);
            Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.print(" %"); Serial.print("Battery Voltage: "); Serial.print(Vbat); Serial.println(" Volts");
            battSumPcnt += batteryPcnt;
            Serial.print("battSumPcnt:::");Serial.println(battSumPcnt);
            battAveragePcnt = battSumPcnt / i;
            VbatSum += Vbat;
            VbatAverage = VbatSum / i;
            Serial.print("battAveragePcnt Calculated: ");Serial.println(battAveragePcnt);
            
          }
        }
    //=========================
    /*BATTERY*/
    
    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    Dear @neverdie ,
    Ok, so I wont use these batteries.

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @tommas

    Dear All!

    Can I use 2xAA 1.6V NiZn battery for 3.3V arduino mini pro?

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    Hi All!

    Im near to get it work:) .
    Someone could write an example openhab2 thing and item for Battery Voltage handling?

    Thank you!

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @gohan

    Dear Gohan!

    Thank you! I thought that it isnt equal with this: https://www.mysensors.org/download/sensor_api_20#sleeping ....
    But perhaps I misunderstood something because you says that it is the same sleep mode...

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    @sundberg84

    Oh ok. I have put this in the code, so it is OK, i think. I thought that SLEEP_TIME isnt equal to powerdown, but it seems that i misunderstood.
    I use your easypcb board Sundberg.... Is your battery measurement code better than this standard mysensors one?

    Thank You again!

    Development

  • Arduino mini pro 3.3 battery optimization code
    T Tommas

    Dear All!

    I would like to use the Arduino Mini Pro 3.3 8Mhz (aTMega328) with 2xAA battery. I have read that it useful to put it in powerdown/sleep mode.
    Could you help me what code/sketch should I use. I copied to here my beta sketch(It works, but it doesnt have the powerdown function)
    If someone has any other suggestion related to the code, please write it!

    /**
     * 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: Henrik EKblad
     * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
     * 
     * DESCRIPTION
     * This sketch provides an example of how to implement a humidity/temperature
     * sensor using a DHT11/DHT-22.
     *  
     * For more information, please visit:
     * http://www.mysensors.org/build/humidity
     * 
     */
    #define MY_NODE_ID 6
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached 
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    /* Sketch with Si7021 and battery monitoring.
    by m26872, 20151109 
    */
    #include <MySensors.h>  
    #include <Wire.h>
    #include <SI7021.h>
    #include <SPI.h>
    #include <RunningAverage.h>
    #include <BH1750.h> //BH1750
    
    #define DEBUG
    
    #ifdef DEBUG
    #define DEBUG_SERIAL(x) Serial.begin(x)
    #define DEBUG_PRINT(x) Serial.print(x)
    #define DEBUG_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_SERIAL(x)
    #define DEBUG_PRINT(x) 
    #define DEBUG_PRINTLN(x) 
    #endif
    #define MOTION_DIGITAL_INPUT_SENSOR 3 //MOTION
    
    #define NODE_ID 6             // <<<<<<<<<<<<<<<<<<<<<<<<<<<   Enter Node_ID
    #define CHILD_ID_TEMP 0
    #define CHILD_ID_HUM 1
    #define CHILD_ID_LIGHT 2 //BH1750
    #define CHILD_ID_MOTION 3 /*MOTION*/
    //BATTERY
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    
    uint32_t SLEEP_TIME = 900000;  // sleep time between reads (seconds * 1000 milliseconds)
    int oldBatteryPcnt = 0;
    
    
    //#define SLEEP_TIME 15000 // 15s for DEBUG
    #define SLEEP_TIME 10000   // 5 min
    //#define FORCE_TRANSMIT_CYCLE 36  // 5min*12=1/hour, 5min*36=1/3hour 
    #define FORCE_TRANSMIT_CYCLE 1  // 5min*12=1/hour, 5min*36=1/3hour 
    //#define BATTERY_REPORT_CYCLE 2880   // Once per 5min   =>   12*24*7 = 2016 (one report/week)
    //#define VMIN 1900
    //#define VMAX 3300
    #define HUMI_TRANSMIT_THRESHOLD 3.0  // THRESHOLD tells how much the value should have changed since last time it was transmitted.
    #define TEMP_TRANSMIT_THRESHOLD 0.5
    #define AVERAGES 2
    
    //int batteryReportCounter = BATTERY_REPORT_CYCLE - 1;  // to make it report the first time.
    int measureCount = 0;
    float lastTemperature = -100;
    int lastHumidity = -100;
    
    uint16_t lastlux; //BH1750
    
    RunningAverage raHum(AVERAGES);
    SI7021 humiditySensor;
    BH1750 lightSensor;
    
    //MySensor gw;
    MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP); // Initialize temperature message
    MyMessage msgHum(CHILD_ID_HUM,V_HUM);
    MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); //BH1750
    MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED); //MOTION
    
    void presentation(){
    
    sendSketchInfo("Node 6, Temp,Hum,Light,Motion", "1.1"); 
      present(CHILD_ID_TEMP, S_TEMP);   // Present sensor to controller
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); //BH1750
      present(CHILD_ID_MOTION, S_MOTION); /*MOTION*/
    
    //BATTERY
    sendSketchInfo("Battery Meter", "1.0");
    }
    
    
    void setup() {
    
      //BATTERY
        // use the 1.1 V internal reference
    #if defined(__AVR_ATmega2560__)
        analogReference(INTERNAL1V1);
    #else
        analogReference(INTERNAL);
    #endif
    
    //BATTERY
      
      DEBUG_SERIAL(115200);    
      DEBUG_PRINTLN("Serial started");
      
      //DEBUG_PRINT("Voltage: ");
      //DEBUG_PRINT(readVcc()); 
      //DEBUG_PRINTLN(" mV");
    /*
      delay(500);
      DEBUG_PRINT("Internal temp: ");
      DEBUG_PRINT(GetInternalTemp()); // Probably not calibrated. Just to print something.
      DEBUG_PRINTLN(" *C");
    */  
      delay(500); // Allow time for radio if power useed as reset
      //begin(NULL,NODE_ID);
      
      //DEBUG_PRINT("Node and "); DEBUG_PRINTLN("2 children presented.");
      
      raHum.clear();
      lightSensor.begin(); //BH1750
      /* MOTION */
      pinMode(MOTION_DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void loop() {
      DEBUG_PRINTLN("Loop started"); 
      measureCount ++;
      
      bool forceTransmit = true;
      
      //if (measureCount > FORCE_TRANSMIT_CYCLE) {
      //forceTransmit = true; 
      //}
      sleep(SLEEP_TIME);
      //BATTERY
    // get the battery Voltage
        int sensorValue = analogRead(BATTERY_SENSE_PIN);
    #ifdef MY_DEBUG
        Serial.println(sensorValue);
    #endif
    
        // 1M, 470K divider across battery and using internal ADC ref of 1.1V
        // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
        // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
        // 3.44/1023 = Volts per bit = 0.003363075
    
        int batteryPcnt = sensorValue / 10;
    
    #ifdef MY_DEBUG
        float batteryV  = sensorValue * 0.003363075;
        Serial.print("Battery Voltage: ");
        Serial.print(batteryV);
        Serial.println(" V");
    
        Serial.print("Battery percent: ");
        Serial.print(batteryPcnt);
        Serial.println(" %");
    #endif
    
        if (oldBatteryPcnt != batteryPcnt) {
            // Power up radio after sleep
            sendBatteryLevel(batteryPcnt);
            oldBatteryPcnt = batteryPcnt;
        }
    
      //BATTERY
      sendTempHumidityMeasurements(forceTransmit);
      //BH1750   
        uint16_t lux = lightSensor.readLightLevel();// Get Lux value
        Serial.println(lux);
        DEBUG_PRINT("LUX: ");DEBUG_PRINTLN(lux);
        if (lux != lastlux) {
            send(msgLight.set(lux));
            lastlux = lux; }
      //BH1750
      /* MOTION */
      // Read digital motion value
      bool tripped = digitalRead(MOTION_DIGITAL_INPUT_SENSOR) == HIGH;
      Serial.println(tripped);
      send(msgMotion.set(tripped?"1":"0"));  // Send tripped value to gw
      
      DEBUG_PRINTLN("Loop ended");
      }
    /*********************************************
     * * Sends temperature and humidity from Si7021 sensor
     * Parameters
     * - force : Forces transmission of a value (even if it's the same as previous measurement)
     *********************************************/
    void sendTempHumidityMeasurements(bool force) {
      bool tx = force;
      DEBUG_PRINTLN("Send TEMP and HUM started"); 
      si7021_env data = humiditySensor.getHumidityAndTemperature();
      float temperature = data.celsiusHundredths / 100.0;
      DEBUG_PRINT("T: ");DEBUG_PRINTLN(temperature);
      float diffTemp = abs(lastTemperature - temperature);
      DEBUG_PRINT(F("TempDiff :"));DEBUG_PRINTLN(diffTemp);
      //if (diffTemp > TEMP_TRANSMIT_THRESHOLD || tx) {
      send(msgTemp.set(temperature, 1));
      //lastTemperature = temperature;
      //measureCount = 0;
      DEBUG_PRINTLN("T sent!");
      //}
      
      int humidity = data.humidityPercent;
      DEBUG_PRINT("H: ");DEBUG_PRINTLN(humidity);
      raHum.addValue(humidity);
      humidity = raHum.getAverage();  // MA sample imply reasonable fast sample frequency
      float diffHum = abs(lastHumidity - humidity);  
      DEBUG_PRINT(F("HumDiff  :"));DEBUG_PRINTLN(diffHum); 
      //if (diffHum > HUMI_TRANSMIT_THRESHOLD || tx) {
      send(msgHum.set(humidity, 1));
      //lastHumidity = humidity;
      //measureCount = 0;
      DEBUG_PRINTLN("H sent!");
      //}
    
    }```
    
    Thank you in advance!!
    Development
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular