Navigation

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

    Posts made by niccodemi

    • RE: openHAB 4 MySensors Binding

      @forexsieno I am running OH4 but have migrated MySensors to MQTTGateway. Below example of how to control relays.

      thing file

      Bridge mqtt:broker:Mosquitto "Mysensors MQTT Broker" [host="192.xxx.xxx.xxx", secure=false, port=1883, clientID="Openhab"] 
      {
          Thing topic relunderstair "Relay" (mqtt:broker:Mosquitto) {
              Channels:
                  Type switch : relunderstair0101 "LED-stairs" [ stateTopic="mygateway1-out/1/1/0/0/2", commandTopic ="mygateway1-in/1/1/0/0/2", on="1", off="0" ]
          }
       }
      

      item file

      Switch relunderstair0101  "LED-stairs" { channel="mqtt:topic:Mosquitto:relunderstair:relunderstair0101" }
      
      posted in OpenHAB
      niccodemi
      niccodemi
    • RE: openHAB 4 MySensors Binding

      @ben999 Thank you. I managed to get sensors data coming into OH.

      Would you happen to have also any thing / item example for switch / relay sketch?

      posted in OpenHAB
      niccodemi
      niccodemi
    • RE: openHAB 4 MySensors Binding

      Hi @ben999

      I used to have OH3 with MySensors Ethernet gateway but now I have upgraded to OH4 and it seems the only option is to connect MySensors network to OH via MQTT.
      I flashed MySensors mqtt_gateway and installed Mosquitto on same machine where OH4 is installed (ip=192.168.1.yyy). I also installed MQTT binding in OH4.

      Can you please advise how did you configure things and items file? In OH3 I had them configured in textual format.

      Things file in OH3

      Bridge mysensors:bridge-eth:gateway [ ipAddress="192.168.1.xxx", tcpPort=5003, sendDelay=300, startupCheckEnabled=false, networkSanCheckEnabled=true ] {
      	 light			relunderstair0101 [ nodeId=1, childId=1, requestAck=false ]
      

      Items file in OH3

      Switch relunderstair0101  "LED-stairs" { channel="mysensors:light:gateway:relunderstair0101:status" }
      
      posted in OpenHAB
      niccodemi
      niccodemi
    • RE: OH3 - MySensors Binding

      After upgrading OH from 3.2.0 to 3.3.0 and placing latest Mysensors binding (3.3.0-SNAPSHOT) into addon folder I can only get it to "Installed" status but not "active".

      Any advise how to remove following issues?

      openhab> feature:install openhab-transport-serial
      openhab> feature:install openhab-core-io-transport-mqtt
      openhab> diag 291
      openHAB Add-ons :: Bundles :: MySensors Binding (291)
      -----------------------------------------------------
      Status: Installed
      Unsatisfied Requirements:
      osgi.wiring.package; filter:="(osgi.wiring.package=org.openhab.binding.mqtt.handler)"
      osgi.wiring.package; filter:="(osgi.wiring.package=org.openhab.binding.mysensors.action)"
      osgi.wiring.package; filter:="(osgi.wiring.package=org.openhab.binding.mysensors.config)"
      osgi.wiring.package; filter:="(osgi.wiring.package=org.openhab.binding.mysensors.factory)"
      Declarative Services
      
      posted in OpenHAB
      niccodemi
      niccodemi
    • RE: OH3 - MySensors Binding

      Hi,

      I just upgraded Linux Openhab version from "openHAB 3.1.0.M2" to "openHAB 3.1.0.M3". Since upgrade I cannot use / activate MySensors binding anymore (it worked in previous version - M2).
      I cleaned openhab cache, rebooted computer; feature:install openhab-transport-serial and feature:install openhab-core-io-transport-mqtt are properly installed and active. When I place Mysensors.jar to Addons folder the file gets recognized but it is listed only as Installed, not active.

      openhab> bundle:list | grep MySensors
      266 x Installed x  80 x 3.1.0.202012312203      x openHAB Add-ons :: Bundles :: MySensors Binding
      

      Log shows following error:

       [WARN ] [org.apache.felix.fileinstall         ] - Error while starting bundle: file:/usr/share/openhab/addons/org.openhab.binding.mysensors-3.1.0.jar
      org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.mysensors [266]
        Unresolved requirement: Import-Package: org.apache.commons.lang; version="[2.6.0,3.0.0)"
      
              at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi-3.12.100.jar:?]
              at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[org.eclipse.osgi-3.12.100.jar:?]
              at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.4]
              at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.4]
              at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [bundleFile:3.6.4]
              at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.4]
              at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.4]
      
      

      Does anyone know how to resolve this issue / install missing requirement?

      posted in OpenHAB
      niccodemi
      niccodemi
    • RE: Openhab multiple gateways

      @TimO thanks, that's great. Do I have to change the bridge name (gateway) for the second bridge to something else? Can I use same node IDs on both gateways?

      Bridge mysensors:bridge-ser:gateway [ serialPort="/dev/pts/2", sendDelay=200 ] {
      	humidity 		hum01 	[ nodeId=172, childId=0 ]
      	temperature		temp01 	[ nodeId=172, childId=1 ]
              light			light01 [ nodeId=105, childId=0  ]
              light			light02 [ nodeId=105, childId=1 ]
        }
      Bridge mysensors:bridge-eth:gateway [ ipAddress="127.0.0.1", tcpPort=5003, sendDelay=200 ] {
      	humidity 		hum01 	[ nodeId=172, childId=0 ]
      	temperature		temp01 	[ nodeId=172, childId=1 ]
              light			light01 [ nodeId=105, childId=0 ]
              light			light02 [ nodeId=105, childId=1 ]
        }
      
      posted in OpenHAB
      niccodemi
      niccodemi
    • Openhab multiple gateways

      Hi,

      is it possible to configure multiple MySensors gateways (ie one serial and one ethernet) on single Openhab server?

      posted in OpenHAB
      niccodemi
      niccodemi
    • RE: water flow sensor YF-B5

      @yveaux is there any way to convert flow in l/min to pulses per liter?

      Another user posted below info; is that accurate?

        • Flow meter using Honeywell C7195A2001B which has a hall sensor that pulses at 7 Hz per liter/min
      • we count only upgoing pulses, so in our case we get:
      • 7 pulses per second at 1 l/min
      • 420 pulses per liter
      • 420000 pulses per m3
      • Flow meter Caleffi 316 which has a hall sensor that pulses at 8.8 Hz per liter/min (according to specs)
      • In reality the frequency is about 30% lower in my case, so we have to correct this with a factor of 1.3.
      • 8.8 pulses per second at 1 l/min
      • 528 pulses per liter
      • 528000 pulses per m3
      • 528000/1.3 = 406154
      posted in Troubleshooting
      niccodemi
      niccodemi
    • water flow sensor YF-B5

      Hi,

      I would like to use YF-B5 water flow sensor with default mysensors water-meter sketch. I need help getting correct PULSE_FACTOR value based on below specs:

      1 Appearance Product identification clear, accurate and meet the requirements
      2 water pressure> 1.75MPa
      3 Operating voltage range DC5 ~ 15V
      4 Insulation resistance> 100MΩ
      5 Accuracy (in 1 ~ 25L \ MIN) ± 3%
      6 Flow Pulse Characteristics (6.6 * Q) Q = L / Min ± 3%
      7 Output pulse high> DC 4.7V (input voltage DC 5V)
      8 Output pulse low level <DC 0.5V (input voltage DC 5V)
      9 Output pulse duty cycle 50% ± 10%

      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_NRF5_ESB
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      #include <MySensors.h>
      
      #define DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
      
      #define PULSE_FACTOR 1000                       // Number of blinks per m3 of your meter (One rotation/liter)
      
      #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
      
      #define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.
      
      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Relay control - bistable switch instead of monostable.

      I am using below sketch; make sure that number of relays matches number of relayPins and buttonPins.

      //MultiRelayButton Sketch, MySensors 1.6, toggle switch
      
      #define MY_RADIO_NRF24
      
      #define MY_REPEATER_FEATURE
      
      //Set Static node id
      //#define MY_NODE_ID 250
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #define RELAY_ON 0                      // switch around for ACTIVE LOW / ACTIVE HIGH relay
      #define RELAY_OFF 1
      //
      
      #define noRelays 2                     //2-4
      const int relayPin[] = {14,15};          //  switch around pins to your desire
      const int buttonPin[] = {3,4};      //  switch around pins to your desire
      
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
      public:                                      
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays]; 
      Bounce debouncer[noRelays];
      MyMessage msg[noRelays];
      
      void setup(){
          sendHeartbeat();
          wait(100);
          // Initialize Relays with corresponding buttons
          for (int i = 0; i < noRelays; i++){
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msg[i].sensor = i;                                   // initialize messages
          msg[i].type = V_LIGHT;   
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          wait(100);
          pinMode(Relays[i].relayPin, OUTPUT);
          Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
          send(msg[i].set(Relays[i].relayState? true : false));                  // make controller aware of last status  
          wait(50);
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(20);
          wait(50);
          }
      }
      void presentation()  {
            sendSketchInfo("MultiRelayButton", "1.0");
            wait(100);
            for (int i = 0; i < noRelays; i++)
            present(i, S_LIGHT);                               // present sensor to gateway
            wait(100);
      }
      void loop()
      {
          for (byte i = 0; i < noRelays; i++) {
              if (debouncer[i].update()) {
                  Relays[i].relayState = !Relays[i].relayState;
                  digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
                  send(msg[i].set(Relays[i].relayState? true : false));
                  // save sensor state in EEPROM (location == sensor number)
                  saveState( i, Relays[i].relayState );
              }                 
          }
          wait(20);
      }
      // process incoming message 
      void receive(const MyMessage &message){        
         if (message.type == V_LIGHT){ 
         if (message.sensor <noRelays){            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
         Relays[message.sensor].relayState = message.getBool(); 
         digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
         saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
         }
        }
        wait(20);
      }
      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Remote Access

      @Mitja-Blazinsek I had similar issue. I found the cause was port 8443 itself. When I changed Mycontroller config to use another port (8442 or 8444) and opened it, I was able to access Mycontroller from external networks.

      posted in MyController.org
      niccodemi
      niccodemi
    • RE: How to scan rf remote

      as emc2 said; alternatively if rc-switch doesn't work for you (unlikely) you can also try with Remoteswitch library.

      posted in Development
      niccodemi
      niccodemi
    • RE: Anyone tried the $199 Monoprice 3D printer?

      @NeverDie they do, but many people don't notice it or find it unbearable. It also depends on type of filament; ABS smells like hot plastic, PLA like something sweet (it is derived from sugar). I keep mine in the house but I put it inside DIY enclosure - mainly to improve ABS printing quality but as side effect it also contains smell.

      posted in Enclosures / 3D Printing
      niccodemi
      niccodemi
    • RE: Remote Access

      @Velo17 I am still on IPv4. I use DDClient as an update agent. I think it works with majority of providers such as NO-IP and DYNU.

      posted in MyController.org
      niccodemi
      niccodemi
    • RE: Remote Access

      @Velo17 One of my linux servers is also behind double NAT network but I can still use DDNS service however update client has to be installed / configured on the server itself not on the router.

      Other option (if you are running Raspbian) would be Teamviewer.

      posted in MyController.org
      niccodemi
      niccodemi
    • RE: Rain Guage

      @mrc-core Remove folder "Time" from your libraries folder, then download the "MySensorsArduinoExamples" zip from this link and extract Time library to your libraries folder. Restart Arduino IDE and try again.

      posted in My Project
      niccodemi
      niccodemi
    • RE: Rain Guage

      @mrc-core is this the sketch you are using?

      /*
       Arduino Tipping Bucket Rain Gauge
      
       April 26, 2015
      
       Version 1.4.1 alpha
      
       Arduino Tipping Bucket Rain Gauge
      
       Utilizing a tipping bucket sensor, your Vera home automation controller and the MySensors.org
       gateway you can measure and sense local rain.  This sketch will create two devices on your
       Vera controller.  One will display your total precipitation for the last 5 days.  The other, 
       a sensor that changes state if there is recent rain (up to last 120 hours)  above a threshold.  
       Both these settings are user definable.
      
       There is a build overview video here: https://youtu.be/1eMfKQaLROo
      
       This sketch features the following:
      
       * Allows you to set the rain threshold in mm
       * Allows you to determine the tripped indicator window up to 120 hours.
       * Displays the last 5 days of rain in Variable1 through Variable5
         of the Rain Sensor device
       * Configuration changes to Sensor device updated every hour
       * Should run on any Arduino
       * Will retain Tripped/Not Tripped status and data in a power interruption, saving small amount
         of data to EEPROM (Circular Buffer to maximize life of EEPROM)
       * LED status indicator
       * Optional Temp/Humidity (DHT-22 or DHT-11) and Light LUX (BH1750) sensors. To use, uncomment
         #define DHT_ON  and/or #define LUX_ON
       * Optionally send total accumulation of each day's rainfall or send only individual days rainfall totals.
         Comment out #define USE_DAILY to display individual daily rainfall.
      
       by @BulldogLowell and @PeteWill for free public use
      
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      //#define MY_NODE_ID 7
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <math.h>
      #include <Time.h>
      
      #define SKETCH_NAME "Rain Gauge"
      #define SKETCH_VERSION "1.4.1a"
      
      #define DWELL_TIME 125  // this allows for radio to come back to power after a transmission, ideally 0 
      
      //#define DEBUG_ON  // comment out this line to disable serial debug
      #define DHT_ON // uncomment out this line to enable DHT sensor
      #define LUX_ON // uncomment out this line to enable BH1750 sensor
      //#define USE_DAILY // displays each time segment as an accumulation of prior periods inclusive.  Comment out to display individual daily rainfall totals in the variables sent to your controller.
      
      #define TIP_SENSOR_PIN 3
      
      #define CALIBRATE_FACTOR 60 // amount of rain per rain bucket tip e.g. 5 is .05mm
      #define DHT_LUX_DELAY 300000  //Delay in milliseconds that the DHT and LUX sensors will wait before sending data
      
      #define CHILD_ID_RAIN_LOG 3  // Keeps track of accumulated rainfall
      #define CHILD_ID_TRIPPED_INDICATOR 4  // Indicates Tripped when rain detected
      #define EEPROM_BUFFER_LOCATION 0  // location of the EEPROM circular buffer
      #define E_BUFFER_LENGTH 240
      #define RAIN_BUCKET_SIZE 120
      
      #ifdef  DEBUG_ON
        #define DEBUG_PRINT(x)   Serial.print(x)
        #define DEBUG_PRINTLN(x) Serial.println(x)
        #define SERIAL_START(x)  Serial.begin(x)
        #else
        #define DEBUG_PRINT(x)
        #define DEBUG_PRINTLN(x)
        #define SERIAL_START(x)
      #endif
      //
      MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE);
      MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
      //
      MyMessage msgRainVAR1(CHILD_ID_RAIN_LOG, V_VAR1);
      MyMessage msgRainVAR2(CHILD_ID_RAIN_LOG, V_VAR2);
      MyMessage msgRainVAR3(CHILD_ID_RAIN_LOG, V_VAR3);
      MyMessage msgRainVAR4(CHILD_ID_RAIN_LOG, V_VAR4);
      MyMessage msgRainVAR5(CHILD_ID_RAIN_LOG, V_VAR5);
      //
      MyMessage msgTripped(CHILD_ID_TRIPPED_INDICATOR, V_TRIPPED);
      MyMessage msgTrippedVar1(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
      MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
      //
      #ifdef DHT_ON
        #include <DHT.h>
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define HUMIDITY_SENSOR_DIGITAL_PIN 8
        DHT dht;
        float lastTemp;
        float lastHum;
        boolean metric = true;
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      #endif
      //
      #ifdef LUX_ON
        //BH1750 is connected to SCL (analog input A5) and SDA (analog input A4)
        #include <BH1750.h>
        #include <Wire.h>
        #define CHILD_ID_LIGHT 2
        BH1750 lightSensor;
        MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        unsigned int lastlux;
        byte heartbeat = 10; //Used to send the light lux to gateway as soon as the device is restarted and after the DHT_LUX_DELAY has happened 10 times
      #endif
      unsigned long sensorPreviousMillis;
      int eepromIndex;
      int ledPin = 5; // Pin the LED is connected to.  PWM capable pin required
      unsigned long dataMillis;
      unsigned long serialInterval = 600000UL;
      const unsigned long oneHour = 3600000UL;
      unsigned long lastTipTime;
      unsigned long lastRainTime; //Used for rainRate calculation
      unsigned int rainBucket [RAIN_BUCKET_SIZE] ; /* 24 hours x 5 Days = 120 hours */
      unsigned int rainRate = 0;
      byte rainWindow = 72;         //default rain window in hours.  Will be overwritten with msgTrippedVar1.
      volatile int wasTippedBuffer = 0;
      int rainSensorThreshold = 50; //default rain sensor sensitivity in hundredths.  Will be overwritten with msgTrippedVar2.
      byte state = 0;
      byte oldState = -1;
      unsigned int lastRainRate = 0;
      int lastMeasure = 0;
      boolean gotTime = false;
      byte lastHour;
      byte currentHour;
      //
      void setup()
      {
        SERIAL_START(115200);
        //
        // Set up the IO
        pinMode(TIP_SENSOR_PIN, INPUT_PULLUP);
        attachInterrupt (digitalPinToInterrupt(TIP_SENSOR_PIN), sensorTipped, FALLING);  // depending on location of the hall effect sensor may need CHANGE
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, HIGH);
        //
        //Sync time with the server, this will be called hourly in order to keep time from creeping with the crystal
        //
        unsigned long functionTimeout = millis();
        while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
        {
          requestTime();
          DEBUG_PRINTLN(F("Getting Time"));
          wait(1000); // call once per second
          DEBUG_PRINTLN(F("."));
        }
        currentHour = hour();
        lastHour = hour();
        //
        //retrieve from EEPROM stored values on a power cycle.
        //
        boolean isDataOnEeprom = false;
        for (int i = 0; i < E_BUFFER_LENGTH; i++)
        {
          byte locator = loadState(EEPROM_BUFFER_LOCATION + i);
          if (locator == 0xFE)  // found the EEPROM circular buffer index
          {
            eepromIndex = EEPROM_BUFFER_LOCATION + i;
            DEBUG_PRINT(F("EEPROM Index "));
            DEBUG_PRINTLN(eepromIndex);
            //Now that we have the buffer index let's populate the rainBucket[] with data from eeprom
            loadRainArray(eepromIndex);
            isDataOnEeprom = true;
            break;
          }
        }
        //
        if (!isDataOnEeprom) // Added for the first time it is run on a new Arduino
        {
          DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0"));
          eepromIndex = EEPROM_BUFFER_LOCATION;
          saveState(eepromIndex, 0xFE);
          saveState(eepromIndex + 1, 0xFE);
          //then I will clear out any bad data
          for (int i = 2; i <= E_BUFFER_LENGTH; i++)
          {
            saveState(i, 0x00);
          }
        }
        dataMillis = millis();
        lastTipTime = millis() - oneHour; //why is this -oneHour?? Doesn't millis() start at 0 when first powered on?
        //
        request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
        wait(DWELL_TIME);
        request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
        wait(DWELL_TIME);
        //
      #ifdef DHT_ON
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
        wait(DWELL_TIME);
        metric = getConfig().isMetric;
      #endif
        //
      #ifdef LUX_ON
        wait(DWELL_TIME);
        lightSensor.begin();
      #endif
        //
        DEBUG_PRINTLN(F("Radio Setup Complete!"));
        transmitRainData();
      }
      
      
      void presentation()  {
        // Register all sensors to gw (they will be created as child devices)
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        wait(DWELL_TIME);
        present(CHILD_ID_RAIN_LOG, S_RAIN);
        wait(DWELL_TIME);
        present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
        wait(DWELL_TIME);
      
      #ifdef DHT_ON
        present(CHILD_ID_HUM, S_HUM);
        wait(DWELL_TIME);
        present(CHILD_ID_TEMP, S_TEMP);
        wait(DWELL_TIME);
      #endif
      
      
      #ifdef LUX_ON
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      #endif
      
        DEBUG_PRINTLN(F("Sensor Presentation Complete"));
      }
      
      void loop()
      {
        if (state)
        {
          prettyFade();  // breathe if tripped
        }
        else
        {
          slowFlash();   // blink if not tripped
        }
      #ifdef DEBUG_ON  // Serial Debug Block
        if ( (millis() - dataMillis) >= serialInterval)
        {
          for (int i = 24; i <= 120; i = i + 24)
          {
            updateSerialData(i);
          }
          dataMillis = millis();
        }
      #endif
        //
        // let's constantly check to see if the rain in the past rainWindow hours is greater than rainSensorThreshold
        //
        int measure = 0; // Check to see if we need to show sensor tripped in this block
        for (int i = 0; i < rainWindow; i++)
        {
          measure += rainBucket [i];
          if (measure != lastMeasure)
          {
            //      DEBUG_PRINT(F("measure value (total rainBucket within rainWindow): "));
            //      DEBUG_PRINTLN(measure);
            lastMeasure = measure;
          }
        }
        //
        state = (measure >= (rainSensorThreshold * 100));
        if (state != oldState)
        {
          send(msgTripped.set(state));
          wait(DWELL_TIME);
          DEBUG_PRINT(F("New Sensor State... Sensor: "));
          DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped");
          oldState = state;
        }
        //
        unsigned long tipDelay = millis() - lastRainTime;
        if (wasTippedBuffer) // if was tipped, then update the 24hour total and transmit to Vera
        {
          DEBUG_PRINTLN(F("Sensor Tipped"));
          DEBUG_PRINT(F("rainBucket [0] value: "));
          DEBUG_PRINTLN(rainBucket [0]);
          send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day
          wait(DWELL_TIME);
          wasTippedBuffer--;
          rainRate = ((oneHour) / tipDelay);
          if (rainRate != lastRainRate)
          {
            send(msgRainRate.set(rainRate, 1));
            wait(DWELL_TIME);
            DEBUG_PRINT(F("RainRate= "));
            DEBUG_PRINTLN(rainRate);
            lastRainRate = rainRate;
          }
          lastRainTime = lastTipTime;
        }
        //
        currentHour = hour();
        if (currentHour != lastHour)
        {
          DEBUG_PRINTLN(F("One hour elapsed."));
          send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall
          wait(DWELL_TIME);
          saveState(eepromIndex, highByte(rainBucket[0]));
          saveState(eepromIndex + 1, lowByte(rainBucket[0]));
          DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = "));
          DEBUG_PRINTLN(rainBucket[0]);
          for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array
          {
            rainBucket [i + 1] = rainBucket [i];
          }
          request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
          wait(DWELL_TIME);
          request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
          wait(DWELL_TIME);
          rainBucket[0] = 0;
          eepromIndex = eepromIndex + 2;
          if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH)
          {
            eepromIndex = EEPROM_BUFFER_LOCATION;
          }
          DEBUG_PRINT(F("Writing to EEPROM.  Index: "));
          DEBUG_PRINTLN(eepromIndex);
          saveState(eepromIndex, 0xFE);
          saveState(eepromIndex + 1, 0xFE);
          requestTime(); // sync the time every hour
          wait(DWELL_TIME);
          transmitRainData();
          rainRate = 0;
          send(msgRainRate.set(rainRate, 1));
          wait(DWELL_TIME);
          DEBUG_PRINTLN(F("Sending rainRate is 0 to controller"));
          lastHour = currentHour;
        }
        if (millis() - sensorPreviousMillis > DHT_LUX_DELAY)
        {
          #ifdef DHT_ON  //DHT Code
            doDHT();
          #endif
          #ifdef LUX_ON
            doLUX();
          #endif
          sensorPreviousMillis = millis();
        }
      }
      //
      #ifdef DHT_ON
      void doDHT(void)
      {
        float temperature = dht.getTemperature();
          if (isnan(temperature)) 
          {
            DEBUG_PRINTLN(F("Failed reading temperature from DHT"));
          } else if (temperature != lastTemp) 
          {
            lastTemp = temperature;
            if (!metric) 
            {
              temperature = dht.toFahrenheit(temperature);
            }
            send(msgTemp.set(temperature, 1));
            wait(DWELL_TIME);
            DEBUG_PRINT(F("Temperature is: "));
            DEBUG_PRINTLN(temperature);
          }
          float humidity = dht.getHumidity();;
          if (isnan(humidity)) 
          {
            DEBUG_PRINTLN(F("Failed reading humidity from DHT"));
          } else if (humidity != lastHum) 
          {
            lastHum = humidity;
            send(msgHum.set(humidity, 1));
            wait(DWELL_TIME);
            DEBUG_PRINT(F("Humidity is: "));
            DEBUG_PRINTLN(humidity);
          }
      }
      #endif
      //
      #ifdef LUX_ON
      void doLUX(void)
      {
        unsigned int lux = lightSensor.readLightLevel();// Get Lux value
        DEBUG_PRINT(F("Current LUX Level: "));
        DEBUG_PRINTLN(lux);
        heartbeat++;
        if (lux != lastlux || heartbeat > 10) 
        {
          send(msg.set(lux));
          lastlux = lux;
        }
        if (heartbeat > 10) 
        {
          heartbeat = 0;
        }
      }
      #endif
      //
      void sensorTipped()
      {
        unsigned long thisTipTime = millis();
        if (thisTipTime - lastTipTime > 100UL)
        {
          rainBucket[0] += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
          wasTippedBuffer++;
        }
        lastTipTime = thisTipTime;
      }
      //
      int rainTotal(int hours)
      {
        int total = 0;
        for ( int i = 0; i <= hours; i++)
        {
          total += rainBucket [i];
        }
        return total;
      }
      
      void updateSerialData(int x)
      {
        DEBUG_PRINT(F("Rain last "));
        DEBUG_PRINT(x);
        DEBUG_PRINTLN(F(" hours: "));
        float tipCount = 0;
        for (int i = 0; i < x; i++)
        {
          tipCount = tipCount + rainBucket [i];
        }
        tipCount = tipCount / 100;
        DEBUG_PRINTLN(tipCount);
      }
      
      void loadRainArray(int value) // retrieve stored rain array from EEPROM on powerup
      {
        for (int i = 0; i < RAIN_BUCKET_SIZE; i++)
        {
          value = value - 2;
          if (value < EEPROM_BUFFER_LOCATION)
          {
            value = EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH;
          }
          DEBUG_PRINT(F("EEPROM location: "));
          DEBUG_PRINTLN(value);
          byte rainValueHigh = loadState(value);
          byte rainValueLow = loadState(value + 1);
          unsigned int rainValue = rainValueHigh << 8;
          rainValue |= rainValueLow;
          rainBucket[i + 1] = rainValue;
          //
          DEBUG_PRINT(F("rainBucket[ value: "));
          DEBUG_PRINT(i + 1);
          DEBUG_PRINT(F("] value: "));
          DEBUG_PRINTLN(rainBucket[i + 1]);
        }
      }
      
      void transmitRainData(void)
      {
        DEBUG_PRINT(F("In transmitRainData. currentHour = "));
        DEBUG_PRINTLN(currentHour);
        int rainUpdateTotal = 0;
        for (int i = currentHour; i >= 0; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight)
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 24; i > currentHour; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 48; i > currentHour + 24; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 72; i > currentHour + 48; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 96; i > currentHour + 72; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      }
      
      void receive(const MyMessage &message)
      {
        if (message.sensor == CHILD_ID_RAIN_LOG)
        {
          // nothing to do here
        }
        else if (message.sensor == CHILD_ID_TRIPPED_INDICATOR)
        {
          if (message.type == V_VAR1)
          {
            rainWindow = atoi(message.data);
            if (rainWindow > 120)
            {
              rainWindow = 120;
            }
            else if (rainWindow < 1)
            {
              rainWindow = 1;
            }
            if (rainWindow != atoi(message.data))   // if I changed the value back inside the boundries, push that number back to Vera
            {
              send(msgTrippedVar1.set(rainWindow));
            }
          }
          else if (message.type == V_VAR2)
          {
            rainSensorThreshold = atoi(message.data);
            if (rainSensorThreshold > 10000)
            {
              rainSensorThreshold = 10000;
            }
            else if (rainSensorThreshold < 1)
            {
              rainSensorThreshold = 1;
            }
            if (rainSensorThreshold != atoi(message.data))  // if I changed the value back inside the boundries, push that number back to Vera
            {
              send(msgTrippedVar2.set(rainSensorThreshold));
            }
          }
        }
      }
      
      void prettyFade(void)
      {
        float val = (exp(sin(millis() / 2000.0 * PI)) - 0.36787944) * 108.0;
        analogWrite(ledPin, val);
      }
      
      void slowFlash(void)
      {
        static boolean ledState = true;
        static unsigned long pulseStart = millis();
        if (millis() - pulseStart < 100UL)
        {
          digitalWrite(ledPin, !ledState);
          pulseStart = millis();
        }
      }
      
      void receiveTime(unsigned long time)
      {
        DEBUG_PRINTLN(F("Time received..."));
        setTime(time);
        char theTime[6];
        sprintf(theTime, "%d:%2d", hour(), minute());
        DEBUG_PRINTLN(theTime);
      }
      

      It compiles fine with Arduino IDE 1.6.5, Mysensors 2.0.0 and libraries (Time, BH1750).

      posted in My Project
      niccodemi
      niccodemi
    • RE: Upgrading to 2.0 sketch dificulty

      @andmaster

      I've used below sketch with 1.6 development version; it compiles also with 2.0.0 but I have not tested it. This sketch uses toggle buttons.

      //MultiRelayButton Sketch, MySensors 1.6, toggle switch
      
      #define MY_RADIO_NRF24
      
      #define MY_REPEATER_FEATURE
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #define RELAY_ON 0                      // switch around for ACTIVE LOW / ACTIVE HIGH relay
      #define RELAY_OFF 1                     // switch around for ACTIVE LOW / ACTIVE HIGH relay
      //
      
      #define noRelays 4                     //2-4, define number of relays
      const int relayPin[] = {14,15,16,17};          //  relay pins - should match noRelays
      const int buttonPin[] = {3,4,5,6};      //  button pins - should match noRelays
      
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
      public:                                      
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays]; 
      Bounce debouncer[noRelays];
      MyMessage msg[noRelays];
      
      void setup(){
          sendHeartbeat();
          wait(100);
          // Initialize Relays with corresponding buttons
          for (int i = 0; i < noRelays; i++){
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msg[i].sensor = i;                                   // initialize messages
          msg[i].type = V_LIGHT;   
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          wait(100);
          pinMode(Relays[i].relayPin, OUTPUT);
          Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
          send(msg[i].set(Relays[i].relayState? true : false));                  // make controller aware of last status  
          wait(50);
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(20);
          wait(50);
          }
      }
      void presentation()  {
            sendSketchInfo("MultiRelayButton", "1.0");
            wait(100);
            for (int i = 0; i < noRelays; i++)
            present(i, S_LIGHT);                               // present sensor to gateway
            wait(100);
      }
      void loop()
      {
          for (byte i = 0; i < noRelays; i++) {
              if (debouncer[i].update()) {
                  Relays[i].relayState = !Relays[i].relayState;
                  digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
                  send(msg[i].set(Relays[i].relayState? true : false));
                  // save sensor state in EEPROM (location == sensor number)
                  saveState( i, Relays[i].relayState );
              }                 
          }
          wait(20);
      }
      // process incoming message 
      void receive(const MyMessage &message){        
         if (message.type == V_LIGHT){ 
         if (message.sensor <noRelays){            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
         Relays[message.sensor].relayState = message.getBool(); 
         digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
         saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
         }
        }
        wait(20);
      }
      
      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: ESP8266 OTA (SOLVED)

      @mfalkvidd I reinstalled Arduino IDE and libraries and that seems to fixed the issue.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: ESP8266 OTA (SOLVED)

      @mfalkvidd ok, I'll try. I thought that's what GatewayESP8266OTA sketch was supposed to do.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • ESP8266 OTA (SOLVED)

      Hi,

      I followed this guide

      https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/readme.md

      to get OTA working on ESP8266. I can flash and re-upload (over WIFI) BasicOTA.ino without issues. Once I upload GatewayESP8266OTA.ino and afterwards try to upload another sketch I receive message "[ERROR]: No Answer".

      I am using Arduino IDE 1.6.9, MySensors 2.0.0, ESP Boards 2.3.0.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Rain Guage

      @AWI thank you. Sketch compiles now but after uploading it still doesn't work - serial monitor is blank (debug on).

      posted in My Project
      niccodemi
      niccodemi
    • RE: Rain Guage

      Has anyone converted this sketch to Mysensors 2.0 already? I've tried but received following error when compiling:

      Rain-gauge.ino: In function 'void setup()':
      Rain-gauge.ino:151:28: error: too many arguments to function 'void requestTime()'
      In file included from D:\Programs\Arduino\Sketchbook\libraries\libraries\MySensors/MySensors.h:293:0,
                   from Rain-gauge.ino:71:
      D:\Programs\Arduino\Sketchbook\libraries\libraries\MySensors/core/MySensorsCore.cpp:296:6: note: declared here
       void requestTime() {
         ^
      Rain-gauge.ino: In function 'void loop()':
      Rain-gauge.ino:323:28: error: too many arguments to function 'void requestTime()'
      In file included from D:\Programs\Arduino\Sketchbook\libraries\libraries\MySensors/MySensors.h:293:0,
                   from Rain-gauge.ino:71:
      D:\Programs\Arduino\Sketchbook\libraries\libraries\MySensors/core/MySensorsCore.cpp:296:6: note: declared here
       void requestTime() {
        ^
      too many arguments to function 'void requestTime()'
      

      Modified sketch below:

      /*
       Arduino Tipping Bucket Rain Gauge
      
       April 26, 2015
      
       Version 1.4.1 alpha
      
       Arduino Tipping Bucket Rain Gauge
      
       Utilizing a tipping bucket sensor, your Vera home automation controller and the MySensors.org
       gateway you can measure and sense local rain.  This sketch will create two devices on your
       Vera controller.  One will display your total precipitation for the last 5 days.  The other, 
       a sensor that changes state if there is recent rain (up to last 120 hours)  above a threshold.  
       Both these settings are user definable.
      
       There is a build overview video here: https://youtu.be/1eMfKQaLROo
      
       This sketch features the following:
      
       * Allows you to set the rain threshold in mm
       * Allows you to determine the tripped indicator window up to 120 hours.
       * Displays the last 5 days of rain in Variable1 through Variable5
         of the Rain Sensor device
       * Configuration changes to Sensor device updated every hour
       * Should run on any Arduino
       * Will retain Tripped/Not Tripped status and data in a power interruption, saving small amount
         of data to EEPROM (Circular Buffer to maximize life of EEPROM)
       * LED status indicator
       * Optional Temp/Humidity (DHT-22 or DHT-11) and Light LUX (BH1750) sensors. To use, uncomment
         #define DHT_ON  and/or #define LUX_ON
       * Optionally send total accumulation of each day's rainfall or send only individual days rainfall totals.
         Comment out #define USE_DAILY to display individual daily rainfall.
      
       by @BulldogLowell and @PeteWill for free public use
      
       */
      #include <SPI.h>
      #include <math.h>
      #include <Time.h>
      
      //#define NODE_ID AUTO //or AUTO to let controller assign
      #define SKETCH_NAME "Rain Gauge"
      #define SKETCH_VERSION "1.4.1a"
      #define MY_RADIO_NRF24
      
      #define DWELL_TIME 125  // this allows for radio to come back to power after a transmission, ideally 0 
      
      //#define DEBUG_ON  // comment out this line to disable serial debug
      //#define DHT_ON // uncomment out this line to enable DHT sensor
      //#define LUX_ON // uncomment out this line to enable BH1750 sensor
      //#define USE_DAILY // displays each time segment as an accumulation of prior periods inclusive.  Comment out to display individual daily rainfall totals in the variables sent to your controller.
      
      #define CALIBRATE_FACTOR 60 // amount of rain per rain bucket tip e.g. 5 is .05mm
      #define DHT_LUX_DELAY 300000  //Delay in milliseconds that the DHT and LUX sensors will wait before sending data
      
      #define CHILD_ID_RAIN_LOG 3  // Keeps track of accumulated rainfall
      #define CHILD_ID_TRIPPED_INDICATOR 4  // Indicates Tripped when rain detected
      #define EEPROM_BUFFER_LOCATION 0  // location of the EEPROM circular buffer
      #define E_BUFFER_LENGTH 240
      #define RAIN_BUCKET_SIZE 120
      
      #ifdef  DEBUG_ON
        #define DEBUG_PRINT(x)   Serial.print(x)
        #define DEBUG_PRINTLN(x) Serial.println(x)
        #define SERIAL_START(x)  Serial.begin(x)
        #else
        #define DEBUG_PRINT(x)
        #define DEBUG_PRINTLN(x)
        #define SERIAL_START(x)
      #endif
      #include <MySensors.h>
      //
      MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE);
      MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
      //
      MyMessage msgRainVAR1(CHILD_ID_RAIN_LOG, V_VAR1);
      MyMessage msgRainVAR2(CHILD_ID_RAIN_LOG, V_VAR2);
      MyMessage msgRainVAR3(CHILD_ID_RAIN_LOG, V_VAR3);
      MyMessage msgRainVAR4(CHILD_ID_RAIN_LOG, V_VAR4);
      MyMessage msgRainVAR5(CHILD_ID_RAIN_LOG, V_VAR5);
      //
      MyMessage msgTripped(CHILD_ID_TRIPPED_INDICATOR, V_TRIPPED);
      MyMessage msgTrippedVar1(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
      MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
      //
      #ifdef DHT_ON
        #include <DHT.h>
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define HUMIDITY_SENSOR_DIGITAL_PIN 8
        DHT dht;
        float lastTemp;
        float lastHum;
        boolean metric = true;
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      #endif
      //
      #ifdef LUX_ON
        //BH1750 is connected to SCL (analog input A5) and SDA (analog input A4)
        #include <BH1750.h>
        #include <Wire.h>
        #define CHILD_ID_LIGHT 2
        BH1750 lightSensor;
        MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        unsigned int lastlux;
        byte heartbeat = 10; //Used to send the light lux to gateway as soon as the device is restarted and after the DHT_LUX_DELAY has happened 10 times
      #endif
      unsigned long sensorPreviousMillis;
      int eepromIndex;
      int tipSensorPin = 3; // Pin the tipping bucket is connected to. Must be interrupt capable pin
      int ledPin = 5; // Pin the LED is connected to.  PWM capable pin required
      unsigned long dataMillis;
      unsigned long serialInterval = 600000UL;
      const unsigned long oneHour = 3600000UL;
      unsigned long lastTipTime;
      unsigned long lastRainTime; //Used for rainRate calculation
      unsigned int rainBucket [RAIN_BUCKET_SIZE] ; /* 24 hours x 5 Days = 120 hours */
      unsigned int rainRate = 0;
      byte rainWindow = 72;         //default rain window in hours.  Will be overwritten with msgTrippedVar1.
      volatile int wasTippedBuffer = 0;
      int rainSensorThreshold = 50; //default rain sensor sensitivity in hundredths.  Will be overwritten with msgTrippedVar2.
      byte state = 0;
      byte oldState = -1;
      int lastRainRate = 0;
      int lastMeasure = 0;
      boolean gotTime = false;
      byte lastHour;
      byte currentHour;
      //
      void setup()
      {
        SERIAL_START(115200);
        //
        // Set up the IO
        pinMode(tipSensorPin, INPUT_PULLUP);
        attachInterrupt (1, sensorTipped, FALLING);  // depending on location of the hall effect sensor may need CHANGE
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, HIGH);
        //
        //Let's get the controller talking to the Arduino
        //begin(getVariables, NODE_ID);
      
        //
        //Sync time with the server, this will be called hourly in order to keep time from creeping with the crystal
        //
        unsigned long functionTimeout = millis();
        while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
        {
      //    process();
          requestTime(receiveTime);
          DEBUG_PRINTLN(F("Getting Time"));
          wait(1000); // call once per second
          DEBUG_PRINTLN(F("."));
        }
        currentHour = hour();
        lastHour = hour();
        //
        //retrieve from EEPROM stored values on a power cycle.
        //
        boolean isDataOnEeprom = false;
        for (int i = 0; i < E_BUFFER_LENGTH; i++)
        {
          byte locator = loadState(EEPROM_BUFFER_LOCATION + i);
          if (locator == 0xFE)  // found the EEPROM circular buffer index
          {
            eepromIndex = EEPROM_BUFFER_LOCATION + i;
            DEBUG_PRINT(F("EEPROM Index "));
            DEBUG_PRINTLN(eepromIndex);
            //Now that we have the buffer index let's populate the rainBucket[] with data from eeprom
            loadRainArray(eepromIndex);
            isDataOnEeprom = true;
            break;
          }
        }
        //
        if (!isDataOnEeprom) // Added for the first time it is run on a new Arduino
        {
          DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0"));
          eepromIndex = EEPROM_BUFFER_LOCATION;
          saveState(eepromIndex, 0xFE);
          saveState(eepromIndex + 1, 0xFE);
          //then I will clear out any bad data
          for (int i = 2; i <= E_BUFFER_LENGTH; i++)
          {
            saveState(i, 0x00);
          }
        }
        dataMillis = millis();
        lastTipTime = millis() - oneHour; //why is this -oneHour?? Doesn't millis() start at 0 when first powered on?
        //
        request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
        wait(DWELL_TIME);
        request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
        wait(DWELL_TIME);
        //
      #ifdef DHT_ON
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        wait(DWELL_TIME);
        present(CHILD_ID_TEMP, S_TEMP);
        wait(DWELL_TIME);
        metric = getConfig().isMetric;
        .wait(DWELL_TIME);
      #endif
        //
      #ifdef LUX_ON
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        wait(DWELL_TIME);
        lightSensor.begin();
      #endif
        //
        DEBUG_PRINTLN(F("Radio Setup Complete!"));
        transmitRainData();
      }
      void presentation()
      {
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        wait(DWELL_TIME);
        present(CHILD_ID_RAIN_LOG, S_RAIN);
        wait(DWELL_TIME);
        present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
        wait(DWELL_TIME);
        DEBUG_PRINTLN(F("Sensor Presentation Complete"));
      }
      //
      void loop()
      {
      //  process();
        if (state)
        {
          prettyFade();  // breathe if tripped
        }
        else
        {
          slowFlash();   // blink if not tripped
        }
      #ifdef DEBUG_ON  // Serial Debug Block
        if ( (millis() - dataMillis) >= serialInterval)
        {
          for (int i = 24; i <= 120; i = i + 24)
          {
            updateSerialData(i);
          }
          dataMillis = millis();
        }
      #endif
        //
        // let's constantly check to see if the rain in the past rainWindow hours is greater than rainSensorThreshold
        //
        int measure = 0; // Check to see if we need to show sensor tripped in this block
        for (int i = 0; i < rainWindow; i++)
        {
          measure += rainBucket [i];
          if (measure != lastMeasure)
          {
            //      DEBUG_PRINT(F("measure value (total rainBucket within rainWindow): "));
            //      DEBUG_PRINTLN(measure);
            lastMeasure = measure;
          }
        }
        //
        state = (measure >= (rainSensorThreshold * 100));
        if (state != oldState)
        {
          send(msgTripped.set(state));
          wait(DWELL_TIME);
          DEBUG_PRINT(F("New Sensor State... Sensor: "));
          DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped");
          oldState = state;
        }
        //
        unsigned long tipDelay = millis() - lastRainTime;
        if (wasTippedBuffer) // if was tipped, then update the 24hour total and transmit to Vera
        {
          DEBUG_PRINTLN(F("Sensor Tipped"));
          DEBUG_PRINT(F("rainBucket [0] value: "));
          DEBUG_PRINTLN(rainBucket [0]);
          send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day
          wait(DWELL_TIME);
          wasTippedBuffer--;
          rainRate = ((oneHour) / tipDelay);
          if (rainRate != lastRainRate)
          {
            send(msgRainRate.set(rainRate, 1));
            wait(DWELL_TIME);
            DEBUG_PRINT(F("RainRate= "));
            DEBUG_PRINTLN(rainRate);
            lastRainRate = rainRate;
          }
          lastRainTime = lastTipTime;
        }
        //
        currentHour = hour();
        if (currentHour != lastHour)
        {
          DEBUG_PRINTLN(F("One hour elapsed."));
          send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall
          wait(DWELL_TIME);
          saveState(eepromIndex, highByte(rainBucket[0]));
          saveState(eepromIndex + 1, lowByte(rainBucket[0]));
          DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = "));
          DEBUG_PRINTLN(rainBucket[0]);
          for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array
          {
            rainBucket [i + 1] = rainBucket [i];
          }
          request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
          wait(DWELL_TIME);
          request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
          wait(DWELL_TIME);
          rainBucket[0] = 0;
          eepromIndex = eepromIndex + 2;
          if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH)
          {
            eepromIndex = EEPROM_BUFFER_LOCATION;
          }
          DEBUG_PRINT(F("Writing to EEPROM.  Index: "));
          DEBUG_PRINTLN(eepromIndex);
          saveState(eepromIndex, 0xFE);
          saveState(eepromIndex + 1, 0xFE);
          requestTime(receiveTime); // sync the time every hour
          wait(DWELL_TIME);
          transmitRainData();
          rainRate = 0;
          send(msgRainRate.set(rainRate, 1));
          wait(DWELL_TIME);
          DEBUG_PRINTLN(F("Sending rainRate is 0 to controller"));
          lastHour = currentHour;
        }
        if (millis() - sensorPreviousMillis > DHT_LUX_DELAY)
        {
          #ifdef DHT_ON  //DHT Code
            doDHT();
          #endif
          #ifdef LUX_ON
            doLUX();
          #endif
          sensorPreviousMillis = millis();
        }
      }
      //
      #ifdef DHT_ON
      void doDHT(void)
      {
        float temperature = dht.getTemperature();
          if (isnan(temperature)) 
          {
            DEBUG_PRINTLN(F("Failed reading temperature from DHT"));
          } else if (temperature != lastTemp) 
          {
            lastTemp = temperature;
            if (!metric) 
            {
              temperature = dht.toFahrenheit(temperature);
            }
            gw.send(msgTemp.set(temperature, 1));
            gw.wait(DWELL_TIME);
            DEBUG_PRINT(F("Temperature is: "));
            DEBUG_PRINTLN(temperature);
          }
          float humidity = dht.getHumidity();;
          if (isnan(humidity)) 
          {
            DEBUG_PRINTLN(F("Failed reading humidity from DHT"));
          } else if (humidity != lastHum) 
          {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
            gw.wait(DWELL_TIME);
            DEBUG_PRINT(F("Humidity is: "));
            DEBUG_PRINTLN(humidity);
          }
      }
      #endif
      //
      #ifdef LUX_ON
      void doLUX(void)
      {
        unsigned int lux = lightSensor.readLightLevel();// Get Lux value
        DEBUG_PRINT(F("Current LUX Level: "));
        DEBUG_PRINTLN(lux);
        heartbeat++;
        if (lux != lastlux || heartbeat > 10) 
        {
          gw.send(msg.set(lux));
          lastlux = lux;
        }
        if (heartbeat > 10) 
        {
          heartbeat = 0;
        }
      }
      #endif
      //
      void sensorTipped()
      {
        unsigned long thisTipTime = millis();
        if (thisTipTime - lastTipTime > 100UL)
        {
          rainBucket[0] += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
          wasTippedBuffer++;
        }
        lastTipTime = thisTipTime;
      }
      //
      int rainTotal(int hours)
      {
        int total = 0;
        for ( int i = 0; i <= hours; i++)
        {
          total += rainBucket [i];
        }
        return total;
      }
      
      void updateSerialData(int x)
      {
        DEBUG_PRINT(F("Rain last "));
        DEBUG_PRINT(x);
        DEBUG_PRINTLN(F(" hours: "));
        float tipCount = 0;
        for (int i = 0; i < x; i++)
        {
          tipCount = tipCount + rainBucket [i];
        }
        tipCount = tipCount / 100;
        DEBUG_PRINTLN(tipCount);
      }
      
      void loadRainArray(int value) // retrieve stored rain array from EEPROM on powerup
      {
        for (int i = 0; i < RAIN_BUCKET_SIZE; i++)
        {
          value = value - 2;
          if (value < EEPROM_BUFFER_LOCATION)
          {
            value = EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH;
          }
          DEBUG_PRINT(F("EEPROM location: "));
          DEBUG_PRINTLN(value);
          byte rainValueHigh = loadState(value);
          byte rainValueLow = loadState(value + 1);
          unsigned int rainValue = rainValueHigh << 8;
          rainValue |= rainValueLow;
          rainBucket[i + 1] = rainValue;
          //
          DEBUG_PRINT(F("rainBucket[ value: "));
          DEBUG_PRINT(i + 1);
          DEBUG_PRINT(F("] value: "));
          DEBUG_PRINTLN(rainBucket[i + 1]);
        }
      }
      
      void transmitRainData(void)
      {
        DEBUG_PRINT(F("In transmitRainData. currentHour = "));
        DEBUG_PRINTLN(currentHour);
        int rainUpdateTotal = 0;
        for (int i = currentHour; i >= 0; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight)
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 24; i > currentHour; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 48; i > currentHour + 24; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 72; i > currentHour + 48; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      #ifdef USE_DAILY
        rainUpdateTotal = 0;
      #endif
        for (int i = currentHour + 96; i > currentHour + 72; i--)
        {
          rainUpdateTotal += rainBucket[i];
          DEBUG_PRINT(F("Adding rainBucket["));
          DEBUG_PRINT(i);
          DEBUG_PRINTLN(F("] to rainUpdateTotal."));
        }
        DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = "));
        DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
        send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1));
        wait(DWELL_TIME);
      }
      
      void getVariables(const MyMessage &message)
      {
        if (message.sensor == CHILD_ID_RAIN_LOG)
        {
          // nothing to do here
        }
        else if (message.sensor == CHILD_ID_TRIPPED_INDICATOR)
        {
          if (message.type == V_VAR1)
          {
            rainWindow = atoi(message.data);
            if (rainWindow > 120)
            {
              rainWindow = 120;
            }
            else if (rainWindow < 1)
            {
              rainWindow = 1;
            }
            if (rainWindow != atoi(message.data))   // if I changed the value back inside the boundries, push that number back to Vera
            {
              send(msgTrippedVar1.set(rainWindow));
            }
          }
          else if (message.type == V_VAR2)
          {
            rainSensorThreshold = atoi(message.data);
            if (rainSensorThreshold > 10000)
            {
              rainSensorThreshold = 10000;
            }
            else if (rainSensorThreshold < 1)
            {
              rainSensorThreshold = 1;
            }
            if (rainSensorThreshold != atoi(message.data))  // if I changed the value back inside the boundries, push that number back to Vera
            {
              send(msgTrippedVar2.set(rainSensorThreshold));
            }
          }
        }
      }
      
      void prettyFade(void)
      {
        float val = (exp(sin(millis() / 2000.0 * PI)) - 0.36787944) * 108.0;
        analogWrite(ledPin, val);
      }
      
      void slowFlash(void)
      {
        static boolean ledState = true;
        static unsigned long pulseStart = millis();
        if (millis() - pulseStart < 100UL)
        {
          digitalWrite(ledPin, !ledState);
          pulseStart = millis();
        }
      }
      
      void receiveTime(unsigned long time)
      {
        DEBUG_PRINTLN(F("Time received..."));
        setTime(time);
        char theTime[6];
        sprintf(theTime, "%d:%2d", hour(), minute());
        DEBUG_PRINTLN(theTime);
      }
      
      posted in My Project
      niccodemi
      niccodemi
    • RE: What is the difference between arduino nano (FT232 chip) and arduino nano CH340 chip ?

      @Oitzu I am only not sure whether Vera supports CH340.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Looking for LED 7-segment cover plate

      @BartE I believe what you are looking for is called bezel - check this website.

      As for cover you could modify general pvc electric box or have one printed.

      posted in General Discussion
      niccodemi
      niccodemi
    • RE: relay 2 or 4 or 8 channel ?!

      @Reza below is example for 4 channel relay

      #define NUMBER_OF_RELAYS 4

      It is that simple. If you will use this sketch then connect relays to pins 3, 4, 5 and 6.
      You will be able to control each relay independently.
      Relay actuator sketch allows you to control relays only via controller ie Veralite. Relay actuator with button sketch allows you to control relays via controller AND physical button (light switch).

      posted in My Project
      niccodemi
      niccodemi
    • RE: relay 2 or 4 or 8 channel ?!

      @reza if you are looking for solution to control relays without buttons then you can use default mysensors relay-actuator sketch.

      You only need to change this line according to the number of relays you want to control (this will work with 2 and 4 channel relays).

      #define NUMBER_OF_RELAYS 1 // Total number of attached relays

      For 8 channel I think you would need custom sketch.
      Check this thread. Sketch posted there allows you to assign individual pins.

      posted in My Project
      niccodemi
      niccodemi
    • RE: 433MHz Motion Sensor sketch

      @BartE noted, I didn't actually plan to run this node off a battery but I thought it was a good practice to use sleep() (with interrupt) in nodes which are not expecting messages from gw.

      One more thing: if using array when presenting children

      present(i, S_MOTION);
      

      messages are sent to gw one after another and even with only 4 children at least one gets usually lost. Is there alternative to this?

      present(1, S_MOTION);
        wait(50);
        present(2, S_MOTION);
        wait(50);
        present(3, S_MOTION);
        wait(50);
        present(4, S_MOTION);
        wait(50);
      
      posted in Development
      niccodemi
      niccodemi
    • RE: 433MHz Motion Sensor sketch

      @BartE thanks. Second sensor actually wouldn't even trigger while the first one was triggered (1 second).

      Would you know how to enable sleep-time in this sketch? I tried defining Interrupt on pin 2 but I get strange results (RF codes are randomly received and messages are rarely sent).

      /*
      433MHz Multi Motion Sensor
       * Setup:
       * - connect a 433MHz receiver on digital pin 2.
       * - type appropriate RF codes into array, define noMotion and timetrigger1
      */
      #define MY_DEBUG
      
      #define MY_RADIO_NRF24
      
      #include <RemoteReceiver.h>
      #include <InterruptChain.h>
      #include <SPI.h>
      #include <MySensor.h>
      
      //unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      
      //#define INTERRUPT 2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define noMotion 4                                                           //number of sensors
      const unsigned long RFCODE[] = {354240, 354222, 354216, 354214};              //RF433 codes
      #define CHILD_ID 1   // Id of the sensor child
      
      // Initialize motion message
      MyMessage msg[noMotion];
      
      unsigned long newCodeReceived = 0;
      
      long previousMillis = 0;
      long interval = 120000;                                          //interval at which to send Heartbeat
      
      void setup() {
        Serial.begin(115200);
        // Interrupt -1 to indicate you will call the interrupt handler with InterruptChain
        RemoteReceiver::init(-1, 2, showOldCode);
        // On interrupt, call the interrupt handlers of remote and sensor receivers
        InterruptChain::addInterruptCallback(0, RemoteReceiver::interruptHandler);
        Serial.print("433 Motion Sensor");
        wait(30);
          // initialize Motion sensors 
        for (int i=0; i<noMotion; i++){
          msg[i].sensor = i;          // initialize messages
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          msg[i].type = V_TRIPPED;
      }
      }
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("433 Motion Sensor", "1.0b");
        wait(50);
        // Register all sensors to gw (they will be created as child devices)
        for (int i=0; i<noMotion; i++) {
        present(i, S_MOTION);
        wait(50);
      }
      }
      
      unsigned long timeTrigger1[] = {0, 0, 0, 0};                // same as noMotion
      
      void loop() {
            for (int i=0; i<noMotion; i++) {
            // shows the received code sent from an old-style remote switch
            unsigned long value = RFCODE[i];
            if(newCodeReceived == value) {
                if (timeTrigger1[i] == 0) {
                    send(msg[i].set("1"));  // Send tripped value to gw 
                }
                newCodeReceived = 0;
                timeTrigger1[i] = millis();
            }
            if (timeTrigger1[i] > 0 && (millis() - timeTrigger1[i]) > 1000) {
               // Not tripped for over 1 second tell the GW
               send(msg[i].set("0"));
               timeTrigger1[i] = 0;
            }      
            // Give some time to MySensor  to procces messages
            wait(10);
      }
      {
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval) {
               sendHeartbeat();
               previousMillis = currentMillis;
               }
               }
      }
      
      void showOldCode(unsigned long receivedCode, unsigned int period) {
        // shows the received code sent from an old-style remote switch
        // Print the received code.
        Serial.print("Code: ");
        Serial.print(receivedCode);
        Serial.print(", period: ");
        Serial.print(period);
        Serial.println("us.");
      
        // Read digital motion value
         newCodeReceived = receivedCode;
          // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        //sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: 433MHz Motion Sensor sketch

      I figured out array and the sketch works. As final thing I would like to enable sleep-time and Heartbeat message once node wakes up.

      /*
      433MHz Multi Motion Sensor
       * Setup:
       * - connect a 433MHz receiver on digital pin 2.
       * - type appropriate RF codes into array
      */
      #define MY_DEBUG
      
      #define MY_RADIO_NRF24
      
      #include <RemoteReceiver.h>
      #include <InterruptChain.h>
      #include <SPI.h>
      #include <MySensor.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      
      //#define INTERRUPT 2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define noMotion 4                                                                                                     //number of sensors
      const unsigned long RFCODE[] = {354240, 354222, 354216, 354214};              //RF433 codes
      #define CHILD_ID 1   // Id of the sensor child
      
      // Initialize motion message
      MyMessage msg[noMotion];
      
      unsigned long newCodeReceived = 0;
      
      long previousMillis = 0;
      long interval = 120000;                                          //interval at which to send Heartbeat
      
      void setup() {
        Serial.begin(115200);
        // Interrupt -1 to indicate you will call the interrupt handler with InterruptChain
        RemoteReceiver::init(-1, 2, showOldCode);
        // On interrupt, call the interrupt handlers of remote and sensor receivers
        InterruptChain::addInterruptCallback(0, RemoteReceiver::interruptHandler);
        Serial.print("433 Motion Sensor");
        wait(30);
          // initialize Motion sensors 
        for (int i=0; i<noMotion; i++){
          msg[i].sensor = i;          // initialize messages
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          msg[i].type = V_TRIPPED;
      }
      }
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("433 Motion Sensor", "1.0b");
        wait(50);
        // Register all sensors to gw (they will be created as child devices)
        for (int i=0; i<noMotion; i++) {
        present(i, S_MOTION);
        wait(50);
      }
      }
      
      unsigned long timeTrigger1 = 0;
      
      void loop() {
            for (int i=0; i<noMotion; i++) {
            // shows the received code sent from an old-style remote switch
            unsigned long value = RFCODE[i];
            if(newCodeReceived == value) {
                if (timeTrigger1 == 0) {
                    send(msg[i].set("1"));  // Send tripped value to gw 
                }
                newCodeReceived = 0;
                timeTrigger1 = millis();
            }
            if (timeTrigger1 > 0 && (millis() - timeTrigger1) > 1000) {
               // Not tripped for over 1 second tell the GW
               send(msg[i].set("0"));
               timeTrigger1 = 0;
            }      
            // Give some time to MySensor  to procces messages
            wait(10);
      }
      {
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval) {
               sendHeartbeat();
               previousMillis = currentMillis;
               }
               }
      }
      
      void showOldCode(unsigned long receivedCode, unsigned int period) {
        // shows the received code sent from an old-style remote switch
        // Print the received code.
        Serial.print("Code: ");
        Serial.print(receivedCode);
        Serial.print(", period: ");
        Serial.print(period);
        Serial.println("us.");
      
        // Read digital motion value
         newCodeReceived = receivedCode;
          // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        //sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: 433MHz Motion Sensor sketch

      @BartE thank you. I modified sketch (the one with millis) and it works great. How would I enable sleep mode with interrupt?

      Eventually I plan to add more motion sensors and I think it would be better to use array. This is my first attempt and below is how far I got but obviously something is missing because I cannot compile it; I get error: "msg" cannot be used as function

      /*
      433MHz Motion Sensor
       * Setup:
       * - connect a 433MHz receiver on digital pin 2.
       *
       * MySensor note: This example has not yet been adopted but can be used as an example
       * of receiving 433Mhz stuff. 
       * 
       * One idea could be to echo received 433 codes back to gateway to be able to pick up and
       * handle data over there.
       *
      */
      #define MY_DEBUG
      
      #define MY_RADIO_NRF24
      
      #include <RemoteReceiver.h>
      #include <InterruptChain.h>
      #include <SPI.h>
      #include <MySensor.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      
      //#define INTERRUPT 2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define noMotion 4
      const int RFCODE[] = {354240, 123654, 123789, 123954};  
      #define CHILD_ID 1   // Id of the sensor child
      
      // Initialize motion message
      MyMessage msg[noMotion];
      
      unsigned long newCodeReceived = 0;
      
      void setup() {
        Serial.begin(115200);
        // Interrupt -1 to indicate you will call the interrupt handler with InterruptChain
        RemoteReceiver::init(-1, 2, showOldCode);
        // On interrupt, call the interrupt handlers of remote and sensor receivers
        InterruptChain::addInterruptCallback(0, RemoteReceiver::interruptHandler);
        Serial.print("433 Motion Sensor");
        wait(30);
          // initialize Motion sensors 
        for (int i=1; i<=noMotion; i++){
          msg[i].sensor = i;          // initialize messages
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          msg[i].type = V_TRIPPED;
      }
      }
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("433 Motion Sensor", "1.0a");
      
        // Register all sensors to gw (they will be created as child devices)
        for (int i=1; i<=noMotion; i++) {
        present(i, S_MOTION);
        wait(30);
      }
      }
      
      unsigned long timeTrigger1 = 0;
      //unsigned long timeTrigger2 = 0;
      
      void loop() {
            for (int i=1; i<=noMotion; i++) {
            // shows the received code sent from an old-style remote switch
            if(newCodeReceived == RFCODE[i]) {
                if (timeTrigger1 == 0) {
                    send(msg(i).set("1"));  // Send tripped value to gw 
                }
                newCodeReceived = 0;
                timeTrigger1 = millis();
            }
            if (timeTrigger1 > 0 && (millis() - timeTrigger1) > 1000) {
               // Not tripped for over 1 second tell the GW
               send(msg(i).set("0"));
               timeTrigger1 = 0;
            }      
            // Give some time to MySensor  to procces messages
            wait(10);
      }
      }
      
      void showOldCode(unsigned long receivedCode, unsigned int period) {
        // shows the received code sent from an old-style remote switch
        // Print the received code.
        Serial.print("Code: ");
        Serial.print(receivedCode);
        Serial.print(", period: ");
        Serial.print(period);
        Serial.println("us.");
      
        // Read digital motion value
         newCodeReceived = receivedCode;
         sendHeartbeat();
          // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        //sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: 433MHz Motion Sensor sketch

      @BartE yes, I tried. If I change delay to wait the sketch compiles and I can upload it. After node receives 433 sensor input node sends out tripped value 1 and then stops responding (I have to reboot it). I guess the issue is because of using "wait(1000)" outside of void loop function?

      posted in Development
      niccodemi
      niccodemi
    • 433MHz Motion Sensor sketch

      I would like to reuse 433MHz Motion sensors from old security alarm system. I connected 433MHz receiver to pin number 2 on arduino nano and combined Motion sensor and RF433 sketches. To my initial surprise sketch actually works; I would only need help with following items:

      -how would I enable sleep mode?

      -delay(1000) between sending tripped value of 1 and 0 doesn't work. That means that regardless of what value is delay node sends value 1 and 0 immediately one after another - that doesn't present the issue in itself but because of short period between messages, second message gets lost sometimes.

      -is it ok that function Void loop remains blank? How would I modify sketch to get function "void showoldcode" into "void loop" (if this makes sense at all)?

      /*
      433MHz Motion Sensor
       * Setup:
       * - connect a 433MHz receiver on digital pin 2.
       *
       * MySensor note: This example has not yet been adopted but can be used as an example
       * of receiving 433Mhz stuff. 
       * 
       * One idea could be to echo received 433 codes back to gateway to be able to pick up and
       * handle data over there.
       *
      */
      #define MY_DEBUG
      
      #define MY_RADIO_NRF24
      
      #include <RemoteReceiver.h>
      #include <InterruptChain.h>
      #include <SPI.h>
      #include <MySensor.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      
      //#define INTERRUPT 2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define CHILD_ID_1 1   // Id of the sensor child
      #define CHILD_ID_2 2   // Id of the sensor child
      
      // Initialize motion message
      MyMessage msg1(CHILD_ID_1, V_TRIPPED);
      MyMessage msg2(CHILD_ID_2, V_TRIPPED);
      
      void setup() {
        Serial.begin(115200);
      
        // Interrupt -1 to indicate you will call the interrupt handler with InterruptChain
        RemoteReceiver::init(-1, 2, showOldCode);
      
        // On interrupt, call the interrupt handlers of remote and sensor receivers
        InterruptChain::addInterruptCallback(0, RemoteReceiver::interruptHandler);
        Serial.print("433 Motion Sensor");
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("433 Motion Sensor", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_1, S_MOTION);
        present(CHILD_ID_2, S_MOTION);
      }
      
      void loop() {
         // You can do other stuff here!
      // shows the received code sent from an old-style remote switch
      }
      
      void showOldCode(unsigned long receivedCode, unsigned int period) {
        // Print the received code.
        Serial.print("Code: ");
        Serial.print(receivedCode);
        Serial.print(", period: ");
        Serial.print(period);
        Serial.println("us.");
      
        // Read digital motion value
        //boolean tripped = receivedCode; 
        
        if(receivedCode == 510217) {
                send(msg1.set("1"));  // Send tripped value to gw 
                delay(1000);
                send(msg1.set("0"));
            }
      if(receivedCode == 354240) {
                send(msg2.set("1"));  // Send tripped value to gw 
                delay(1000);
                send(msg2.set("0"));
            }
      
          // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        //sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: Gateway status down

      @eccle Is Mycontroller installed on Linux or Windows system? If Windows, then set port as "COMxx" (xx=number).

      posted in MyController.org
      niccodemi
      niccodemi
    • RE: Array Relay Button Actuator

      @martinhjelmare

      That was it. After I amended sketch according to your advise all the random state changes disappeared. I rebooted node over 20 times in various button / relay states and it always started with relays in correct position. For anyone else interested below is amended sketch.

      //MultiRelayButton Sketch, MySensors 1.6, toggle switch
      
      #define MY_RADIO_NRF24
      
      #define MY_REPEATER_FEATURE
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #define RELAY_ON 0                      // switch around for ACTIVE LOW / ACTIVE HIGH relay
      #define RELAY_OFF 1
      //
      
      #define noRelays 2                     //2-4
      const int relayPin[] = {14,15};          //  switch around pins to your desire
      const int buttonPin[] = {3,4};      //  switch around pins to your desire
      
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
      public:                                      
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays]; 
      Bounce debouncer[noRelays];
      MyMessage msg[noRelays];
      
      void setup(){
          sendHeartbeat();
          wait(100);
          // Initialize Relays with corresponding buttons
          for (int i = 0; i < noRelays; i++){
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msg[i].sensor = i;                                   // initialize messages
          msg[i].type = V_LIGHT;   
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          wait(100);
          pinMode(Relays[i].relayPin, OUTPUT);
          Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
          send(msg[i].set(Relays[i].relayState? true : false));                  // make controller aware of last status  
          wait(50);
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(20);
          wait(50);
          }
      }
      void presentation()  {
            sendSketchInfo("MultiRelayButton", "0.9t");
            wait(100);
            for (int i = 0; i < noRelays; i++)
            present(i, S_LIGHT);                               // present sensor to gateway
            wait(100);
      }
      void loop()
      {
          for (byte i = 0; i < noRelays; i++) {
              if (debouncer[i].update()) {
                  Relays[i].relayState = !Relays[i].relayState;
                  digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
                  send(msg[i].set(Relays[i].relayState? true : false));
                  // save sensor state in EEPROM (location == sensor number)
                  saveState( i, Relays[i].relayState );
              }                 
          }
          wait(20);
      }
      // process incoming message 
      void receive(const MyMessage &message){        
         if (message.type == V_LIGHT){ 
         if (message.sensor <noRelays){            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
         Relays[message.sensor].relayState = message.getBool(); 
         digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
         saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
         }
        }
        wait(20);
      }
      
      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Array Relay Button Actuator

      @martinhjelmare @BartE thank you both for trying to solve this issue but the problem is still there. On reboot relay (usually just 1 never both) gets set randomly in loop function (setup function always restores correct state). I also tried increasing debouncer up to 500 without success. And I am also sure this is not hardware related because if I load sketch which is meant for momentary switch relays work as expected (tested with 10 consecutive reboots). Just to be on the same page this is latest sketch:

      //MultiRelayButton Sketch, MySensors 1.6
      
      #define MY_RADIO_NRF24
      
      #define MY_REPEATER_FEATURE
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #define RELAY_ON 0                      // switch around for realy HIGH/LOW state
      #define RELAY_OFF 1
      //
      
      #define noRelays 2                     //2-4
      const int relayPin[] = {14,15};          //  switch around pins to your desire
      const int buttonPin[] = {3,4};      //  switch around pins to your desire
      
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
      public:                                      
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        //byte oldValue;                    // last Values for key (debounce)
        boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays]; 
      Bounce debouncer[noRelays];
      MyMessage msg[noRelays];
      
      void setup(){
          sendHeartbeat();
          wait(250);
          // Initialize Relays with corresponding buttons
          for (int i = 0; i < noRelays; i++){
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msg[i].sensor = i;                                   // initialize messages
          msg[i].type = V_LIGHT;
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(100);
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          wait(250);
          pinMode(Relays[i].relayPin, OUTPUT);
          //Relays[i].oldValue = digitalRead(Relays[i].buttonPin);
          Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
          send(msg[i].set(Relays[i].relayState? true : false));                  // make controller aware of last status  
          wait(250);
          }
      }
      void presentation()  {
            sendSketchInfo("MultiRelayButton", "0.9k");
            wait(250);
            for (int i = 0; i < noRelays; i++)
            present(i, S_LIGHT);                               // present sensor to gateway
            wait(250);
      }
      void loop()
      {
          for (byte i = 0; i < noRelays; i++) {
              if (debouncer[i].update()) {
                  Relays[i].relayState = !Relays[i].relayState;
                  digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
                  send(msg[i].set(Relays[i].relayState? true : false));
                  // save sensor state in EEPROM (location == sensor number)
                  saveState( i, Relays[i].relayState );
              }                 
          }
          wait(50);
      }
      // process incoming message 
      void receive(const MyMessage &message){        
         if (message.type == V_LIGHT){ 
         if (message.sensor <noRelays){            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
         Relays[message.sensor].relayState = message.getBool(); 
         digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
         saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
         }
        }
        wait(50);
      }
      
      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Remote Access

      @cjm4909 it is very easy if you just open the port of your Mycontroller web address (default 8443) on your router. If you've got dynamic IP from your ISP you can always apply for ddns provider.

      posted in MyController.org
      niccodemi
      niccodemi
    • RE: Array Relay Button Actuator

      @martinhjelmare

      Ok, there is an improvement. Relays now turn to same state as they were before reboot most of the time but not always. Sometimes they inverse - the one which was OFF turns ON and vice-versa. Sometimes (1 in 3) they switch ON and OFF (only for split second) in the loop function. See below screenshots:

      reboot3

      reboot4

      This sketch is used with toggle button, same as on this photo.

      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Array Relay Button Actuator

      @martinhjelmare

      thanks, I understand what you mean but I don't know how to write it in sketch.

      I tried inserting

      Relays[i].oldValue = Relays[i].relayState;
      

      at the end of Void Setup section but then sketch wouldn't compile. I get "name lookup of 'i' changed 'for' ISO for scoping [-fpermissive]" error. I get same error if I substitute Relays[i].relayState with loadstate.

      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Simple detector that detects "breaking of a line"

      @Cliff-Karlsson I use active beam detector. Power is needed on both sides though but if that is an issue you can always use mirror on the other side. In my experience these things are very sensitive in short ranges (below 5m). More expensive models let you adjust trigger time too.

      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Array Relay Button Actuator

      @jeylites Thanks, toggle switch works but there is issue when node boots / restarts. On 1st restart relays stay OFF, on 2nd come ON, on 3rd again OFF and so on. It seems that whatever happens during Setup is reversed in Loop. Hopefully someone can point out what should be changed in modified sketch.

      #define MY_RADIO_NRF24
      
      #define MY_REPEATER_FEATURE
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #define RELAY_ON 0                      // switch around for realy HIGH/LOW state
      #define RELAY_OFF 1
      //
      
      #define noRelays 2                     //2-4
      const int relayPin[] = {14,15};          //  switch around pins to your desire
      const int buttonPin[] = {3,4};      //  switch around pins to your desire
      
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
      public:                                      
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        byte oldValue;                    // last Values for key (debounce)
        boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays]; 
      Bounce debouncer[noRelays];
      MyMessage msg[noRelays];
      
      void setup(){
          sendHeartbeat();
          wait(250);
          // Initialize Relays with corresponding buttons
          for (int i = 0; i < noRelays; i++){
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msg[i].sensor = i;                                   // initialize messages
          msg[i].type = V_LIGHT;
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(5);
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          //digitalWrite(Relays[i].relayPin, RELAY_OFF);
          wait(250);
          pinMode(Relays[i].relayPin, OUTPUT);
          Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
          send(msg[i].set(Relays[i].relayState? true : false));                  // make controller aware of last status  
          wait(250);
          }
      }
      void presentation()  {
            sendSketchInfo("MultiRelayButton", "0.9g");
            wait(250);
            for (int i = 0; i < noRelays; i++)
            present(i, S_LIGHT);                               // present sensor to gateway
      }
      void loop()
          {
          for (byte i = 0; i < noRelays; i++){
          debouncer[i].update();
          byte value = debouncer[i].read();
          if (value != Relays[i].oldValue){
          Relays[i].relayState = !Relays[i].relayState;
          digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
          send(msg[i].set(Relays[i].relayState? true : false));
          saveState( i, Relays[i].relayState );}                 // save sensor state in EEPROM (location == sensor number)
          
              Relays[i].oldValue = value;      
          }
      }
      // process incoming message 
      void receive(const MyMessage &message){        
         if (message.type == V_LIGHT){ 
         if (message.sensor <noRelays){            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
         Relays[message.sensor].relayState = message.getBool(); 
         digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
         saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
         }
        }
      }
      

      these are screenshots from restarts

      reboot1

      reboot2

      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Array Relay Button Actuator

      @Cliff-Karlsson I recently started using 1.6 version, below is converted sketch. It works with momentary (pushbuttons) switches only.

      Does anyone have sketch for toggle switches?

      #define MY_RADIO_NRF24
      
      #define MY_REPEATER_FEATURE
      
      #include <MySensor.h>
      
      #include <SPI.h>
      #include <Bounce2.h>
      #define RELAY_ON 0                      // switch around for relay HIGH/LOW state
      #define RELAY_OFF 1
      //
      
      #define noRelays 2                     //2-4
      const int relayPin[] = {14,15};          //  switch around pins to your desire
      const int buttonPin[] = {3,4};      //  switch around pins to your desire
      
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
      public:                                      
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        byte oldValue;                    // last Values for key (debounce)
        boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays]; 
      Bounce debouncer[noRelays];
      MyMessage msg[noRelays];
      
      void setup(){
          sendHeartbeat();
          wait(250);
          // Initialize Relays with corresponding buttons
          for (int i = 0; i < noRelays; i++){
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msg[i].sensor = i;                                   // initialize messages
          msg[i].type = V_LIGHT;
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(5);
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          //digitalWrite(Relays[i].relayPin, RELAY_OFF);
          wait(250);
          pinMode(Relays[i].relayPin, OUTPUT);
          Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
          send(msg[i].set(Relays[i].relayState? true : false));                  // make controller aware of last status  
          wait(250);
          }
      }
      void presentation()  {
            sendSketchInfo("MultiRelayButton", "0.9f");
            wait(250);
            for (int i = 0; i < noRelays; i++)
            present(i, S_LIGHT);                               // present sensor to gateway
      }
      void loop()
          {
          for (byte i = 0; i < noRelays; i++){
          debouncer[i].update();
          byte value = debouncer[i].read();
          if (value != Relays[i].oldValue && value==0){
          Relays[i].relayState = !Relays[i].relayState;
          digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
          send(msg[i].set(Relays[i].relayState? true : false));
          saveState( i, Relays[i].relayState );}                 // save sensor state in EEPROM (location == sensor number)
          
              Relays[i].oldValue = value;      
          }
      }
      // process incoming message 
      void receive(const MyMessage &message){        
         if (message.type == V_LIGHT){ 
         if (message.sensor <noRelays){            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
         Relays[message.sensor].relayState = message.getBool(); 
         digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
         saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
         }
        }
      }
      
      posted in General Discussion
      niccodemi
      niccodemi
    • RE: Combining multiple sensors into one sketch

      @stubtoe check this thread

      posted in My Project
      niccodemi
      niccodemi
    • RE: REQUEST: Tutorial/Step-by-step to install MySys bootloader

      @drock1985 once you flashed node with mysbootloader you cannot use Arduino IDE to upload sketches anymore. You have to do it via Myscontroller app (OTA).

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Windows GUI/Controller for MySensors

      @p0lar are you still able to remotely reboot node?

      posted in Controllers
      niccodemi
      niccodemi
    • RE: REQUEST: Tutorial/Step-by-step to install MySys bootloader

      Check this instructable.

      You can use Arduino as ISP to burn Mysbootloader.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Relay_Actuator add second relay?

      Check this thread

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Windows GUI/Controller for MySensors

      @petewill thanks, I tried ch77 and it works great.

      posted in Controllers
      niccodemi
      niccodemi
    • RE: Windows GUI/Controller for MySensors

      @petewill did you have any success finding out how to change default channel?

      posted in Controllers
      niccodemi
      niccodemi
    • RE: Windows GUI/Controller for MySensors

      in firmware_config.csv file what is the first column "type" for? And where do I get "type" codes?

      posted in Controllers
      niccodemi
      niccodemi
    • RE: wireless serial communication

      @siklosi thanks, so that means this module would be only good for serial monitor? Is it possible to do serial monitoring with mysbootloader / myscontroller? I am currently using serial gw with vera - if I am to use myscontroller do I have to disconnect it from vera and connect it with computer running myscontroller?

      posted in Hardware
      niccodemi
      niccodemi
    • wireless serial communication

      Everytime I want to modify / update sketch I have to either remove arduino from it's location and bring it over to PC or use laptop (if location permits). Would it be possible to use this module for serial communication (monitoring and uploading sketches)? Or is there any other alternative?

      posted in Hardware
      niccodemi
      niccodemi
    • RE: Relay actuator + water meter pulse sensor sketch

      @tbully thanks, just what I was looking for.

      posted in Development
      niccodemi
      niccodemi
    • Relay actuator + water meter pulse sensor sketch

      I would like to combine relay actuator and water meter pulse sensor sketch . I merged the code from original examples, I can upload sketch but something must be wrong because only one device gets created in Vera. Gateway is version 1.5 and arduino 1.6.5

      #include <MySensor.h>  
      #include <SPI.h>
      #include <MySigningNone.h>
      #include <MyTransportNRF24.h>
      #include <MyTransportRFM69.h>
      #include <MyHwATMega328.h>
      
      #define DIGITAL_INPUT_SENSOR 5                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
      #define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2        // Usually the interrupt = pin -2 (on uno/nano anyway)
      
      #define PULSE_FACTOR 1000                       // Nummber of blinks per m3 of your meter (One rotation/liter)
      
      #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
      
      #define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.
      
      #define CHILD_ID 1                              // Id of the sensor child
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      unsigned long SEND_FREQUENCY = 30000;           // Minimum time between send (in milliseconds). We don't want to spam the gateway.
      
      MySensor gw;
      MyMessage flowMsg(CHILD_ID,V_FLOW);
      MyMessage volumeMsg(CHILD_ID,V_VOLUME);
      MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
      MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
      MyHwATMega328 hw;
      
      double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter
      
      volatile unsigned long pulseCount = 0;   
      volatile unsigned long lastBlink = 0;
      volatile double flow = 0;  
      boolean pcReceived = false;
      unsigned long oldPulseCount = 0;
      unsigned long newBlink = 0;   
      double oldflow = 0;
      double volume =0;                     
      double oldvolume =0;
      unsigned long lastSend =0;
      unsigned long lastPulse =0;
      
      void setup()  
      {  
       gw.begin(incomingMessage); 
      
       // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion) 
       pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
       
       // Send the sketch version information to the gateway and Controller
       gw.sendSketchInfo("Watermeter-Relay", "1.0");
      
       // Register this device as Waterflow sensor
       gw.present(CHILD_ID, S_WATER);       
      
       pulseCount = oldPulseCount = 0;
      
       // Fetch last known pulse count value from gw
       gw.request(CHILD_ID, V_VAR1);
      
       lastSend = lastPulse = millis();
      
       attachInterrupt(SENSOR_INTERRUPT, onPulse, FALLING);
       // Fetch relay status
       for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
         // Register all sensors to gw (they will be created as child devices)
         gw.present(sensor, S_LIGHT);
         // Then set relay pins in output mode
         pinMode(pin, OUTPUT);   
         // Set relay to last known state (using eeprom storage) 
         digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
       }
      }
      
      
      void loop()     
      { 
       gw.process();
       unsigned long currentTime = millis();
       
         // Only send values at a maximum frequency or woken up from sleep
       if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY))
       {
         lastSend=currentTime;
         
         if (!pcReceived) {
           //Last Pulsecount not yet received from controller, request it again
           gw.request(CHILD_ID, V_VAR1);
           return;
         }
      
         if (!SLEEP_MODE && flow != oldflow) {
           oldflow = flow;
      
           Serial.print("l/min:");
           Serial.println(flow);
      
           // Check that we dont get unresonable large flow value. 
           // could hapen when long wraps or false interrupt triggered
           if (flow<((unsigned long)MAX_FLOW)) {
             gw.send(flowMsg.set(flow, 2));                   // Send flow value to gw
           }  
         }
       
         // No Pulse count received in 2min 
         if(currentTime - lastPulse > 120000){
           flow = 0;
         } 
      
         // Pulse count has changed
         if ((pulseCount != oldPulseCount)||(!SLEEP_MODE)) {
           oldPulseCount = pulseCount;
      
           Serial.print("pulsecount:");
           Serial.println(pulseCount);
      
           gw.send(lastCounterMsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
      
           double volume = ((double)pulseCount/((double)PULSE_FACTOR));     
           if ((volume != oldvolume)||(!SLEEP_MODE)) {
             oldvolume = volume;
      
             Serial.print("volume:");
             Serial.println(volume, 3);
             
             gw.send(volumeMsg.set(volume, 3));               // Send volume value to gw
           } 
         }
       }
       if (SLEEP_MODE) {
         gw.sleep(SEND_FREQUENCY);
       }
      }
      
      void incomingMessage(const MyMessage &message) {
       if (message.type==V_VAR1) {
         unsigned long gwPulseCount=message.getULong();
         pulseCount += gwPulseCount;
         flow=oldflow=0;
         Serial.print("Received last pulse count from gw:");
         Serial.println(pulseCount);
         pcReceived = true;
        
       // We only expect one type of message from controller. But we better check anyway.
       if (message.type==V_LIGHT) {
          // Change relay state
          digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
          // Store state in eeprom
          gw.saveState(message.sensor, message.getBool());
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        } 
       }
      }
      
      void onPulse()     
      {
       if (!SLEEP_MODE)
       {
         unsigned long newBlink = micros();   
         unsigned long interval = newBlink-lastBlink;
         
         if (interval!=0)
         {
           lastPulse = millis();
           if (interval<500000L) {
             // Sometimes we get interrupt on RISING,  500000 = 0.5sek debounce ( max 120 l/min)
             return;   
           }
           flow = (60000000.0 /interval) / ppl;
         }
         lastBlink = newBlink;
       }
       pulseCount++; 
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: Relay actuator sketch - auto off function

      @Dwalt initially I tried with Vera and Rfxtrx433 but only later I learned there are many different coding systems on 433 Mhz and many (including Lightning4) are not supported in Rfxtrx plugin. I wanted to try with arduino + 433 transmitter but about same time I found out about mysensors and abandoned 433+arduino altogether. That said I've still got couple 433 mhz controlled switches and I want to integrate them to Vera-Mysensors environment. Until now I thought that the only option is to use relay. I would be interested to try other solutions.

      posted in Development
      niccodemi
      niccodemi
    • RE: Relay actuator sketch - auto off function

      @BulldogLowell it is remote control fob similar to this one. It uses 12 volt battery (27A).

      posted in Development
      niccodemi
      niccodemi
    • RE: Relay actuator sketch - auto off function

      @BulldogLowell I tested it today and it works as expected.

      On the hardware side do you think it would make more sense to use transistor instead of relay (since I am dealing only with 12 volts)?

      posted in Development
      niccodemi
      niccodemi
    • RE: Relay actuator sketch - auto off function

      @BulldogLowell thanks again.

      posted in Development
      niccodemi
      niccodemi
    • RE: Relay actuator sketch - auto off function

      1 arduino with 2 relays attached (each relay on different pin).

      posted in Development
      niccodemi
      niccodemi
    • RE: Relay actuator sketch - auto off function

      @BulldogLowell thanks, initially I want to use 2 relays.

      posted in Development
      niccodemi
      niccodemi
    • Relay actuator sketch - auto off function

      I would like to control simple 12v 433 mhz remote control using relay. The thing is that relay needs to close only for half a second and then open again (just enough to send pulse out). It would be possible to create a scene in vera but due to very short response time I think it would be better to do this on node itself. There is similar functionality on Fibaro wall module (auto-off function).

      Not sure how to modify code - add delay and reverse previous state?

      void loop() 
      {
        // Alway process incoming messages whenever possible
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LIGHT) {
           // Change relay state
           digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           // Store state in eeprom
           gw.saveState(message.sensor, message.getBool());
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: Out of memory in pressureSensor example

      @portals I had same issue - see this thread.

      Download latest library, disable debug and follow @BulldogLowell advice. I managed to get dynamic memory to 75% and that seems sufficient - it has been running for a week now without issues.

      posted in Bug Reports
      niccodemi
      niccodemi
    • RE: Trouble flashing Arduino Pro Mini with a sketch

      @CaptainZap FTDI recently released driver update with intent to disable fake ftdi chips.

      There is a solution.

      posted in Hardware
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      thanks, pressure sensors works ok with updated code (7 hours now).

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      pressure sensor and radio are powered off Nano. There is capacitor on radio vcc / gnd pins. I will try simple sketch and report back.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @hek sure, I can try. Do you have anything specific in mind?

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      I tried IDE 1.0.5 and codebender with same results - sensor stops responding after 3-4 hours. Is anyone running this sensor successfully?
      Upon searching for arduino board with more SRAM I found arduino micro. It has 2.5 KB SRAM (0.5 KB more than Nano). Would it work with Mysensors?

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @BulldogLowell So which IDE are you using now? I can try with the same version. What is your dynamic memory usage?

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @BulldogLowell I used F() on all Serialprints("") and I got below sketch size. What is your dynamic memory usage?

      pressure.jpg

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @BulldogLowell just noticed that if I don't use PROGMEM then F() macro compiles ok.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @BulldogLowell only things modified now are: disabled DEBUG in Myconfig.h and replaced PROGMEM line you suggested earlier. If I try to use F() I get compiling error. This is on IDE 1.5.8 and Nano 328.

      Sketch uses 18,002 bytes. Global variables use 1616 bytes (78%). I still get low memory warning.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @BulldogLowell can I change any other line with PROGMEM? After changing one you suggested I got 1% more.

      F() macro doesn't compile.

      press1.jpg

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Pressure sensor - arduino low memory (SOLVED)

      @BulldogLowell I will try your suggestions. It's for Nano.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • Pressure sensor - arduino low memory (SOLVED)

      When I compile pressure sensor sketch I get below error in Arduino IDE.

      pressure.jpg

      I can add it to Vera but it only works for few hours (3-4) and then stops responding. I tried disabling DEBUG but that didn't help (it did reduce storage space).

      Is there anything else to do in order to reduce dynamic memory usage?

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: implementing multiple sensors

      @BulldogLowell no, they were both defined as 0. I changed them to 1 and 2 and now three devices show up. Thanks.

      posted in Development
      niccodemi
      niccodemi
    • RE: implementing multiple sensors

      @hek @BulldogLowell UV sensor works fine as standalone sensor / node. After trying different things I noticed that if I switch order of

      these lines

        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        gw.present(CHILD_ID_UV, S_UV);
        
      

      to these below

        gw.present(CHILD_ID_UV, S_UV);
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      

      then node and UV sensor show up in vera, but lux light is missing. It seems that sensor presented 1st gets recognized but second one omitted. Could it have to do anything with both devices using analog pins?

      lux-uv.jpg

      posted in Development
      niccodemi
      niccodemi
    • RE: implementing multiple sensors

      One more combined sketch - UV / Light Lux. Everything seems to work ok except only 2 items show up in vera: node and lux sensor. UV sensor is missing.

      serial output

      sensor started, id 6
      send: 6-6-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
      send: 6-6-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
      read: 0-0-6 s=255,c=3,t=6,pt=0,l=1:M
      send: 6-6-0-0 s=255,c=3,t=11,pt=0,l=13,st=ok:UV/Lux Sensor
      send: 6-6-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
      send: 6-6-0-0 s=0,c=0,t=16,pt=0,l=5,st=ok:1.4.1
      send: 6-6-0-0 s=0,c=0,t=11,pt=0,l=5,st=ok:1.4.1
      Lux reading: 48
      send: 6-6-0-0 s=0,c=1,t=23,pt=7,l=5,st=ok:48.0
      Uv reading: 583
      Uv index: 5
      send: 6-6-0-0 s=0,c=1,t=11,pt=7,l=5,st=ok:5.0
      

      sketch code

      /*
        Vera Arduino BH1750FVI Light sensor
        communicate using I2C Protocol
        this library enable 2 slave device addresses
        Main address  0x23
        secondary address 0x5C
        connect the sensor as follows :
        Light sensor
        VCC  >>> 5V
        Gnd  >>> Gnd
        ADDR >>> NC or GND  
        SCL  >>> A5
        SDA  >>> A4
        
        UV sensor
        VCC  >>> 5V
        Gnd  >>> Gnd
        OUT  >>> A3
        Contribution: idefix
       
      */
      
      #include <SPI.h>
      #include <MySensor.h>  
      #include <BH1750.h>
      #include <Wire.h> 
      
      #define CHILD_ID_LIGHT 0
      #define CHILD_ID_UV 0
      #define LIGHT_SENSOR_ANALOG_PIN 0
      #define UV_SENSOR_ANALOG_PIN 3
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      BH1750 lightSensor;
      MySensor gw;
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      MyMessage uvMsg(CHILD_ID_UV, V_UV);
      uint16_t lastlux;
      int lastUV = -1;
      int uvIndexValue [13] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170, 3000};
      int uvIndex;
      
      void setup()  
      { 
        gw.begin();
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("UV/Lux Sensor", "1.0");
        // Register all sensors to gateway (they will be created as child devices)
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        gw.present(CHILD_ID_UV, S_UV);
        
        lightSensor.begin();
      }
      
      void loop()      
      {     
        uint16_t lux = lightSensor.readLightLevel();// Get Lux value
        Serial.print("Lux reading: ");
        Serial.println(lux);
        if (lux != lastlux) {
            gw.send(msg.set(lux, 1));
            lastlux = lux;
        }
        uint16_t uv = analogRead(0);// Get UV value
        Serial.print("Uv reading: ");
        Serial.println(uv);
        for (int i = 0; i < 13; i++)
        {
          if (uv <= uvIndexValue[i]) 
          {
            uvIndex = i;
            break;
          }
        }
        Serial.print("Uv index: ");
        Serial.println(uvIndex);
      
        if (uvIndex != lastUV) {
            gw.send(uvMsg.set(uvIndex, 1));
            lastUV = uvIndex;
        }
        gw.sleep(SLEEP_TIME);
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: Well I'm lost

      good to hear that you got it working. Let us know how it goes on ui7.

      posted in Vera
      niccodemi
      niccodemi
    • RE: INA219 DC Current Sensor

      @jeylites said:

      Has anyone made any progress implementing the AC current sensor or is there a My Sensor plugin?

      +1 I would be also interested in AC current sensor.

      posted in Hardware
      niccodemi
      niccodemi
    • RE: Binary / Temp sensor help - sleep time

      @BulldogLowell thank you, I uploaded it and so far it works fine.

      posted in Development
      niccodemi
      niccodemi
    • RE: Serial Gateway halt!

      @dzairo I believe it is possible to use it stand-alone but with very limited functionality and possibly code modification. See this and this thread for more info.

      posted in Development
      niccodemi
      niccodemi
    • RE: Serial Gateway halt!

      which controller do you use?

      posted in Development
      niccodemi
      niccodemi
    • Binary / Temp sensor help - sleep time

      I combined temp and binary (2x) sketches.
      All works ok if I remove "sleep time" but in this case I get flooded with temperature sensor data.
      If "sleep time" is used then binary switches don't change states.

      How to amend sketch to send temp to gw at certain interval ie 30 seconds?

           // 2x binary switch + dallas temp example 
           // Connect button or door/window reed switch between 
           // digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND.
          // Connect dallas temp sensor to digital pin 3
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      
      #define CHILD_ID_4 4
      #define CHILD_ID_5 5
      #define BUTTON_PIN_4  4  // Arduino Digital I/O pin for button/reed switch
      #define BUTTON_PIN_5  5  // Arduino Digital I/O pin for button/reed switch
      #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
      #define MAX_ATTACHED_DS18B20 16
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      OneWire oneWire(ONE_WIRE_BUS);
      DallasTemperature sensors(&oneWire);
      MySensor gw;
      Bounce debouncer = Bounce(); 
      Bounce debouncer_2 = Bounce();
      int oldValue=-1;
      int oldValue_2 =-1;
      float lastTemperature[MAX_ATTACHED_DS18B20];
      int numSensors=0;
      boolean receivedConfig = false;
      boolean metric = true; 
      // Initialize temperature message
      MyMessage msg(0,V_TEMP);
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg4(CHILD_ID_4,V_TRIPPED);
      MyMessage msg5(CHILD_ID_5,V_TRIPPED);
      
      void setup()  
      {  
        // Startup OneWire 
        sensors.begin();
        // Startup and initialize MySensors library. Set callback for incoming messages. 
        gw.begin();
        
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Door/Temp", "1.0");
        
        // Fetch the number of attached temperature sensors  
        numSensors = sensors.getDeviceCount();
      
        // Present all sensors to controller
        for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
           gw.present(i, S_TEMP);
        }
      
       // Setup the button
        pinMode(BUTTON_PIN_4,INPUT);
        pinMode(BUTTON_PIN_5,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_4,HIGH);
        digitalWrite(BUTTON_PIN_5,HIGH);
        
        // After setting up the button, setup debouncer
        debouncer.attach(BUTTON_PIN_4);
        debouncer.interval(5);
        debouncer_2.attach(BUTTON_PIN_5);
        debouncer_2.interval(5);
        
        // 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.
        gw.present(CHILD_ID_4, S_DOOR);  
        gw.present(CHILD_ID_5, S_DOOR);  
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop() 
      {
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
       
        if (value != oldValue) {
           // Send in the new value
           gw.send(msg4.set(value==HIGH ? 1 : 0));
           oldValue = value;
        }
        debouncer_2.update();
        // Get the update value
        int value_2 = debouncer_2.read();
       
        if (value_2 != oldValue_2) {
           // Send in the new value
           gw.send(msg5.set(value_2==HIGH ? 1 : 0));
           oldValue_2 = value_2;
        }
       // Process incoming messages (like config from server)
        gw.process(); 
      
        // Fetch temperatures from Dallas sensors
        sensors.requestTemperatures(); 
      
        // Read temperatures and send them to controller 
        for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
       
          // Fetch and round temperature to one decimal
          float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
       
          // Only send data if temperature has changed and no error
          if (lastTemperature[i] != temperature && temperature != -127.00) {
       
            // Send in the new temperature
            gw.send(msg.setSensor(i).set(temperature,1));
            lastTemperature[i]=temperature;
          }
        }
        gw.sleep(SLEEP_TIME);
      } 
      
      posted in Development
      niccodemi
      niccodemi
    • RE: implementing multiple sensors

      @pgo thanks, all sensors show up now.

      posted in Development
      niccodemi
      niccodemi
    • RE: Serial Gateway halt!

      can you post screenshot of Mysensors plugin? you have to give us more information ie controller type. you should connect serial gateway to computer and check serial monitor in arduino ide.

      posted in Development
      niccodemi
      niccodemi
    • RE: Vera Plugin does not start inclusion

      You Nano isn't properly communicating with Vera that's why you don't get Lib version. Are you using any other usb device with vera?

      From my experience using clones for gateway is a hit and miss. After few months I had enough and bought gravitech nano which is connected to vera via powered usb hub. It has been rock steady since I plugged it in.

      posted in Vera
      niccodemi
      niccodemi
    • RE: implementing multiple sensors

      I combined Humidity and Lux code. Serial monitor works ok (see below) but for some reason when I try to add node to Vera I get only node, temp and lux (no humidity). I guess something is wrong in combined sketch?

      serial monitor

      sensor started, id 1
      send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
      send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
      read: 0-0-1 s=255,c=3,t=6,pt=0,l=1:M
      send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Humidity/Lux
      send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
      send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=5,st=ok:1.4.1
      send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=5,st=ok:1.4.1
      send: 1-1-0-0 s=2,c=0,t=16,pt=0,l=5,st=ok:1.4.1
      send: 1-1-0-0 s=1,c=1,t=0,pt=7,l=5,st=ok:28.6
      T: 28.60
      send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,st=ok:61.8
      H: 61.80
      2
      send: 1-1-0-0 s=2,c=1,t=23,pt=3,l=2,st=ok:2
      2
      

      sketch

      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h> 
      #include <BH1750.h>
      #include <Wire.h> 
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_LIGHT 2
      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      #define LIGHT_SENSOR_ANALOG_PIN 0
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      BH1750 lightSensor;
      MySensor gw;
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      uint16_t lastlux;
      
      
      void setup()  
      { 
        gw.begin();
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Humidity/Lux", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        
        metric = gw.getConfig().isMetric;
        lightSensor.begin();
      }
      
      void loop()      
      {  
        delay(dht.getMinimumSamplingPeriod());
      
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperature != lastTemp) {
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum) {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }     
        uint16_t lux = lightSensor.readLightLevel();// Get Lux value
        Serial.println(lux);
        if (lux != lastlux) {
            gw.send(msg.set(lux));
            lastlux = lux;
        }
        
      
        gw.sleep(SLEEP_TIME); //sleep a bit
      }
      
      posted in Development
      niccodemi
      niccodemi
    • RE: [SOLVED] Problems with Ethernet Gateway (Arduino Ethernet Shield)

      @hek please check below post; where should pins be changed if not in config file?

      http://forum.mysensors.org/topic/466/ethernet-gateway-problem/24

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Vera Plugin does not start inclusion

      Can you post screenshot of Mysensors plugin? have you tried with another browser?

      posted in Vera
      niccodemi
      niccodemi
    • RE: Communication problem (maybe)

      @Hausner do you have any issues with relay node if you are NOT using it also as repeater?

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Vera Plugin does not start inclusion

      is your Nano authentic or clone?

      posted in Vera
      niccodemi
      niccodemi
    • RE: Communication problem (maybe)

      @Hausner yes, arduino and relay share ground. I use this node solely as relay (not repeater) and still have issues.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Communication problem (maybe)

      Same here, relay is powered separately.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Communication problem (maybe)

      @Hausner I've got same issues with relay nodes. Other sensor nodes work ok.

      See this post for my serial output. At first I thought this is because of ethernet gw but now I am having similar issues with serial gw. I can switch relay on/off few times but after that node stops responding.

      posted in Troubleshooting
      niccodemi
      niccodemi
    • RE: Well I'm lost

      @5546dug I guess you are uploading wrong files or something is wrong with vera. Did you try removing Mysensors plugin and rebooting (not just reloading) vera before uploading new files?

      Anyway if you want to remove files from vera check this thread and this one on how to get your ssh password. Maybe you could also ask MIOS support to remove files for you.

      posted in Vera
      niccodemi
      niccodemi
    • RE: Well I'm lost

      @5546dug said:

      just thinking out loud Would this be best done using chrome or internet explorer browser?
      I downloaded the zip from gitrepo with chrome but may have used ie to upload to veralite.
      Issues?

      I don't think it should matter.

      posted in Vera
      niccodemi
      niccodemi
    • RE: Well I'm lost

      @5546dug Delete Mysensors plugin. You don't have to delete lua files from Vera; just upload new ones (from previous link).

      As for deleting files from vera I believe you would have to ssh in vera.

      arrow.jpg

      posted in Vera
      niccodemi
      niccodemi
    • RE: Well I'm lost

      @5546dug did you download Vera files from this website? There is "Download ZIP" button on the right side. Extract those files and upload one by one to Veralite. After that is done you should have Mysensors plugin under your Devices tab (same as on photo below except Lib version should stay blank until Veralite starts communicating with serial gateway).

      vera.jpg

      posted in Vera
      niccodemi
      niccodemi
    • RE: Ethernet gateway troubleshooting advice

      @ntruchsess are you using serial or ethernet gw? I still have issues with relays and ethernet gw (W5100). Have you tested ENC28J60 with new code and 1.4.1 library?

      posted in Troubleshooting
      niccodemi
      niccodemi