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. My Project
  3. Problem with node reciving data

Problem with node reciving data

Scheduled Pinned Locked Moved My Project
11 Posts 5 Posters 4.1k 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.
  • D Offline
    D Offline
    Dalhoj
    wrote on last edited by
    #1

    Hi I'm trying to make a scene controller with a display, witch show info from my Vera.

    The sketch works fine as long im not trying to recive data from the gateway.
    so the problem is how to get data from the gateway using the V_VAR1 in my case. later I would like to use all 5 variables.

    Below is my code:

    // Simple SceneController With Dispaly
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    // Display START
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    
    //// If using software SPI (the default case):
    #define OLED_MOSI   3 //D1
    #define OLED_CLK   4 //D0
    #define OLED_DC    5 //DC
    #define OLED_CS    6 //CS
    #define OLED_RESET 7 //res
    Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
    
    #define NUMFLAKES 10
    #define XPOS 0
    #define YPOS 1
    #define DELTAY 2
    
    #define LOGO16_GLCD_HEIGHT 16 
    #define LOGO16_GLCD_WIDTH  16 
    static const unsigned char PROGMEM logo16_glcd_bmp[] =
    { B00000000, B11000000,
      B00000001, B11000000,
      B00000001, B11000000,
      B00000011, B11100000,
      B11110011, B11100000,
      B11111110, B11111000,
      B01111110, B11111111,
      B00110011, B10011111,
      B00011111, B11111100,
      B00001101, B01110000,
      B00011011, B10100000,
      B00111111, B11100000,
      B00111111, B11110000,
      B01111100, B11110000,
      B01110000, B01110000,
      B00000000, B00110000 };
    
    #if (SSD1306_LCDHEIGHT != 64)
    #error("Height incorrect, please fix Adafruit_SSD1306.h!");
    #endif
    // Display END
    
    String VAR1 = "Error";
    
    #define CHILD_ID 3
    // PIN for the buttons
    byte buttons[] = {3, 4, 5, 6, 7, 8     };
    #define NUMBUTTONS sizeof(buttons)
    byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
    
    MySensor gw;
    
    Bounce debouncer[NUMBUTTONS];
    
    int oldValue[NUMBUTTONS];
    
    MyMessage msgOn(CHILD_ID,V_SCENE_ON);
    MyMessage msgOff(CHILD_ID,V_SCENE_OFF);
    MyMessage msg(CHILD_ID,V_VAR1);
    void setup()  
    {  
      gw.begin(incomingMessage, AUTO, true);
    
      /// Make input & enable pull-up resistors on switch pins
      for (short i=0; i < NUMBUTTONS; i++){
    
        pinMode(buttons[i], INPUT);
        digitalWrite(buttons[i], HIGH);
        oldValue[i] = -1;
        // After setting up the button, setup debouncer
        debouncer[i].attach(buttons[i]);
        debouncer[i].interval(5);
        
        // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Display", "1.0");
      // Register binary input sensor to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_SCENE_CONTROLLER); 
      
    //Display START
    // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
      display.begin(SSD1306_SWITCHCAPVCC);
      // init done
    //Display END
      }
      
    }
    
    //  Check if digital input has changed and send in new value
    void loop()  
    {
      
      // Alway process incoming messages whenever possible
      gw.process();
      
      for (short i=0; i < NUMBUTTONS; i++){
        debouncer[i].update();
        // Get the update value
        int value = debouncer[i].read();
    
        if (value != oldValue[i]) {
           // Send in the new value
           if (value==HIGH) {
             //gw.send(msgOff.set(i));
           }
           else {
             gw.send(msgOn.set(i));
           }
           oldValue[i] = value;
        }
      }
      
    //Display
    
       // Clear the buffer.
      display.clearDisplay();
    
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Test 1");
      display.display();
      delay(2000);
      
      // Clear the buffer.
      display.clearDisplay();
    
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Test");
      display.setTextColor(BLACK, WHITE); // 'inverted' text
      display.println("2");
      display.display();
      delay(2000);
      
      // Clear the buffer.
      display.clearDisplay();
      
        display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println(VAR1);
      display.display();
      delay(2000);
      
      // Clear the buffer.
      display.clearDisplay();
    }
    
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_VAR1) {
         VAR1 = String(message.data);
       } 
    }
    

    Regards ;-)

    hekH 1 Reply Last reply
    0
    • D Dalhoj

      Hi I'm trying to make a scene controller with a display, witch show info from my Vera.

      The sketch works fine as long im not trying to recive data from the gateway.
      so the problem is how to get data from the gateway using the V_VAR1 in my case. later I would like to use all 5 variables.

      Below is my code:

      // Simple SceneController With Dispaly
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      // Display START
      #include <Wire.h>
      #include <Adafruit_GFX.h>
      #include <Adafruit_SSD1306.h>
      
      //// If using software SPI (the default case):
      #define OLED_MOSI   3 //D1
      #define OLED_CLK   4 //D0
      #define OLED_DC    5 //DC
      #define OLED_CS    6 //CS
      #define OLED_RESET 7 //res
      Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
      
      #define NUMFLAKES 10
      #define XPOS 0
      #define YPOS 1
      #define DELTAY 2
      
      #define LOGO16_GLCD_HEIGHT 16 
      #define LOGO16_GLCD_WIDTH  16 
      static const unsigned char PROGMEM logo16_glcd_bmp[] =
      { B00000000, B11000000,
        B00000001, B11000000,
        B00000001, B11000000,
        B00000011, B11100000,
        B11110011, B11100000,
        B11111110, B11111000,
        B01111110, B11111111,
        B00110011, B10011111,
        B00011111, B11111100,
        B00001101, B01110000,
        B00011011, B10100000,
        B00111111, B11100000,
        B00111111, B11110000,
        B01111100, B11110000,
        B01110000, B01110000,
        B00000000, B00110000 };
      
      #if (SSD1306_LCDHEIGHT != 64)
      #error("Height incorrect, please fix Adafruit_SSD1306.h!");
      #endif
      // Display END
      
      String VAR1 = "Error";
      
      #define CHILD_ID 3
      // PIN for the buttons
      byte buttons[] = {3, 4, 5, 6, 7, 8     };
      #define NUMBUTTONS sizeof(buttons)
      byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
      
      MySensor gw;
      
      Bounce debouncer[NUMBUTTONS];
      
      int oldValue[NUMBUTTONS];
      
      MyMessage msgOn(CHILD_ID,V_SCENE_ON);
      MyMessage msgOff(CHILD_ID,V_SCENE_OFF);
      MyMessage msg(CHILD_ID,V_VAR1);
      void setup()  
      {  
        gw.begin(incomingMessage, AUTO, true);
      
        /// Make input & enable pull-up resistors on switch pins
        for (short i=0; i < NUMBUTTONS; i++){
      
          pinMode(buttons[i], INPUT);
          digitalWrite(buttons[i], HIGH);
          oldValue[i] = -1;
          // After setting up the button, setup debouncer
          debouncer[i].attach(buttons[i]);
          debouncer[i].interval(5);
          
          // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Display", "1.0");
        // Register binary input sensor to gw (they will be created as child devices)
        gw.present(CHILD_ID, S_SCENE_CONTROLLER); 
        
      //Display START
      // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
        display.begin(SSD1306_SWITCHCAPVCC);
        // init done
      //Display END
        }
        
      }
      
      //  Check if digital input has changed and send in new value
      void loop()  
      {
        
        // Alway process incoming messages whenever possible
        gw.process();
        
        for (short i=0; i < NUMBUTTONS; i++){
          debouncer[i].update();
          // Get the update value
          int value = debouncer[i].read();
      
          if (value != oldValue[i]) {
             // Send in the new value
             if (value==HIGH) {
               //gw.send(msgOff.set(i));
             }
             else {
               gw.send(msgOn.set(i));
             }
             oldValue[i] = value;
          }
        }
        
      //Display
      
         // Clear the buffer.
        display.clearDisplay();
      
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println("Test 1");
        display.display();
        delay(2000);
        
        // Clear the buffer.
        display.clearDisplay();
      
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println("Test");
        display.setTextColor(BLACK, WHITE); // 'inverted' text
        display.println("2");
        display.display();
        delay(2000);
        
        // Clear the buffer.
        display.clearDisplay();
        
          display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println(VAR1);
        display.display();
        delay(2000);
        
        // Clear the buffer.
        display.clearDisplay();
      }
      
      
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_VAR1) {
           VAR1 = String(message.data);
         } 
      }
      

      Regards ;-)

      hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      @Dalhoj

      Try avoid using the String-class if possible.

      You could probably just do a
      strcpy(VAR1, message.data);
      or
      strcpy(VAR1, message.getString())

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

        I found that the problem starts when I add

        gw.begin(incomingMessage, AUTO, true);
        

        insted of:

        gw.begin();
        

        even when I try to use:

        gw.begin(NULL, AUTO, true);
        

        Its like the sketch freezes, and I cant see anything on the display or in the serial monitor.
        When I go back to gw.begin() the display Again starts showing the Things in the loop ()

        Why can that be?

        andyunoA 1 Reply Last reply
        0
        • D Dalhoj

          I found that the problem starts when I add

          gw.begin(incomingMessage, AUTO, true);
          

          insted of:

          gw.begin();
          

          even when I try to use:

          gw.begin(NULL, AUTO, true);
          

          Its like the sketch freezes, and I cant see anything on the display or in the serial monitor.
          When I go back to gw.begin() the display Again starts showing the Things in the loop ()

          Why can that be?

          andyunoA Offline
          andyunoA Offline
          andyuno
          wrote on last edited by
          #4

          @Dalhoj I know it's not much of a help that I've been trying to do pretty much the same thing and using the same statements you are and countering the same problems, I'm not a programmer or from a programming background but I try and understand as much as possible about what's going on but I just can't seem to get my head around it..
          Kind regards.

          :) Any Help is Appreciated Thank You.

          1 Reply Last reply
          0
          • hekH Offline
            hekH Offline
            hek
            Admin
            wrote on last edited by
            #5

            @Dalhoj

            Does it still hang if you just do:

            void incomingMessage(const MyMessage &message) {
              // We only expect one type of message from controller. But we better check anyway.
              if (message.type==V_VAR1) {
                 Serial.println( message.getString());
               } 
            }
            
            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dalhoj
              wrote on last edited by
              #6

              OK so far so good

              I tryed the new code you posted @hek, but still no luck

              Then I changed the gw.begin() to:

              gw.begin(incomingMessage);
              

              Then I could see things on the display :-)

              Then the question comes to how to send from vera to the node?

              I tryed to do as here: Mysensor forum
              I used this code:

              luup.call_action("urn:upnp-arduino-cc:serviceId:arduino1", "SendCommand", {radioId="10;255", variableId="VAR_1", value=88}, 260)
              

              The problem is when I run the code the serial monitor looks like this:

              sensor started, id 10
              send: 10-10-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
              send: 10-10-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
              read: 0-0-10 s=255,c=3,t=6,pt=0,l=2:M
              send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=7,st=ok:Display
              send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 10-10-0-0 s=3,c=0,t=25,pt=0,l=3,st=ok:1.4
              send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=7,st=ok:Display
              send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 10-10-0-0 s=3,c=0,t=25,pt=0,l=3,st=ok:1.4
              send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=7,st=ok:Display
              send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 10-10-0-0 s=3,c=0,t=25,pt=0,l=3,st=ok:1.4
              send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=7,st=ok:Display
              send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 10-10-0-0 s=3,c=0,t=25,pt=0,l=3,st=ok:1.4
              send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=7,st=ok:Display
              send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 10-10-0-0 s=3,c=0,t=25,pt=0,l=3,st=ok:1.4
              send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=7,st=ok:Display
              send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 10-10-0-0 s=3,c=0,t=25,pt=0,l=3,st=ok:1.4
              
              

              And its like the node restarts, and not recives any data.

              I also changed from the string to int, in the var1. so this the code as it is now:

              // Simple SceneController With Dispaly
              
              #include <MySensor.h>
              #include <SPI.h>
              #include <Bounce2.h>
              // Display START
              #include <Wire.h>
              #include <Adafruit_GFX.h>
              #include <Adafruit_SSD1306.h>
              
              //// If using software SPI (the default case):
              #define OLED_MOSI   3 //D1
              #define OLED_CLK   4 //D0
              #define OLED_DC    5 //DC
              #define OLED_CS    6 //CS
              #define OLED_RESET 7 //res
              Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
              
              #define NUMFLAKES 10
              #define XPOS 0
              #define YPOS 1
              #define DELTAY 2
              
              #define LOGO16_GLCD_HEIGHT 16 
              #define LOGO16_GLCD_WIDTH  16 
              static const unsigned char PROGMEM logo16_glcd_bmp[] =
              { B00000000, B11000000,
                B00000001, B11000000,
                B00000001, B11000000,
                B00000011, B11100000,
                B11110011, B11100000,
                B11111110, B11111000,
                B01111110, B11111111,
                B00110011, B10011111,
                B00011111, B11111100,
                B00001101, B01110000,
                B00011011, B10100000,
                B00111111, B11100000,
                B00111111, B11110000,
                B01111100, B11110000,
                B01110000, B01110000,
                B00000000, B00110000 };
              
              #if (SSD1306_LCDHEIGHT != 64)
              #error("Height incorrect, please fix Adafruit_SSD1306.h!");
              #endif
              // Display END
              
              int VAR1 = 99;
              
              #define CHILD_ID 3
              // PIN for the buttons
              byte buttons[] = {14, 15, 16, 17, 18, 19};
              #define NUMBUTTONS sizeof(buttons)
              byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
              
              MySensor gw;
              
              Bounce debouncer[NUMBUTTONS];
              
              int oldValue[NUMBUTTONS];
              
              MyMessage msgOn(CHILD_ID,V_SCENE_ON);
              MyMessage msgOff(CHILD_ID,V_SCENE_OFF);
              MyMessage msg(CHILD_ID,V_VAR1);
              void setup()  
              {  
                gw.begin(incomingMessage);
                
                /// Make input & enable pull-up resistors on switch pins
                for (short i=0; i < NUMBUTTONS; i++){
              
                  pinMode(buttons[i], INPUT);
                  digitalWrite(buttons[i], HIGH);
                  oldValue[i] = -1;
                  // After setting up the button, setup debouncer
                  debouncer[i].attach(buttons[i]);
                  debouncer[i].interval(5);
                  
                  // Send the Sketch Version Information to the Gateway
                gw.sendSketchInfo("Display", "1.0");
                // Register binary input sensor to gw (they will be created as child devices)
                gw.present(CHILD_ID, S_SCENE_CONTROLLER); 
                
              //Display START
              // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
                display.begin(SSD1306_SWITCHCAPVCC);
                // init done
              //Display END
                }
                
              }
              
              //  Check if digital input has changed and send in new value
              void loop()  
              {
                
                // Alway process incoming messages whenever possible
                gw.process();
                
                for (short i=0; i < NUMBUTTONS; i++){
                  debouncer[i].update();
                  // Get the update value
                  int value = debouncer[i].read();
              
                  if (value != oldValue[i]) {
                     // Send in the new value
                     if (value==HIGH) {
                       //gw.send(msgOff.set(i));
                     }
                     else {
                       gw.send(msgOn.set(i));
                     }
                     oldValue[i] = value;
                  }
                }
                
              //Display
              
                 // Clear the buffer.
                display.clearDisplay();
              
                display.setTextSize(2);
                display.setTextColor(WHITE);
                display.setCursor(0,0);
                display.println("Test 1");
                display.display();
                delay(2000);
                
                // Clear the buffer.
                display.clearDisplay();
              
                display.setTextSize(2);
                display.setTextColor(WHITE);
                display.setCursor(0,0);
                display.println("Test");
                display.setTextColor(BLACK, WHITE); // 'inverted' text
                display.println("2");
                display.display();
                delay(2000);
                
                // Clear the buffer.
                display.clearDisplay();
                
                  display.setTextSize(2);
                display.setTextColor(WHITE);
                display.setCursor(0,0);
                display.println(VAR1);
                display.display();
                delay(2000);
                
                // Clear the buffer.
                display.clearDisplay();
              }
              
              
              void incomingMessage(const MyMessage &message) {
                // We only expect one type of message from controller. But we better check anyway.
                if (message.type==V_VAR1) {
                   VAR1 = atoi(message.data);
                 } 
              }
              /*
              void incomingMessage(const MyMessage &message) {
                // We only expect one type of message from controller. But we better check anyway.
                if (message.type==V_VAR1) {
                   Serial.println( message.getString());
                 } 
              }
              */
              
              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dalhoj
                wrote on last edited by
                #7

                OK

                Now I have come a step further.

                When I remote everything from the loop() besides the process() I can recive date from the gateway.

                The question now is how to get it on the display, and change between the data, say every 2 sec.

                1 Reply Last reply
                0
                • rvendrameR Offline
                  rvendrameR Offline
                  rvendrame
                  Hero Member
                  wrote on last edited by
                  #8

                  How are you powering your Arduino and Radio?

                  Home Assistant / Vera Plus UI7
                  ESP8266 GW + mySensors 2.3.2
                  Alexa / Google Home

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dalhoj
                    wrote on last edited by
                    #9

                    It's on a arduino uno, and it's powerd via the usb, som my laptop.

                    Do you think I should try an extern power supply?

                    M 1 Reply Last reply
                    0
                    • D Dalhoj

                      It's on a arduino uno, and it's powerd via the usb, som my laptop.

                      Do you think I should try an extern power supply?

                      M Offline
                      M Offline
                      maltimus
                      wrote on last edited by
                      #10

                      @Dalhoj I think that @rvendrame might be on the right path. Your laptop USB port is probably only putting out around 500mA. If the screen you are trying to display too is pulling a lot of current is could be causing the Arduino to act in a strange manor. It wouldnt hurt to try powering the Arduino from an external power supply and seeing if you get the same results.

                      1 Reply Last reply
                      0
                      • rvendrameR Offline
                        rvendrameR Offline
                        rvendrame
                        Hero Member
                        wrote on last edited by
                        #11

                        ... and also add a decoupling capacitor between radio's VCC and GND pin, in order to smooth the power to radio --- something from 4.7uF to 100uF may be helpful.

                        Home Assistant / Vera Plus UI7
                        ESP8266 GW + mySensors 2.3.2
                        Alexa / Google Home

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


                        18

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.1k

                        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