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. Problem getting the code to run with MySensors library 2.0

Problem getting the code to run with MySensors library 2.0

Scheduled Pinned Locked Moved Troubleshooting
38 Posts 3 Posters 8.8k 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.
  • palande.vaibhavP palande.vaibhav

    @ayo
    did you try commenting #define MY_GATEWAY_SERIAL and running your Blink code?
    Can you please try that?

    ayoA Offline
    ayoA Offline
    ayo
    wrote on last edited by
    #22

    I don't have access to my computer now I will try it when I have it.

    @palande.vaibhav said:

    @ayo
    did you try commenting #define MY_GATEWAY_SERIAL and running your Blink code?
    Can you please try that?

    palande.vaibhavP 1 Reply Last reply
    0
    • palande.vaibhavP palande.vaibhav

      @mfalkvidd
      Thanx for the suggestion. It's worse than I thought.

      Here is the code:

      
      //MySensors
      // Enable debug prints
      //#define MY_DEBUG
      
      //// Enable and select radio type attached
      #define MY_RADIO_NRF24
      ////#define MY_RADIO_RFM69
      
      #define MY_GATEWAY_SERIAL
      
      #include <SPI.h>
      #include <MySensors.h>
      
      // Initialize motion message
      //MyMessage msg(1, V_LIGHT);
      
      void setup() { 
        // Setup locally attached sensors
        pinMode(8, OUTPUT);
        Serial.println("Setup runs");
      }
      
      void presentation() {
       // Present locally attached sensors 
       Serial.println("presentation runs");
      }
      
      void loop() { 
        // Send locally attached sensor data here 
        Serial.println("loop runs");
         digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(1000);              // wait for a second
        digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
        delay(1000);              // wait for a second
      }
      

      This is the output with #define MY_GATEWAY_SERIAL line.
      0_1474716279452_javaw_2016-09-24_04-22-42.png

      Without #define MY_GATEWAY_SERIAL, it doesn't show anything on the serial monitor.

      palande.vaibhavP Offline
      palande.vaibhavP Offline
      palande.vaibhav
      wrote on last edited by palande.vaibhav
      #23

      @palande.vaibhav said:

      @mfalkvidd
      Thanx for the suggestion. It's worse than I thought.

      Here is the code:

      
      //MySensors
      // Enable debug prints
      //#define MY_DEBUG
      
      //// Enable and select radio type attached
      #define MY_RADIO_NRF24
      ////#define MY_RADIO_RFM69
      
      #define MY_GATEWAY_SERIAL
      
      #include <SPI.h>
      #include <MySensors.h>
      
      // Initialize motion message
      //MyMessage msg(1, V_LIGHT);
      
      void setup() { 
        // Setup locally attached sensors
        pinMode(8, OUTPUT);
        Serial.println("Setup runs");
      }
      
      void presentation() {
       // Present locally attached sensors 
       Serial.println("presentation runs");
      }
      
      void loop() { 
        // Send locally attached sensor data here 
        Serial.println("loop runs");
         digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(1000);              // wait for a second
        digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
        delay(1000);              // wait for a second
      }
      

      This is the output with #define MY_GATEWAY_SERIAL line.
      0_1474716279452_javaw_2016-09-24_04-22-42.png

      Without #define MY_GATEWAY_SERIAL, it doesn't show anything on the serial monitor.

      @mfalkvidd Any update on this?

      mfalkviddM 1 Reply Last reply
      0
      • palande.vaibhavP palande.vaibhav

        @palande.vaibhav said:

        @mfalkvidd
        Thanx for the suggestion. It's worse than I thought.

        Here is the code:

        
        //MySensors
        // Enable debug prints
        //#define MY_DEBUG
        
        //// Enable and select radio type attached
        #define MY_RADIO_NRF24
        ////#define MY_RADIO_RFM69
        
        #define MY_GATEWAY_SERIAL
        
        #include <SPI.h>
        #include <MySensors.h>
        
        // Initialize motion message
        //MyMessage msg(1, V_LIGHT);
        
        void setup() { 
          // Setup locally attached sensors
          pinMode(8, OUTPUT);
          Serial.println("Setup runs");
        }
        
        void presentation() {
         // Present locally attached sensors 
         Serial.println("presentation runs");
        }
        
        void loop() { 
          // Send locally attached sensor data here 
          Serial.println("loop runs");
           digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
          delay(1000);              // wait for a second
          digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
          delay(1000);              // wait for a second
        }
        

        This is the output with #define MY_GATEWAY_SERIAL line.
        0_1474716279452_javaw_2016-09-24_04-22-42.png

        Without #define MY_GATEWAY_SERIAL, it doesn't show anything on the serial monitor.

        @mfalkvidd Any update on this?

        mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by
        #24

        @palande.vaibhav no, I haven't got any ideas on what could be wrong. Sorry.

        palande.vaibhavP 1 Reply Last reply
        0
        • ayoA ayo

          I don't have access to my computer now I will try it when I have it.

          @palande.vaibhav said:

          @ayo
          did you try commenting #define MY_GATEWAY_SERIAL and running your Blink code?
          Can you please try that?

          palande.vaibhavP Offline
          palande.vaibhavP Offline
          palande.vaibhav
          wrote on last edited by
          #25

          @ayo Did you try running the code?

          ayoA 1 Reply Last reply
          0
          • mfalkviddM mfalkvidd

            @palande.vaibhav no, I haven't got any ideas on what could be wrong. Sorry.

            palande.vaibhavP Offline
            palande.vaibhavP Offline
            palande.vaibhav
            wrote on last edited by
            #26

            @mfalkvidd
            Is it only me?
            Can you please try this on your setup as time permits?
            I have a manual install of the library 2.0
            I want to use this for one of my projects and I am dead stuck.

            1 Reply Last reply
            0
            • mfalkviddM mfalkvidd

              @palande.vaibhav said:

              Cause I can't use MY_GATEWAY_SERIAL for a node. Right?

              Yes you can. But I read that there is a bug in MySensors 2.0 that causes the presentation function to not run, so you'll need the latest code from the MySensors development branch on Github.

              palande.vaibhavP Offline
              palande.vaibhavP Offline
              palande.vaibhav
              wrote on last edited by palande.vaibhav
              #27

              @mfalkvidd
              I have to keep #define MY_GATEWAY_SERIAL line in the code for both gateway and sensor nodes.
              Now since I have #define MY_GATEWAY_SERIAL line in the code for both gateway and sensor node, both of them are initializing as gateways.
              And this causes them not to be able to communicate with each other.
              Please help
              0_1474801920068_javaw_2016-09-25_04-11-40.png

              1 Reply Last reply
              0
              • palande.vaibhavP palande.vaibhav

                @ayo Did you try running the code?

                ayoA Offline
                ayoA Offline
                ayo
                wrote on last edited by
                #28

                So I tried the whole code thing again as you have requested and I notice something weird happening to the device.
                This is the code below

                //// Enable debug prints to serial monitor
                //#define MY_DEBUG 
                //
                //
                //// Enable and select radio type attached
                #define MY_RADIO_NRF24
                ////#define MY_RADIO_RFM69
                //
                //// Set LOW transmit power level as default, if you have an amplified NRF-module and
                //// power your radio separately with a good regulator you can turn up PA level. 
                //#define MY_RF24_PA_LEVEL RF24_PA_LOW
                //
                //// Enable serial gateway
                //#define MY_GATEWAY_SERIAL
                
                #include <SPI.h>
                #include <MySensors.h>  
                
                void setup() { 
                  // Setup locally attached sensors
                  pinMode(8, OUTPUT);
                }
                
                void presentation() {
                 // Present locally attached sensors 
                 Serial.println("Presentation Runs");
                }
                
                void loop() { 
                  // Send locally attached sensor data here 
                   digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
                  delay(1000);              // wait for a second
                  digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
                  delay(1000);              // wait for a second
                  Serial.println("Loop is running");
                

                }

                After I commented out #define MY_GATEWAY_SERIAL nothing really happens on the serial monitor as you have said.
                No blinking nor display on the monitor.

                So I went back to the code and enable #define MY_DEBUG to see what was actually happening....

                THEN..I figured out what was happening
                I uploaded the new code with #define MY_Debug uncomment and #define MY_Gateway_Serial still commented out I got this one the serial monitor

                Starting sensor (RNNNA-, 2.0.0)
                TSM:INIT
                TSM:RADIO:OK
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                !TSM:FPAR:FAIL
                !TSM:FAILURE
                TSM:PDT
                TSM:INIT
                TSM:RADIO:OK
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                TSM:FPAR
                TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                

                From the result, the device is working as a node and trying to communicate with the parent/gateway and it enters an endless retry loop that keeps trying to communicate with the gateway. This is the reason i suppose nothing seems to be working because it is stuck trying to connect to the parent.
                The Addition of #define MY_GATEWAY_SERIAL makes it already a gateway/parent device and avoids that endless loop thing.

                @palande.vaibhav said:

                @ayo Did you try running the code?

                palande.vaibhavP 1 Reply Last reply
                1
                • ayoA Offline
                  ayoA Offline
                  ayo
                  wrote on last edited by
                  #29

                  I think one way to go about making it work is to edit that element of the mysensor main code that makes it enter an infinite retry loop is to is to make it retry for about maybe 3 times if no connection still it should raise a flag and leaves the loop and continue into the main code.

                  1 Reply Last reply
                  0
                  • ayoA ayo

                    So I tried the whole code thing again as you have requested and I notice something weird happening to the device.
                    This is the code below

                    //// Enable debug prints to serial monitor
                    //#define MY_DEBUG 
                    //
                    //
                    //// Enable and select radio type attached
                    #define MY_RADIO_NRF24
                    ////#define MY_RADIO_RFM69
                    //
                    //// Set LOW transmit power level as default, if you have an amplified NRF-module and
                    //// power your radio separately with a good regulator you can turn up PA level. 
                    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
                    //
                    //// Enable serial gateway
                    //#define MY_GATEWAY_SERIAL
                    
                    #include <SPI.h>
                    #include <MySensors.h>  
                    
                    void setup() { 
                      // Setup locally attached sensors
                      pinMode(8, OUTPUT);
                    }
                    
                    void presentation() {
                     // Present locally attached sensors 
                     Serial.println("Presentation Runs");
                    }
                    
                    void loop() { 
                      // Send locally attached sensor data here 
                       digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
                      delay(1000);              // wait for a second
                      digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
                      delay(1000);              // wait for a second
                      Serial.println("Loop is running");
                    

                    }

                    After I commented out #define MY_GATEWAY_SERIAL nothing really happens on the serial monitor as you have said.
                    No blinking nor display on the monitor.

                    So I went back to the code and enable #define MY_DEBUG to see what was actually happening....

                    THEN..I figured out what was happening
                    I uploaded the new code with #define MY_Debug uncomment and #define MY_Gateway_Serial still commented out I got this one the serial monitor

                    Starting sensor (RNNNA-, 2.0.0)
                    TSM:INIT
                    TSM:RADIO:OK
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    !TSM:FPAR:FAIL
                    !TSM:FAILURE
                    TSM:PDT
                    TSM:INIT
                    TSM:RADIO:OK
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    TSM:FPAR
                    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                    

                    From the result, the device is working as a node and trying to communicate with the parent/gateway and it enters an endless retry loop that keeps trying to communicate with the gateway. This is the reason i suppose nothing seems to be working because it is stuck trying to connect to the parent.
                    The Addition of #define MY_GATEWAY_SERIAL makes it already a gateway/parent device and avoids that endless loop thing.

                    @palande.vaibhav said:

                    @ayo Did you try running the code?

                    palande.vaibhavP Offline
                    palande.vaibhavP Offline
                    palande.vaibhav
                    wrote on last edited by
                    #30

                    @ayo
                    But adding #define MY_GATEWAY_SERIAL to the code for the sensor node will make it a gateway. Right? Please check my last post where I posted the screenshots of this making both of them initialize as the gateway.

                    And if both are gateways they won't communicate

                    ayoA 1 Reply Last reply
                    0
                    • palande.vaibhavP palande.vaibhav

                      @ayo
                      But adding #define MY_GATEWAY_SERIAL to the code for the sensor node will make it a gateway. Right? Please check my last post where I posted the screenshots of this making both of them initialize as the gateway.

                      And if both are gateways they won't communicate

                      ayoA Offline
                      ayoA Offline
                      ayo
                      wrote on last edited by
                      #31

                      Yes they won't communicate

                      @palande.vaibhav said:

                      @ayo
                      But adding #define MY_GATEWAY_SERIAL to the code for the sensor node will make it a gateway. Right? Please check my last post where I posted the screenshots of this making both of them initialize as the gateway.

                      And if both are gateways they won't communicate

                      palande.vaibhavP 1 Reply Last reply
                      0
                      • ayoA ayo

                        Yes they won't communicate

                        @palande.vaibhav said:

                        @ayo
                        But adding #define MY_GATEWAY_SERIAL to the code for the sensor node will make it a gateway. Right? Please check my last post where I posted the screenshots of this making both of them initialize as the gateway.

                        And if both are gateways they won't communicate

                        palande.vaibhavP Offline
                        palande.vaibhavP Offline
                        palande.vaibhav
                        wrote on last edited by
                        #32

                        @ayo
                        Then this makes library 2.0 completely useless cause we always have to use MY_GATEWAY_SERIAL and so can't create sensor nodes.

                        If you also confirm this then I am gonna report this as a bug.

                        ayoA 1 Reply Last reply
                        0
                        • palande.vaibhavP palande.vaibhav

                          @ayo
                          Then this makes library 2.0 completely useless cause we always have to use MY_GATEWAY_SERIAL and so can't create sensor nodes.

                          If you also confirm this then I am gonna report this as a bug.

                          ayoA Offline
                          ayoA Offline
                          ayo
                          wrote on last edited by ayo
                          #33

                          No it is not like that.

                          You can create sensor nodes without the MY_Gateway_Serial thing, you just have to make sure that you have one device acting as a gateway device and the rest as a sensor node and everything will work very fine.

                          The reason you are having problem is because you are only building with one device and the library requires at-least 2 devices to work.

                          @palande.vaibhav said:

                          @ayo
                          Then this makes library 2.0 completely useless cause we always have to use MY_GATEWAY_SERIAL and so can't create sensor nodes.

                          If you also confirm this then I am gonna report this as a bug.

                          palande.vaibhavP 1 Reply Last reply
                          1
                          • ayoA ayo

                            No it is not like that.

                            You can create sensor nodes without the MY_Gateway_Serial thing, you just have to make sure that you have one device acting as a gateway device and the rest as a sensor node and everything will work very fine.

                            The reason you are having problem is because you are only building with one device and the library requires at-least 2 devices to work.

                            @palande.vaibhav said:

                            @ayo
                            Then this makes library 2.0 completely useless cause we always have to use MY_GATEWAY_SERIAL and so can't create sensor nodes.

                            If you also confirm this then I am gonna report this as a bug.

                            palande.vaibhavP Offline
                            palande.vaibhavP Offline
                            palande.vaibhav
                            wrote on last edited by palande.vaibhav
                            #34

                            @ayo
                            How can I make sensor nodes with the MY_GATEWAY_SERIAL line in the code. This just makes the device a gateway. How do I make it a sensor node with that line included?

                            Just having two different devices in the same code will work??

                            Like in this code:

                            /**
                             * 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.
                             *
                             *******************************
                             *
                             * DESCRIPTION
                             *
                             * Interrupt driven binary switch example with dual interrupts
                             * Author: Patrick 'Anticimex' Fallberg
                             * Connect one button or door/window reed switch between 
                             * digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
                             * one in similar fashion on digital I/O pin 2.
                             * This example is designed to fit Arduino Nano/Pro Mini
                             * 
                             */
                            
                            
                            // Enable debug prints to serial monitor
                            #define MY_DEBUG 
                            
                            // Enable and select radio type attached
                            #define MY_RADIO_NRF24
                            //#define MY_RADIO_RFM69
                            
                            //#define MY_GATEWAY_SERIAL
                            
                            #define MY_NODE_ID 1
                            
                            #include <SPI.h>
                            #include <MySensors.h>
                            
                            #define SKETCH_NAME "Binary Sensor"
                            #define SKETCH_MAJOR_VER "1"
                            #define SKETCH_MINOR_VER "0"
                            
                            #define PRIMARY_CHILD_ID 3
                            #define SECONDARY_CHILD_ID 4
                            
                            #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
                            #define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
                            
                            #if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
                            #error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
                            #endif
                            #if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
                            #error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
                            #endif
                            #if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
                            #error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
                            #endif
                            #if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
                            #error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
                            #endif
                             
                            
                            // Change to V_LIGHT if you use S_LIGHT in presentation below
                            MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
                            MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
                            
                            void setup()  
                            {  
                              // Setup the buttons
                              pinMode(PRIMARY_BUTTON_PIN, INPUT);
                              pinMode(SECONDARY_BUTTON_PIN, INPUT);
                              pinMode(8,OUTPUT);
                            
                              // Activate internal pull-ups
                              digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
                              digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
                            
                              Serial.begin(115200);
                            }
                            
                            void presentation() {
                              // Send the sketch version information to the gateway and Controller
                              sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
                            
                               Register binary input sensor to sensor_node (they will be created as child devices)
                               You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                               If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                              present(PRIMARY_CHILD_ID, S_DOOR);  
                              present(SECONDARY_CHILD_ID, S_DOOR);  
                            }
                            
                            // Loop will iterate on changes on the BUTTON_PINs
                            void loop() 
                            {
                              uint8_t value;
                              static uint8_t sentValue=2;
                              static uint8_t sentValue2=2;
                            
                              // Short delay to allow buttons to properly settle
                              //sleep(5);
                              
                              value = digitalRead(PRIMARY_BUTTON_PIN);
                              
                              if (value != sentValue) {
                                 // Value has changed from last transmission, send the updated value
                                 send(msg.set(value==HIGH ? 1 : 0));
                                 digitalWrite(8,!(digitalRead(8)));
                            
                                 String string = "Value changed to: ";
                            
                                 Serial.println(string += value);
                                 sentValue = value;
                              }
                            
                              value = digitalRead(SECONDARY_BUTTON_PIN);
                              
                              if (value != sentValue2) {
                                 // Value has changed from last transmission, send the updated value
                                 send(msg2.set(value==HIGH ? 1 : 0));
                                 sentValue2 = value;
                              }
                            
                              // Sleep until something happens with the sensor
                              sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
                              //sleep(0,CHANGE,0);
                            } 
                            
                            ayoA 1 Reply Last reply
                            0
                            • ayoA Offline
                              ayoA Offline
                              ayo
                              wrote on last edited by
                              #35

                              I was able to make the blinking thing run with #Define MY_GATEWAY_SERIAL commented out by having another Arduino Uno runing the gateway serial program. Basically you will need two devices setup to work or you could make use of this hack
                              too which will also make your device work too without having to connect to the parent.

                              Go to your library folder and find the mysensors library folder open it and look for the core folder open the MySensorCore.cpp file make sure you have a backup of that file before opening it.

                              Find this section of the code

                              #if defined(MY_RADIO_FEATURE)
                              		// Save static parent id in eeprom (used by bootloader)
                              		hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);
                              		debug(PSTR("Starting Connection Process\n"));
                              		transportInitialize();
                              		// My modification should be removed for later
                              		debug(PSTR("Starting Connection Process 2\n"));
                              		int counter = 0;
                              		while (!isTransportOK()) {
                              			hwWatchdogReset();
                              			transportProcess();
                              			//debug(PSTR("Trying to connect to parent \n"));
                              			#if defined(ARDUINO_ARCH_ESP8266)
                              				yield();
                              			#endif
                              			counter++;
                              			if (counter >= 3) // exit after 3 attempts to connect
                              				break;
                              		}
                              		debug(PSTR("Starting Connection Process 3\n"));
                              	#endif
                              

                              You can replace that section with those or just make those modification you see.
                              Save and try to upload your program again with the #define MY_Gateway_Serial thing commented out and the program will still run.

                              What that modification does is to exit the loop after 3 connection attempts.

                              palande.vaibhavP 1 Reply Last reply
                              1
                              • palande.vaibhavP palande.vaibhav

                                @ayo
                                How can I make sensor nodes with the MY_GATEWAY_SERIAL line in the code. This just makes the device a gateway. How do I make it a sensor node with that line included?

                                Just having two different devices in the same code will work??

                                Like in this code:

                                /**
                                 * 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.
                                 *
                                 *******************************
                                 *
                                 * DESCRIPTION
                                 *
                                 * Interrupt driven binary switch example with dual interrupts
                                 * Author: Patrick 'Anticimex' Fallberg
                                 * Connect one button or door/window reed switch between 
                                 * digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
                                 * one in similar fashion on digital I/O pin 2.
                                 * This example is designed to fit Arduino Nano/Pro Mini
                                 * 
                                 */
                                
                                
                                // Enable debug prints to serial monitor
                                #define MY_DEBUG 
                                
                                // Enable and select radio type attached
                                #define MY_RADIO_NRF24
                                //#define MY_RADIO_RFM69
                                
                                //#define MY_GATEWAY_SERIAL
                                
                                #define MY_NODE_ID 1
                                
                                #include <SPI.h>
                                #include <MySensors.h>
                                
                                #define SKETCH_NAME "Binary Sensor"
                                #define SKETCH_MAJOR_VER "1"
                                #define SKETCH_MINOR_VER "0"
                                
                                #define PRIMARY_CHILD_ID 3
                                #define SECONDARY_CHILD_ID 4
                                
                                #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
                                #define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
                                
                                #if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
                                #error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
                                #endif
                                #if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
                                #error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
                                #endif
                                #if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
                                #error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
                                #endif
                                #if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
                                #error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
                                #endif
                                 
                                
                                // Change to V_LIGHT if you use S_LIGHT in presentation below
                                MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
                                MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
                                
                                void setup()  
                                {  
                                  // Setup the buttons
                                  pinMode(PRIMARY_BUTTON_PIN, INPUT);
                                  pinMode(SECONDARY_BUTTON_PIN, INPUT);
                                  pinMode(8,OUTPUT);
                                
                                  // Activate internal pull-ups
                                  digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
                                  digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
                                
                                  Serial.begin(115200);
                                }
                                
                                void presentation() {
                                  // Send the sketch version information to the gateway and Controller
                                  sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
                                
                                   Register binary input sensor to sensor_node (they will be created as child devices)
                                   You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                                   If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                                  present(PRIMARY_CHILD_ID, S_DOOR);  
                                  present(SECONDARY_CHILD_ID, S_DOOR);  
                                }
                                
                                // Loop will iterate on changes on the BUTTON_PINs
                                void loop() 
                                {
                                  uint8_t value;
                                  static uint8_t sentValue=2;
                                  static uint8_t sentValue2=2;
                                
                                  // Short delay to allow buttons to properly settle
                                  //sleep(5);
                                  
                                  value = digitalRead(PRIMARY_BUTTON_PIN);
                                  
                                  if (value != sentValue) {
                                     // Value has changed from last transmission, send the updated value
                                     send(msg.set(value==HIGH ? 1 : 0));
                                     digitalWrite(8,!(digitalRead(8)));
                                
                                     String string = "Value changed to: ";
                                
                                     Serial.println(string += value);
                                     sentValue = value;
                                  }
                                
                                  value = digitalRead(SECONDARY_BUTTON_PIN);
                                  
                                  if (value != sentValue2) {
                                     // Value has changed from last transmission, send the updated value
                                     send(msg2.set(value==HIGH ? 1 : 0));
                                     sentValue2 = value;
                                  }
                                
                                  // Sleep until something happens with the sensor
                                  sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
                                  //sleep(0,CHANGE,0);
                                } 
                                
                                ayoA Offline
                                ayoA Offline
                                ayo
                                wrote on last edited by
                                #36

                                I meant without the MY_Gateway_Serial thing
                                @palande.vaibhav said:

                                @ayo
                                How can I make sensor nodes with the MY_GATEWAY_SERIAL line in the code. This just makes the device a gateway. How do I make it a sensor node with that line included?

                                Just having two different devices in the same code will work??

                                Like in this code:

                                /**
                                 * 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.
                                 *
                                 *******************************
                                 *
                                 * DESCRIPTION
                                 *
                                 * Interrupt driven binary switch example with dual interrupts
                                 * Author: Patrick 'Anticimex' Fallberg
                                 * Connect one button or door/window reed switch between 
                                 * digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
                                 * one in similar fashion on digital I/O pin 2.
                                 * This example is designed to fit Arduino Nano/Pro Mini
                                 * 
                                 */
                                
                                
                                // Enable debug prints to serial monitor
                                #define MY_DEBUG 
                                
                                // Enable and select radio type attached
                                #define MY_RADIO_NRF24
                                //#define MY_RADIO_RFM69
                                
                                //#define MY_GATEWAY_SERIAL
                                
                                #define MY_NODE_ID 1
                                
                                #include <SPI.h>
                                #include <MySensors.h>
                                
                                #define SKETCH_NAME "Binary Sensor"
                                #define SKETCH_MAJOR_VER "1"
                                #define SKETCH_MINOR_VER "0"
                                
                                #define PRIMARY_CHILD_ID 3
                                #define SECONDARY_CHILD_ID 4
                                
                                #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
                                #define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
                                
                                #if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
                                #error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
                                #endif
                                #if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
                                #error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
                                #endif
                                #if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
                                #error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
                                #endif
                                #if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
                                #error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
                                #endif
                                 
                                
                                // Change to V_LIGHT if you use S_LIGHT in presentation below
                                MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
                                MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
                                
                                void setup()  
                                {  
                                  // Setup the buttons
                                  pinMode(PRIMARY_BUTTON_PIN, INPUT);
                                  pinMode(SECONDARY_BUTTON_PIN, INPUT);
                                  pinMode(8,OUTPUT);
                                
                                  // Activate internal pull-ups
                                  digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
                                  digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
                                
                                  Serial.begin(115200);
                                }
                                
                                void presentation() {
                                  // Send the sketch version information to the gateway and Controller
                                  sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
                                
                                   Register binary input sensor to sensor_node (they will be created as child devices)
                                   You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                                   If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                                  present(PRIMARY_CHILD_ID, S_DOOR);  
                                  present(SECONDARY_CHILD_ID, S_DOOR);  
                                }
                                
                                // Loop will iterate on changes on the BUTTON_PINs
                                void loop() 
                                {
                                  uint8_t value;
                                  static uint8_t sentValue=2;
                                  static uint8_t sentValue2=2;
                                
                                  // Short delay to allow buttons to properly settle
                                  //sleep(5);
                                  
                                  value = digitalRead(PRIMARY_BUTTON_PIN);
                                  
                                  if (value != sentValue) {
                                     // Value has changed from last transmission, send the updated value
                                     send(msg.set(value==HIGH ? 1 : 0));
                                     digitalWrite(8,!(digitalRead(8)));
                                
                                     String string = "Value changed to: ";
                                
                                     Serial.println(string += value);
                                     sentValue = value;
                                  }
                                
                                  value = digitalRead(SECONDARY_BUTTON_PIN);
                                  
                                  if (value != sentValue2) {
                                     // Value has changed from last transmission, send the updated value
                                     send(msg2.set(value==HIGH ? 1 : 0));
                                     sentValue2 = value;
                                  }
                                
                                  // Sleep until something happens with the sensor
                                  sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
                                  //sleep(0,CHANGE,0);
                                } 
                                
                                1 Reply Last reply
                                0
                                • ayoA ayo

                                  I was able to make the blinking thing run with #Define MY_GATEWAY_SERIAL commented out by having another Arduino Uno runing the gateway serial program. Basically you will need two devices setup to work or you could make use of this hack
                                  too which will also make your device work too without having to connect to the parent.

                                  Go to your library folder and find the mysensors library folder open it and look for the core folder open the MySensorCore.cpp file make sure you have a backup of that file before opening it.

                                  Find this section of the code

                                  #if defined(MY_RADIO_FEATURE)
                                  		// Save static parent id in eeprom (used by bootloader)
                                  		hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);
                                  		debug(PSTR("Starting Connection Process\n"));
                                  		transportInitialize();
                                  		// My modification should be removed for later
                                  		debug(PSTR("Starting Connection Process 2\n"));
                                  		int counter = 0;
                                  		while (!isTransportOK()) {
                                  			hwWatchdogReset();
                                  			transportProcess();
                                  			//debug(PSTR("Trying to connect to parent \n"));
                                  			#if defined(ARDUINO_ARCH_ESP8266)
                                  				yield();
                                  			#endif
                                  			counter++;
                                  			if (counter >= 3) // exit after 3 attempts to connect
                                  				break;
                                  		}
                                  		debug(PSTR("Starting Connection Process 3\n"));
                                  	#endif
                                  

                                  You can replace that section with those or just make those modification you see.
                                  Save and try to upload your program again with the #define MY_Gateway_Serial thing commented out and the program will still run.

                                  What that modification does is to exit the loop after 3 connection attempts.

                                  palande.vaibhavP Offline
                                  palande.vaibhavP Offline
                                  palande.vaibhav
                                  wrote on last edited by
                                  #37

                                  @ayo

                                  Oh I get it now. Now I understand. I must have a gateway and at least one sensor node running for this to work. If there is no gateway then sensor nodes don't work because of the constant loop trying to find a parent.

                                  My problem was I was trying to write and run the code with just the sensor node.

                                  I will also do the modifications you mentioned to the core files.

                                  Thanx a lot for your help. I really appreciate it. :+1:

                                  1 Reply Last reply
                                  2
                                  • ayoA Offline
                                    ayoA Offline
                                    ayo
                                    wrote on last edited by
                                    #38

                                    That's correct :)

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


                                    12

                                    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