Skip to content
  • 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. Why can't I assign a static NODE_ID in one sketch; but not the other?
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Why can't I assign a static NODE_ID in one sketch; but not the other?

Scheduled Pinned Locked Moved Troubleshooting
7 Posts 4 Posters 1.9k 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.
  • D Offline
    D Offline
    drock1985
    wrote on last edited by
    #1

    Hi,

    I'm trying to assign a static NODE_ID to the standard Motion Sensor Example sketch, but I am getting compile errors. The code I am using is

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Motion Sensor example using HC-SR501 
     * http://www.mysensors.org/build/motion
     *
     */
    
    
    #include <MySensor.h>  
    #include <SPI.h>
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define NODE_ID 6
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 1   // Id of the sensor child
    
    MySensor gw;
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      gw.begin (msg, NODE_ID) ;
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Motion Sensor", "1.0");
    
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_MOTION);
      
    }
    
    void loop()     
    {     
      // Read digital motion value
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
            
      Serial.println(tripped);
      gw.send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
     
      // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
      gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    }
    
    

    What I don't understand about all of this is, I have another sketch that I can and have manually set the NODE_ID for, and it is not that much different from what I have. The code for the working node I have with a set manual ID is:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - 6-December-2015, Derrick Rockwell
     *
     * DESCRIPTION
     *This sketch uses two 30 bulb, 3mm LED holiday light strings. These
     *can usually be found in most dollar stores/hardware stores and are 
     *battery powered. This sketch uses digital pins 3 and 4 to power two 
     *a string of lights each. Ex, one can control white lights the other
     *could control multi-colour lights. 
     */
    
    #define SN "HolidayLEDDeskLights"
    #define SV "1.0"
    
    #include <MySensor.h> 
    #include <SPI.h>
    
    #define MLED_PIN 3      // Pin Multi-Coloured LED's will attached to
    #define WLED_PIN 5      // Pin White-Coloured LED's will attached to
    #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
    #define NODE_ID 4
    #define CHILD_ID0 0
    #define CHILD_ID1 1
    
    MySensor gw;
    
    static int currentLevelM = 0;  // Current dim level...
    static int currentLevelW = 0;  // Current dim level...
    
    MyMessage dimmerMsgM(MLED_PIN, V_DIMMER);
    MyMessage lightMsgM(MLED_PIN, V_LIGHT);
    MyMessage dimmerMsgW(WLED_PIN, V_DIMMER);
    MyMessage lightMsgW(WLED_PIN, V_LIGHT);
    
    /***
     * Dimmable LED initialization method
     */
    void setup()  
    { 
      Serial.println( SN ); 
      Serial.println( SV );
      gw.begin( incomingMessage, NODE_ID );
      
      // Register the LED Dimmable Light with the gateway
      gw.present( MLED_PIN, S_DIMMER );
      gw.present( WLED_PIN, S_DIMMER );
      
      gw.sendSketchInfo(SN, SV);
      // Pull the gateway's current dim level - restore light level upon sendor node power-up
      gw.request( MLED_PIN, V_DIMMER );
      gw.request( WLED_PIN, V_DIMMER );
    }
    
    /***
     *  Dimmable LED main processing loop 
     */
    void loop() 
    {
      gw.process();
    }
    
    //For Multi Coloured Lights
    void incomingMessage(const MyMessage &message) {
    if (message.type == V_LIGHT || message.type == V_DIMMER) {
          // if (message.sensor <= 2)
          {
              //0: All Dimmers
              //1: LED 1
              //2: LED 2
              //  Retrieve the power or dim level from the incoming request message
              int requestedLevel = atoi( message.data );
              
              // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
              requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
              
              if ((message.sensor == CHILD_ID0) || (message.sensor == 0)){
                fadeToLevel ( requestedLevel, MLED_PIN, &currentLevelM );
                // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                gw.send(lightMsgM.set(requestedLevel > 0 ? 1 : 0));
                gw.send(dimmerMsgM.set(requestedLevel) );
              }
              if ((message.sensor == CHILD_ID1) || (message.sensor == 0)){
                fadeToLevel( requestedLevel, WLED_PIN, &currentLevelW );
                // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                gw.send(lightMsgW.set(requestedLevel > 0 ? 1 : 0));
                gw.send(dimmerMsgW.set(requestedLevel) );
              }
            }
    }
    }
    
    /***
     *  This method provides a graceful fade up/down effect
     */
     // For Multi Coloured Lights
    void fadeToLevel( int toLevel, int pin, int *currentLevel ) {
      int delta = ( toLevel - (*currentLevel) ) < 0 ? -1 : 1;
      while ( (*currentLevel) != toLevel ) {
        (*currentLevel) += delta;
        analogWrite( pin, (int)((*currentLevel) / 100. * 255) );
        delay( FADE_DELAY );
      }
    }
    

    can anyone help me? I checked out the API page when starting the library, but i'm still drawing blanks.

    My Projects
    2 Door Chime Sensor
    Washing Machine Monitor

    1 Reply Last reply
    0
    • dakkyD Offline
      dakkyD Offline
      dakky
      wrote on last edited by
      #2

      what is your error?

      Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
      Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

      Software: MySensors 2.0development

      1 Reply Last reply
      0
      • D Offline
        D Offline
        drock1985
        wrote on last edited by
        #3

        Hi @dakky

        This is the error I get from Arduino IDE:

        exit status 1
        invalid conversion from 'int' to 'void (*)(const MyMessage&)' [-fpermissive]

        My Projects
        2 Door Chime Sensor
        Washing Machine Monitor

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

          You are sending a message (msg) instead of a function (incomingMessage) to gw.begin.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ericvdb
            wrote on last edited by
            #5

            In the first sketch change

            gw.begin (msg, NODE_ID) ;
            

            to

            gw.begin (NULL, NODE_ID) ;
            
            1 Reply Last reply
            1
            • D Offline
              D Offline
              drock1985
              wrote on last edited by
              #6

              Hi @ericvdb

              That did the trick, thanks. Just now to figure out the why.

              My Projects
              2 Door Chime Sensor
              Washing Machine Monitor

              1 Reply Last reply
              0
              • mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #7

                In your first sketch, the node accepts incoming messages.

                The second sketch does not have a function for incoming messages, so you have no function to give gw.begin as argument. You tried giving ge.begin a message instead, but that's not what gw.begin expects so you got a warning.

                When you don't want to use incoming messages you simply give NULL to gw.begin, as ericvdb suggested.

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


                3

                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
                • OpenHardware.io
                • Categories
                • Recent
                • Tags
                • Popular