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

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Conversion from 1.5.4 to 2.1.1.

Conversion from 1.5.4 to 2.1.1.

Scheduled Pinned Locked Moved General Discussion
10 Posts 3 Posters 1.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • DickD Offline
    DickD Offline
    Dick
    wrote on last edited by
    #1

    I am converting all my nodes to 2.1.1 because they are not visible in the Domoticz so I think I have re adjust them all. Is there a central place where the conversion is explained? I found already a lot of info on this forum. Now I have a questions what can I do with the row:
    gw.begin(incomingMessage, AUTO, true);
    I changed it already in
    begin(recieve,AUTO, true);
    But get an erro "begin was not declared in the scope.
    What must I do?

    1 Reply Last reply
    0
    • scalzS Offline
      scalzS Offline
      scalz
      Hardware Contributor
      wrote on last edited by scalz
      #2

      Not easy to say without your sketch..

      But I think that you may miss the "s" in

      #include <MySensors.h>  
      

      For more infos, you can take a look here:

      • https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x
      • MySensors examples
      DickD 1 Reply Last reply
      0
      • scalzS scalz

        Not easy to say without your sketch..

        But I think that you may miss the "s" in

        #include <MySensors.h>  
        

        For more infos, you can take a look here:

        • https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x
        • MySensors examples
        DickD Offline
        DickD Offline
        Dick
        wrote on last edited by
        #3

        @scalz thanks for the link, that was the one I used also. Perhaps you can do something with the whole script in the part void presentation (3rd row)

        // 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 <MySensors.h>
        #include <SPI.h>
        #include <Bounce2.h>
        #include <DallasTemperature.h>
        #include <OneWire.h>
        #define DIGITAL_MOTION_SENSOR 2
        #define CHILD_ID_MOTION 6
        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
        #define MAX_ATTACHED_DS18B20 16
        #define RELAY_ON 1                      // switch around for realy HIGH/LOW state
        #define RELAY_OFF 0
        
        Bounce motionsDebouncer = Bounce();
        
        int lastMOTION;
        unsigned long SLEEP_TIME = 420000;
        //unsigned long SLEEP_TIME = 3000;
        unsigned long blockMotionTimer = 0;
        
        
        OneWire oneWire(ONE_WIRE_BUS);
        DallasTemperature sensors(&oneWire);
        
        //#define noRelays 3
        //const int relayPin[] = {A1, A4, A5}; //  switch around pins to your desire
        //const int buttonPin[] = {6, 7, 8}; //  switch around pins to your desire
        #define noRelays 1
        const int relayPin[] = {A1}; //  switch around pins to your desire
        const int buttonPin[] = {6}; //  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 debouncerRELAY[noRelays];
        MyMessage msgRELAY[noRelays];
        
        
        float lastTemperature[MAX_ATTACHED_DS18B20];
        int numSensors=0;
        boolean receivedConfig = false;
        boolean metric = true; 
        MyMessage msg(0,V_TEMP);
        MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED);
        
        void presentation()  
        {  
          sensors.begin();
          begin(receive, AUTO, true);
          sendSketchInfo("Motion/Temp/relay", "1.0");
          numSensors = sensors.getDeviceCount();
          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) 
          {   
            present(i, S_TEMP);
          }
        
        
         
        pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP);      // sets the motion sensor digital pin as input
          motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);
          motionsDebouncer.interval(400);
          // Register all sensors to gw (they will be created as child devices)
          present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);
        
           for (int i = 0; i < noRelays; i++)
          {
            Relays[i].buttonPin = buttonPin[i];              // assign physical pins
            Relays[i].relayPin = relayPin[i];
            msgRELAY[i].sensor = i;                                   // initialize messages
            msgRELAY[i].type = V_LIGHT;
            debouncerRELAY[i] = Bounce();                        // initialize debouncer
            debouncerRELAY[i].attach(buttonPin[i]);
            debouncerRELAY[i].interval(5);
            pinMode(Relays[i].buttonPin, INPUT_PULLUP);
            pinMode(Relays[i].relayPin, OUTPUT);
            Relays[i].relayState = gw.loadState(i);                               // retrieve last values from EEPROM
            digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
            send(msgRELAY[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
            present(i, S_LIGHT);                               // present sensor to gateway
            delay(250);
        
          }
            
        }
        void loop() 
        {
        //process(); 
        
        for (byte i = 0; i < noRelays; i++)
          {
            debouncerRELAY[i].update();
            byte value = debouncerRELAY[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(msgRELAY[i].set(Relays[i].relayState ? true : false));
              saveState( i, Relays[i].relayState );
            }                 // save sensor state in EEPROM (location == sensor number)
        
            Relays[i].oldValue = value;
          }
          
          if (blockMotionTimer == 0) {
            if (motionsDebouncer.update()) {
                int value = motionsDebouncer.read();
                Serial.println( "PIR " + (String)value );
                send( msgMOTION.set( value ), true ); // Also it might need inverted value
                blockMotionTimer = (millis() + SLEEP_TIME);
           }
        } else {
                motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires 
                if (blockMotionTimer < millis()) {
                    blockMotionTimer = 0;
                }
        }
         
         
          
          updateTemperature(30);// update time in seconds
          
        }
        
        void updateTemperature(int frequency)
        {
          static unsigned long lastUpdateTime;
          if (millis() - lastUpdateTime >= frequency * 1000UL)
          {
            sensors.requestTemperatures(); 
            for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) 
            {
              float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
              if (lastTemperature[i] != temperature && temperature != -127.00) 
              {
                send(msg.setSensor(i).set(temperature,1));
                lastTemperature[i]=temperature;
              }
            }
            lastUpdateTime += frequency * 1000UL;
          }
        }
        
        //void incomingMessage(const MyMessage &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
              gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
            }
          }
        //gw.wait(50);
        
        }
        
        1 Reply Last reply
        0
        • scalzS Offline
          scalzS Offline
          scalz
          Hardware Contributor
          wrote on last edited by
          #4

          you don't need to use begin() with 2.x. It's explained in the link above ;) Take a look at the examples in case

          DickD 2 Replies Last reply
          0
          • scalzS scalz

            you don't need to use begin() with 2.x. It's explained in the link above ;) Take a look at the examples in case

            DickD Offline
            DickD Offline
            Dick
            wrote on last edited by
            #5

            @scalz That is a good idea, totaly forgotten:cyclone:

            1 Reply Last reply
            0
            • scalzS scalz

              you don't need to use begin() with 2.x. It's explained in the link above ;) Take a look at the examples in case

              DickD Offline
              DickD Offline
              Dick
              wrote on last edited by
              #6

              @scalz I changed everything as mentioned before. I uploaded to my Nano but I see nothing in the serial monitor. I hope it is my last queation:
              the code is until now:

              In// 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 <MySensors.h>
              #include <SPI.h>
              #include <Bounce2.h>
              #include <DallasTemperature.h>
              #include <OneWire.h>
              #define MY_RADIO_NRF24
              #define DIGITAL_MOTION_SENSOR 2
              #define CHILD_ID_MOTION 6
              #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
              #define MAX_ATTACHED_DS18B20 16
              #define RELAY_ON 1                      // switch around for realy HIGH/LOW state
              #define RELAY_OFF 0
              
              Bounce motionsDebouncer = Bounce();
              
              int lastMOTION;
              unsigned long SLEEP_TIME = 420000;
              //unsigned long SLEEP_TIME = 3000;
              unsigned long blockMotionTimer = 0;
              
              
              OneWire oneWire(ONE_WIRE_BUS);
              DallasTemperature sensors(&oneWire);
              
              //#define noRelays 3
              //const int relayPin[] = {A1, A4, A5}; //  switch around pins to your desire
              //const int buttonPin[] = {6, 7, 8}; //  switch around pins to your desire
              #define noRelays 1
              const int relayPin[] = {A1}; //  switch around pins to your desire
              const int buttonPin[] = {6}; //  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 debouncerRELAY[noRelays];
              MyMessage msgRELAY[noRelays];
              
              
              float lastTemperature[MAX_ATTACHED_DS18B20];
              int numSensors=0;
              boolean receivedConfig = false;
              boolean metric = true; 
              MyMessage msg(0,V_TEMP);
              MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED);
              
              void presentation()  
              {  
                //sensors.begin();
                //begin receive, AUTO, true;
                sendSketchInfo("Motion/Temp/relay", "1.0");
                numSensors = sensors.getDeviceCount();
                for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) 
                {   
                  present(i, S_TEMP);
                }
              
              
               
              pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP);      // sets the motion sensor digital pin as input
                motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);
                motionsDebouncer.interval(400);
                // Register all sensors to gw (they will be created as child devices)
                present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);
              
                 for (int i = 0; i < noRelays; i++)
                {
                  Relays[i].buttonPin = buttonPin[i];              // assign physical pins
                  Relays[i].relayPin = relayPin[i];
                  msgRELAY[i].sensor = i;                                   // initialize messages
                  msgRELAY[i].type = V_LIGHT;
                  debouncerRELAY[i] = Bounce();                        // initialize debouncer
                  debouncerRELAY[i].attach(buttonPin[i]);
                  debouncerRELAY[i].interval(5);
                  pinMode(Relays[i].buttonPin, INPUT_PULLUP);
                  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(msgRELAY[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
                  present(i, S_LIGHT);                               // present sensor to gateway
                  delay(250);
              
                }
                  
              }
              void loop() 
              {
              
              
              for (byte i = 0; i < noRelays; i++)
                {
                  debouncerRELAY[i].update();
                  byte value = debouncerRELAY[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(msgRELAY[i].set(Relays[i].relayState ? true : false));
                    saveState( i, Relays[i].relayState );
                  }                 // save sensor state in EEPROM (location == sensor number)
              
                  Relays[i].oldValue = value;
                }
                
                if (blockMotionTimer == 0) {
                  if (motionsDebouncer.update()) {
                      int value = motionsDebouncer.read();
                      Serial.println( "PIR " + (String)value );
                      send( msgMOTION.set( value ), true ); // Also it might need inverted value
                      blockMotionTimer = (millis() + SLEEP_TIME);
                 }
              } else {
                      motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires 
                      if (blockMotionTimer < millis()) {
                          blockMotionTimer = 0;
                      }
              }
               
               
                
                updateTemperature(30);// update time in seconds
                
              }
              
              void updateTemperature(int frequency)
              {
                static unsigned long lastUpdateTime;
                if (millis() - lastUpdateTime >= frequency * 1000UL)
                {
                  sensors.requestTemperatures(); 
                  for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) 
                  {
                    float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                    if (lastTemperature[i] != temperature && temperature != -127.00) 
                    {
                      send(msg.setSensor(i).set(temperature,1));
                      lastTemperature[i]=temperature;
                    }
                  }
                  lastUpdateTime += frequency * 1000UL;
                }
              }
              
              //void incomingMessage(const MyMessage &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)
                  }
                }
              //gw.wait(50);
              
              }
              `
              DickD 1 Reply Last reply
              0
              • scalzS Offline
                scalzS Offline
                scalz
                Hardware Contributor
                wrote on last edited by
                #7

                in the link i provided above, at the 2nd line..

                "It is important to do these defines before including MySensors.h, otherwise they will go unnoticed when the library evaluates which parts to include."

                1 Reply Last reply
                0
                • DickD Dick

                  @scalz I changed everything as mentioned before. I uploaded to my Nano but I see nothing in the serial monitor. I hope it is my last queation:
                  the code is until now:

                  In// 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 <MySensors.h>
                  #include <SPI.h>
                  #include <Bounce2.h>
                  #include <DallasTemperature.h>
                  #include <OneWire.h>
                  #define MY_RADIO_NRF24
                  #define DIGITAL_MOTION_SENSOR 2
                  #define CHILD_ID_MOTION 6
                  #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                  #define MAX_ATTACHED_DS18B20 16
                  #define RELAY_ON 1                      // switch around for realy HIGH/LOW state
                  #define RELAY_OFF 0
                  
                  Bounce motionsDebouncer = Bounce();
                  
                  int lastMOTION;
                  unsigned long SLEEP_TIME = 420000;
                  //unsigned long SLEEP_TIME = 3000;
                  unsigned long blockMotionTimer = 0;
                  
                  
                  OneWire oneWire(ONE_WIRE_BUS);
                  DallasTemperature sensors(&oneWire);
                  
                  //#define noRelays 3
                  //const int relayPin[] = {A1, A4, A5}; //  switch around pins to your desire
                  //const int buttonPin[] = {6, 7, 8}; //  switch around pins to your desire
                  #define noRelays 1
                  const int relayPin[] = {A1}; //  switch around pins to your desire
                  const int buttonPin[] = {6}; //  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 debouncerRELAY[noRelays];
                  MyMessage msgRELAY[noRelays];
                  
                  
                  float lastTemperature[MAX_ATTACHED_DS18B20];
                  int numSensors=0;
                  boolean receivedConfig = false;
                  boolean metric = true; 
                  MyMessage msg(0,V_TEMP);
                  MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED);
                  
                  void presentation()  
                  {  
                    //sensors.begin();
                    //begin receive, AUTO, true;
                    sendSketchInfo("Motion/Temp/relay", "1.0");
                    numSensors = sensors.getDeviceCount();
                    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) 
                    {   
                      present(i, S_TEMP);
                    }
                  
                  
                   
                  pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP);      // sets the motion sensor digital pin as input
                    motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);
                    motionsDebouncer.interval(400);
                    // Register all sensors to gw (they will be created as child devices)
                    present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);
                  
                     for (int i = 0; i < noRelays; i++)
                    {
                      Relays[i].buttonPin = buttonPin[i];              // assign physical pins
                      Relays[i].relayPin = relayPin[i];
                      msgRELAY[i].sensor = i;                                   // initialize messages
                      msgRELAY[i].type = V_LIGHT;
                      debouncerRELAY[i] = Bounce();                        // initialize debouncer
                      debouncerRELAY[i].attach(buttonPin[i]);
                      debouncerRELAY[i].interval(5);
                      pinMode(Relays[i].buttonPin, INPUT_PULLUP);
                      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(msgRELAY[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
                      present(i, S_LIGHT);                               // present sensor to gateway
                      delay(250);
                  
                    }
                      
                  }
                  void loop() 
                  {
                  
                  
                  for (byte i = 0; i < noRelays; i++)
                    {
                      debouncerRELAY[i].update();
                      byte value = debouncerRELAY[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(msgRELAY[i].set(Relays[i].relayState ? true : false));
                        saveState( i, Relays[i].relayState );
                      }                 // save sensor state in EEPROM (location == sensor number)
                  
                      Relays[i].oldValue = value;
                    }
                    
                    if (blockMotionTimer == 0) {
                      if (motionsDebouncer.update()) {
                          int value = motionsDebouncer.read();
                          Serial.println( "PIR " + (String)value );
                          send( msgMOTION.set( value ), true ); // Also it might need inverted value
                          blockMotionTimer = (millis() + SLEEP_TIME);
                     }
                  } else {
                          motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires 
                          if (blockMotionTimer < millis()) {
                              blockMotionTimer = 0;
                          }
                  }
                   
                   
                    
                    updateTemperature(30);// update time in seconds
                    
                  }
                  
                  void updateTemperature(int frequency)
                  {
                    static unsigned long lastUpdateTime;
                    if (millis() - lastUpdateTime >= frequency * 1000UL)
                    {
                      sensors.requestTemperatures(); 
                      for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) 
                      {
                        float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                        if (lastTemperature[i] != temperature && temperature != -127.00) 
                        {
                          send(msg.setSensor(i).set(temperature,1));
                          lastTemperature[i]=temperature;
                        }
                      }
                      lastUpdateTime += frequency * 1000UL;
                    }
                  }
                  
                  //void incomingMessage(const MyMessage &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)
                      }
                    }
                  //gw.wait(50);
                  
                  }
                  `
                  DickD Offline
                  DickD Offline
                  Dick
                  wrote on last edited by
                  #8

                  @Dick I hope it is the last time to keep you involved, still nothing in the serial Monitor. For a test I loaded an Example and that showed up in the monitor. Any idea?

                  In// 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
                  
                  #define MY_RADIO_NRF24
                  #define DIGITAL_MOTION_SENSOR 2
                  #define CHILD_ID_MOTION 6
                  #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                  #define MAX_ATTACHED_DS18B20 16
                  #define noRelays 1
                  #define RELAY_ON 1                      // switch around for realy HIGH/LOW state
                  #define RELAY_OFF 0
                  
                  #include <MySensors.h>
                  #include <SPI.h>
                  #include <Bounce2.h>
                  #include <DallasTemperature.h>
                  #include <OneWire.h>
                  
                  Bounce motionsDebouncer = Bounce();
                  
                  int lastMOTION;
                  unsigned long SLEEP_TIME = 420000;
                  //unsigned long SLEEP_TIME = 3000;
                  unsigned long blockMotionTimer = 0;
                  
                  
                  OneWire oneWire(ONE_WIRE_BUS);
                  DallasTemperature sensors(&oneWire);
                  
                  //#define noRelays 3
                  //const int relayPin[] = {A1, A4, A5}; //  switch around pins to your desire
                  //const int buttonPin[] = {6, 7, 8}; //  switch around pins to your desire
                  const int relayPin[] = {A1}; //  switch around pins to your desire
                  const int buttonPin[] = {6}; //  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 debouncerRELAY[noRelays];
                  MyMessage msgRELAY[noRelays];
                  
                  
                  float lastTemperature[MAX_ATTACHED_DS18B20];
                  int numSensors = 0;
                  boolean receivedConfig = false;
                  boolean metric = true;
                  MyMessage msg(0, V_TEMP);
                  MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED);
                  
                  void presentation()
                  {
                    //sensors.begin();
                    //begin receive, AUTO, true;
                    sendSketchInfo("Motion/Temp/relay", "1.0");
                    numSensors = sensors.getDeviceCount();
                    for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++)
                    {
                      present(i, S_TEMP);
                    }
                  
                    pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP);      // sets the motion sensor digital pin as input
                    motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);
                    motionsDebouncer.interval(400);
                    // Register all sensors to gw (they will be created as child devices)
                    present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);
                  
                    for (int i = 0; i < noRelays; i++)
                    {
                      Relays[i].buttonPin = buttonPin[i];              // assign physical pins
                      Relays[i].relayPin = relayPin[i];
                      msgRELAY[i].sensor = i;                                   // initialize messages
                      msgRELAY[i].type = V_LIGHT;
                      debouncerRELAY[i] = Bounce();                        // initialize debouncer
                      debouncerRELAY[i].attach(buttonPin[i]);
                      debouncerRELAY[i].interval(5);
                      pinMode(Relays[i].buttonPin, INPUT_PULLUP);
                      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(msgRELAY[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
                      present(i, S_LIGHT);                               // present sensor to gateway
                      delay(250);
                  
                    }
                  
                  }
                  void loop()
                  {
                  
                  
                    for (byte i = 0; i < noRelays; i++)
                    {
                      debouncerRELAY[i].update();
                      byte value = debouncerRELAY[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(msgRELAY[i].set(Relays[i].relayState ? true : false));
                        saveState( i, Relays[i].relayState );
                      }                 // save sensor state in EEPROM (location == sensor number)
                  
                      Relays[i].oldValue = value;
                    }
                  
                    if (blockMotionTimer == 0) {
                      if (motionsDebouncer.update()) {
                        int value = motionsDebouncer.read();
                        Serial.println( "PIR " + (String)value );
                        send( msgMOTION.set( value ), true ); // Also it might need inverted value
                        blockMotionTimer = (millis() + SLEEP_TIME);
                      }
                    } else {
                      motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires
                      if (blockMotionTimer < millis()) {
                        blockMotionTimer = 0;
                      }
                    }
                  
                  
                  
                    updateTemperature(30);// update time in seconds
                  
                  }
                  
                  void updateTemperature(int frequency)
                  {
                    static unsigned long lastUpdateTime;
                    if (millis() - lastUpdateTime >= frequency * 1000UL)
                    {
                      sensors.requestTemperatures();
                      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++)
                      {
                        float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;
                        if (lastTemperature[i] != temperature && temperature != -127.00)
                        {
                          send(msg.setSensor(i).set(temperature, 1));
                          lastTemperature[i] = temperature;
                        }
                      }
                      lastUpdateTime += frequency * 1000UL;
                    }
                  }
                  
                  //void incomingMessage(const MyMessage &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)
                      }
                    }
                    //gw.wait(50);
                  
                  }
                  `
                  korttomaK 1 Reply Last reply
                  0
                  • DickD Dick

                    @Dick I hope it is the last time to keep you involved, still nothing in the serial Monitor. For a test I loaded an Example and that showed up in the monitor. Any idea?

                    In// 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
                    
                    #define MY_RADIO_NRF24
                    #define DIGITAL_MOTION_SENSOR 2
                    #define CHILD_ID_MOTION 6
                    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                    #define MAX_ATTACHED_DS18B20 16
                    #define noRelays 1
                    #define RELAY_ON 1                      // switch around for realy HIGH/LOW state
                    #define RELAY_OFF 0
                    
                    #include <MySensors.h>
                    #include <SPI.h>
                    #include <Bounce2.h>
                    #include <DallasTemperature.h>
                    #include <OneWire.h>
                    
                    Bounce motionsDebouncer = Bounce();
                    
                    int lastMOTION;
                    unsigned long SLEEP_TIME = 420000;
                    //unsigned long SLEEP_TIME = 3000;
                    unsigned long blockMotionTimer = 0;
                    
                    
                    OneWire oneWire(ONE_WIRE_BUS);
                    DallasTemperature sensors(&oneWire);
                    
                    //#define noRelays 3
                    //const int relayPin[] = {A1, A4, A5}; //  switch around pins to your desire
                    //const int buttonPin[] = {6, 7, 8}; //  switch around pins to your desire
                    const int relayPin[] = {A1}; //  switch around pins to your desire
                    const int buttonPin[] = {6}; //  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 debouncerRELAY[noRelays];
                    MyMessage msgRELAY[noRelays];
                    
                    
                    float lastTemperature[MAX_ATTACHED_DS18B20];
                    int numSensors = 0;
                    boolean receivedConfig = false;
                    boolean metric = true;
                    MyMessage msg(0, V_TEMP);
                    MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED);
                    
                    void presentation()
                    {
                      //sensors.begin();
                      //begin receive, AUTO, true;
                      sendSketchInfo("Motion/Temp/relay", "1.0");
                      numSensors = sensors.getDeviceCount();
                      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++)
                      {
                        present(i, S_TEMP);
                      }
                    
                      pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP);      // sets the motion sensor digital pin as input
                      motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);
                      motionsDebouncer.interval(400);
                      // Register all sensors to gw (they will be created as child devices)
                      present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);
                    
                      for (int i = 0; i < noRelays; i++)
                      {
                        Relays[i].buttonPin = buttonPin[i];              // assign physical pins
                        Relays[i].relayPin = relayPin[i];
                        msgRELAY[i].sensor = i;                                   // initialize messages
                        msgRELAY[i].type = V_LIGHT;
                        debouncerRELAY[i] = Bounce();                        // initialize debouncer
                        debouncerRELAY[i].attach(buttonPin[i]);
                        debouncerRELAY[i].interval(5);
                        pinMode(Relays[i].buttonPin, INPUT_PULLUP);
                        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(msgRELAY[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
                        present(i, S_LIGHT);                               // present sensor to gateway
                        delay(250);
                    
                      }
                    
                    }
                    void loop()
                    {
                    
                    
                      for (byte i = 0; i < noRelays; i++)
                      {
                        debouncerRELAY[i].update();
                        byte value = debouncerRELAY[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(msgRELAY[i].set(Relays[i].relayState ? true : false));
                          saveState( i, Relays[i].relayState );
                        }                 // save sensor state in EEPROM (location == sensor number)
                    
                        Relays[i].oldValue = value;
                      }
                    
                      if (blockMotionTimer == 0) {
                        if (motionsDebouncer.update()) {
                          int value = motionsDebouncer.read();
                          Serial.println( "PIR " + (String)value );
                          send( msgMOTION.set( value ), true ); // Also it might need inverted value
                          blockMotionTimer = (millis() + SLEEP_TIME);
                        }
                      } else {
                        motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires
                        if (blockMotionTimer < millis()) {
                          blockMotionTimer = 0;
                        }
                      }
                    
                    
                    
                      updateTemperature(30);// update time in seconds
                    
                    }
                    
                    void updateTemperature(int frequency)
                    {
                      static unsigned long lastUpdateTime;
                      if (millis() - lastUpdateTime >= frequency * 1000UL)
                      {
                        sensors.requestTemperatures();
                        for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++)
                        {
                          float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;
                          if (lastTemperature[i] != temperature && temperature != -127.00)
                          {
                            send(msg.setSensor(i).set(temperature, 1));
                            lastTemperature[i] = temperature;
                          }
                        }
                        lastUpdateTime += frequency * 1000UL;
                      }
                    }
                    
                    //void incomingMessage(const MyMessage &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)
                        }
                      }
                      //gw.wait(50);
                    
                    }
                    `
                    korttomaK Offline
                    korttomaK Offline
                    korttoma
                    Hero Member
                    wrote on last edited by
                    #9

                    @Dick Add the following to the beginning of your sketch to enable serial print:

                    #define MY_DEBUG
                    
                    • Tomas
                    DickD 1 Reply Last reply
                    0
                    • korttomaK korttoma

                      @Dick Add the following to the beginning of your sketch to enable serial print:

                      #define MY_DEBUG
                      
                      DickD Offline
                      DickD Offline
                      Dick
                      wrote on last edited by
                      #10

                      @korttoma That is easy,Thanks for the solution.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      8

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

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