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


  • Contest Winner

    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);
      }
    }

  • Admin

    @BulldogLowell

    gw.begin(incomingMessage, RADIO_ID, false);


  • Contest Winner

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

    thanks Henrik!


 

342
Online

7.8k
Users

8.7k
Topics

93.0k
Posts