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. Troubleshooting
  3. wish to have a non-Repeating node in a sketch based on RELAY example

wish to have a non-Repeating node in a sketch based on RELAY example

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 1.4k Views 1 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.
  • B Offline
    B Offline
    BulldogLowell
    Contest Winner
    wrote on last edited by
    #1

    Do not want a RELAY node

    Can anyone help me modify this so that the node will not become a relaying node?

    Forcing it to be a regular non-repeating node will eliminate that as a suspect to other problems.

    I am using:

    S_LIGHT
    

    not

    S_ARDUINO_RELAY
    

    but still get a relay node when I add it to the network.

    my code here:

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    //
    #define RELAY_PIN  13  // Arduino Digital I/O pin number for relay 
    #define BUTTON_PIN  2  // Arduino Digital I/O pin number for button 
    #define CHILD_ID 1   // Id of the sensor child
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    #define RADIO_ID 12
    //
    int ledPin3 =  3;      // White using PWM
    int ledPin4 =  4;      // Red
    int ledPin5 =  5;      // Blue using PWM
    int ledPin6 =  6;      // Blue using PWM
    int ledPin7 =  7;      // Green
    int ledPin8 =  8;      // White (No PWM)
    //
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    MySensor gw;
    MyMessage msg(CHILD_ID,V_LIGHT);
    int dipInterval = 10;
    int darkTime = 250;
    unsigned long currentDipTime;
    unsigned long dipStartTime;
    unsigned long currentMillis;
    int ledState = LOW;
    long previousMillis = 0; 
    int led = 5;
    int interval = 2000;
    int twitch = 50;
    int dipCount = 0;
    int analogLevel = 100;
    boolean timeToDip = false;
    //
    void setup()  
    {  
      pinMode(ledPin3, OUTPUT);
      pinMode(ledPin4, OUTPUT); 
      pinMode(ledPin5, OUTPUT);
      pinMode(ledPin6, OUTPUT);
      pinMode(ledPin7, OUTPUT);
      pinMode(ledPin8, OUTPUT);
      //
      pinMode(BUTTON_PIN,INPUT_PULLUP);
      //digitalWrite(BUTTON_PIN,HIGH);
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      gw.begin(incomingMessage, RADIO_ID, true);
      dely(3000);
      gw.sendSketchInfo("PhoneyTV", "3.0");
      delay(3000);
      gw.present(CHILD_ID, S_LIGHT);
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);   
      state = gw.loadState(CHILD_ID);
      digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
    }
    //
    void loop() 
    {
      gw.process();
      debouncer.update();
      int value = debouncer.read();
      if (value != oldValue && value==0) 
      {
        gw.send(msg.set(state?false:true), true);
      }
      oldValue = value;
      if (state == true)
      {
        if (timeToDip == false)
        {
          currentMillis = millis();
          if(currentMillis-previousMillis > interval) 
          {
            previousMillis = currentMillis;
            interval = random(750,4001);//Adjusts the interval for more/less frequent random light changes
            twitch = random(40,100);// Twitch provides motion effect but can be a bit much if too high
            dipCount = dipCount++;
          }
          if(currentMillis-previousMillis<twitch)
          {
            led=random(3,9);
            analogLevel=random(50,255);// set the range of the 3 pwm leds
            ledState = ledState == LOW ? HIGH: LOW; // if the LED is off turn it on and vice-versa:
            switch (led) //for the three PWM pins
            {
            case 3:
              pwmWrite();
              break;
            case 5:
              pwmWrite();
              break;
            case 6:
              pwmWrite();
              break;
            default:
              digitalWrite(led, ledState);
            }
            if (dipCount > dipInterval)
            { 
              timeToDip = true;
              dipCount = 0;
              dipStartTime = millis();
              darkTime = random(50,150);
              dipInterval = random(5,250);// cycles of flicker
            }
          } 
        }
        else
        {
          Serial.println("Dip Time");
          currentDipTime = millis();
          if (currentDipTime - dipStartTime < darkTime)
          {
            for (int i=3;i<9;i++)
            {
              digitalWrite(i,LOW);
            }
          }
          else
          {
            timeToDip = false;
    
          }
        }
      }
      else
      {
        for (int i=3;i<9;i++)
        {
          digitalWrite(i,LOW);
        }
      }
    } 
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
        Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT && strlen(msg.getString()) != 0) {
        // Change relay state
        state = message.getBool();
        digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
        // Store state in eeprom
        gw.saveState(CHILD_ID, state);
    
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      } 
    }
    
    void pwmWrite() {
      if (ledState==HIGH){
        analogWrite(led,analogLevel);
      }
      else{
        digitalWrite(led,LOW);
      }
    }
    
    H 1 Reply Last reply
    0
    • B BulldogLowell

      Do not want a RELAY node

      Can anyone help me modify this so that the node will not become a relaying node?

      Forcing it to be a regular non-repeating node will eliminate that as a suspect to other problems.

      I am using:

      S_LIGHT
      

      not

      S_ARDUINO_RELAY
      

      but still get a relay node when I add it to the network.

      my code here:

      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      //
      #define RELAY_PIN  13  // Arduino Digital I/O pin number for relay 
      #define BUTTON_PIN  2  // Arduino Digital I/O pin number for button 
      #define CHILD_ID 1   // Id of the sensor child
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      #define RADIO_ID 12
      //
      int ledPin3 =  3;      // White using PWM
      int ledPin4 =  4;      // Red
      int ledPin5 =  5;      // Blue using PWM
      int ledPin6 =  6;      // Blue using PWM
      int ledPin7 =  7;      // Green
      int ledPin8 =  8;      // White (No PWM)
      //
      Bounce debouncer = Bounce(); 
      int oldValue=0;
      bool state;
      MySensor gw;
      MyMessage msg(CHILD_ID,V_LIGHT);
      int dipInterval = 10;
      int darkTime = 250;
      unsigned long currentDipTime;
      unsigned long dipStartTime;
      unsigned long currentMillis;
      int ledState = LOW;
      long previousMillis = 0; 
      int led = 5;
      int interval = 2000;
      int twitch = 50;
      int dipCount = 0;
      int analogLevel = 100;
      boolean timeToDip = false;
      //
      void setup()  
      {  
        pinMode(ledPin3, OUTPUT);
        pinMode(ledPin4, OUTPUT); 
        pinMode(ledPin5, OUTPUT);
        pinMode(ledPin6, OUTPUT);
        pinMode(ledPin7, OUTPUT);
        pinMode(ledPin8, OUTPUT);
        //
        pinMode(BUTTON_PIN,INPUT_PULLUP);
        //digitalWrite(BUTTON_PIN,HIGH);
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);
        gw.begin(incomingMessage, RADIO_ID, true);
        dely(3000);
        gw.sendSketchInfo("PhoneyTV", "3.0");
        delay(3000);
        gw.present(CHILD_ID, S_LIGHT);
        digitalWrite(RELAY_PIN, RELAY_OFF);
        pinMode(RELAY_PIN, OUTPUT);   
        state = gw.loadState(CHILD_ID);
        digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
      }
      //
      void loop() 
      {
        gw.process();
        debouncer.update();
        int value = debouncer.read();
        if (value != oldValue && value==0) 
        {
          gw.send(msg.set(state?false:true), true);
        }
        oldValue = value;
        if (state == true)
        {
          if (timeToDip == false)
          {
            currentMillis = millis();
            if(currentMillis-previousMillis > interval) 
            {
              previousMillis = currentMillis;
              interval = random(750,4001);//Adjusts the interval for more/less frequent random light changes
              twitch = random(40,100);// Twitch provides motion effect but can be a bit much if too high
              dipCount = dipCount++;
            }
            if(currentMillis-previousMillis<twitch)
            {
              led=random(3,9);
              analogLevel=random(50,255);// set the range of the 3 pwm leds
              ledState = ledState == LOW ? HIGH: LOW; // if the LED is off turn it on and vice-versa:
              switch (led) //for the three PWM pins
              {
              case 3:
                pwmWrite();
                break;
              case 5:
                pwmWrite();
                break;
              case 6:
                pwmWrite();
                break;
              default:
                digitalWrite(led, ledState);
              }
              if (dipCount > dipInterval)
              { 
                timeToDip = true;
                dipCount = 0;
                dipStartTime = millis();
                darkTime = random(50,150);
                dipInterval = random(5,250);// cycles of flicker
              }
            } 
          }
          else
          {
            Serial.println("Dip Time");
            currentDipTime = millis();
            if (currentDipTime - dipStartTime < darkTime)
            {
              for (int i=3;i<9;i++)
              {
                digitalWrite(i,LOW);
              }
            }
            else
            {
              timeToDip = false;
      
            }
          }
        }
        else
        {
          for (int i=3;i<9;i++)
          {
            digitalWrite(i,LOW);
          }
        }
      } 
      
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.isAck()) {
          Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_LIGHT && strlen(msg.getString()) != 0) {
          // Change relay state
          state = message.getBool();
          digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
          // Store state in eeprom
          gw.saveState(CHILD_ID, state);
      
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        } 
      }
      
      void pwmWrite() {
        if (ledState==HIGH){
          analogWrite(led,analogLevel);
        }
        else{
          digitalWrite(led,LOW);
        }
      }
      
      H Offline
      H Offline
      hek
      Admin
      wrote on last edited by
      #2

      @BulldogLowell

      gw.begin(incomingMessage, RADIO_ID, false);

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BulldogLowell
        Contest Winner
        wrote on last edited by
        #3

        so... how could have I missed that HIGHLIGHTED AND BOLDFACED in the MySensors API?

        thanks Henrik!

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        8

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 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