Novice user with serial gateway issues!



  • I've recently started tinkering with sensors, and I'm running into a couple of problems I'm having a hard time sorting.

    I've built a serial gateway and a couple of motion sensors as described in the examples. The first motion sensor I built is working well, connecting to the gateway, and communicating when it trips. Horray!

    But when I tried building a second motion sensor, it fails to receive an ID from the gateway.

    I'm using the latest example sketches for both the gateway and the motion sensors and the same hardware for all my devices. I've checked the wiring carefully, completely redone the wiring, and swapped out each hardware component individually with no change in the behavior of the sensor. I've also tried restarting, reflashing, and clearing EEPROM on all sensors and the gateway.

    Any thoughts on what might be causing this?

    Also, is there any good resource for how node/child IDs get assigned? I didn't find anything super clear when I looked. I have a suspicion that it may be something to do with ID assignment because when I try to use the pymysensors Python library, it gets confused over which IDs are assigned versus which it expects to be assigned.

    Serial Gateway log (with failing sensor active):

    0;255;3;0;9;682089 TSF:MSG:READ,255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;682095 TSF:MSG:BC
    0;255;3;0;9;682098 TSF:MSG:FPAR REQ,ID=255
    0;255;3;0;9;682102 TSF:PNG:SEND,TO=0
    0;255;3;0;9;682105 TSF:CKU:OK
    0;255;3;0;9;682107 TSF:MSG:GWL OK
    0;255;3;0;9;682240 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    0;255;3;0;9;690179 TSF:MSG:READ,255-255-0,s=75,c=3,t=3,pt=0,l=0,sg=0:
    255;75;3;0;3;
    

    Motion sensor log for failing sensor:

    10:11:48.404 -> 
    10:11:48.404 -> 17 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=0,VER=2.4.0-alpha
    10:11:48.404 -> 27 TSM:INIT
    10:11:48.404 -> 28 TSF:WUR:MS=0
    10:11:48.404 -> 35 TSM:INIT:TSP OK
    10:11:48.440 -> 37 TSM:FPAR
    10:11:48.440 -> 39 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    10:11:50.440 -> 2048 !TSM:FPAR:NO REPLY
    10:11:50.440 -> 2050 TSM:FPAR
    10:11:50.440 -> 2052 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    10:11:52.462 -> 4060 !TSM:FPAR:NO REPLY
    10:11:52.462 -> 4062 TSM:FPAR
    10:11:52.462 -> 4064 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    10:11:52.599 -> 4212 TSF:MSG:READ,0-0-255,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    10:11:52.599 -> 4217 TSF:MSG:FPAR OK,ID=0,D=1
    10:11:54.487 -> 6072 TSM:FPAR:OK
    10:11:54.487 -> 6073 TSM:ID
    10:11:54.487 -> 6074 TSM:ID:REQ
    10:11:54.487 -> 6077 TSF:MSG:SEND,255-255-0-0,s=186,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
    10:11:56.509 -> 8084 TSM:ID
    10:11:56.509 -> 8085 TSM:ID:REQ
    10:11:56.509 -> 8087 TSF:MSG:SEND,255-255-0-0,s=149,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
    10:11:58.501 -> 10095 TSM:ID
    10:11:58.501 -> 10096 TSM:ID:REQ
    10:11:58.501 -> 10099 TSF:MSG:SEND,255-255-0-0,s=112,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
    10:12:00.522 -> 12106 TSM:ID
    10:12:00.522 -> 12107 TSM:ID:REQ
    10:12:00.556 -> 12110 TSF:MSG:SEND,255-255-0-0,s=75,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
    

    Serial Gateway log (with working sensor active):

    0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=0,VER=2.4.0-alpha
    0;255;3;0;9;6 TSM:INIT
    0;255;3;0;9;8 TSF:WUR:MS=0
    0;255;3;0;9;15 TSM:INIT:TSP OK
    0;255;3;0;9;18 TSM:INIT:GW MODE
    0;255;3;0;9;21 TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;24 MCO:REG:NOT NEEDED
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.4.0-alpha
    0;255;3;0;9;29 MCO:BGN:STP
    0;255;3;0;9;36 MCO:BGN:INIT OK,TSP=1
    0;255;3;0;9;39 TSM:READY:NWD REQ
    0;255;3;0;9;45 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    0;255;3;0;9;555 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;1930 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;3302 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;4676 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;6050 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;7424 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;8796 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;10181 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;11553 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;12487 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
    1;1;1;0;16;1
    0;255;3;0;9;13859 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
    1;1;1;0;16;1
    0;255;3;0;9;15232 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
    1;1;1;0;16;1
    0;255;3;0;9;16604 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
    1;1;1;0;16;1
    0;255;3;0;9;17613 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;18985 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    1;1;1;0;16;0
    0;255;3;0;9;20358 TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    

    Motion sensor log for working sensor:

    10:20:33.848 -> 17 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=0,VER=2.4.0-alpha
    10:20:33.848 -> 27 TSM:INIT
    10:20:33.848 -> 28 TSF:WUR:MS=0
    10:20:33.848 -> 35 TSM:INIT:TSP OK
    10:20:33.848 -> 37 TSF:SID:OK,ID=1
    10:20:33.886 -> 38 TSM:FPAR
    10:20:33.886 -> 43 ?TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    10:20:35.879 -> 2050 !TSM:FPAR:NO REPLY
    10:20:35.879 -> 2052 TSM:FPAR
    10:20:35.879 -> 2056 ?TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    10:20:36.158 -> 2318 TSF:MSG:READ,0-0-1,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    10:20:36.158 -> 2323 TSF:MSG:FPAR OK,ID=0,D=1
    10:20:37.900 -> 4063 TSM:FPAR:OK
    10:20:37.900 -> 4064 TSM:ID
    10:20:37.900 -> 4065 TSM:ID:OK
    10:20:37.900 -> 4067 TSM:UPL
    10:20:37.900 -> 4072 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    10:20:37.900 -> 4080 TSF:MSG:READ,0-0-1,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    10:20:37.900 -> 4085 TSF:MSG:PONG RECV,HP=1
    10:20:37.900 -> 4088 TSM:UPL:OK
    10:20:37.900 -> 4089 TSM:READY:ID=1,PAR=0,DIS=1
    10:20:37.933 -> 4097 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    10:20:37.933 -> 4104 TSF:MSG:READ,0-0-1,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    10:20:37.933 -> 4114 TSF:MSG:SEND,1-1-0-0,s=255,c=0,t=17,pt=0,l=11,sg=0,ft=0,st=OK:2.4.0-alpha
    10:20:37.933 -> 4123 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    10:20:39.983 -> 6170 !TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=11,pt=0,l=13,sg=0,ft=0,st=NACK:Motion Sensor
    10:20:40.020 -> 6215 !TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=1,st=NACK:1.0
    10:20:40.088 -> 6257 !TSF:MSG:SEND,1-1-0-0,s=1,c=0,t=1,pt=0,l=0,sg=0,ft=2,st=NACK:
    10:20:40.088 -> 6263 MCO:REG:REQ
    10:20:40.122 -> 6300 !TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=3,st=NACK:2
    10:20:42.148 -> 8342 !TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=4,st=NACK:2
    10:20:42.184 -> 8349 TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    10:20:42.184 -> 8354 MCO:PIM:NODE REG=1
    10:20:42.184 -> 8356 MCO:BGN:STP
    10:20:42.184 -> 8358 MCO:BGN:INIT OK,TSP=1
    10:20:42.184 -> 0
    10:20:42.184 -> 8372 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=5,st=OK:0
    10:20:42.184 -> 8378 MCO:SLP:MS=1200,SMS=0,I1=1,M1=1,I2=255,M2=255
    10:20:42.184 -> 8382 TSF:TDI:TSL
    10:20:42.834 -> 8384 MCO:SLP:WUP=1
    10:20:42.834 -> 8385 TSF:TRI:TSB
    10:20:42.834 -> 1
    10:20:42.834 -> 8400 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
    10:20:42.834 -> 8407 MCO:SLP:MS=1200,SMS=0,I1=1,M1=1,I2=255,M2=255
    10:20:42.834 -> 8411 TSF:TDI:TSL
    10:20:44.195 -> 8413 MCO:SLP:WUP=-1
    10:20:44.195 -> 8415 TSF:TRI:TSB
    10:20:44.195 -> 1
    10:20:44.195 -> 8427 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
    10:20:44.195 -> 8433 MCO:SLP:MS=1200,SMS=0,I1=1,M1=1,I2=255,M2=255
    10:20:44.195 -> 8437 TSF:TDI:TSL
    10:20:45.554 -> 8439 MCO:SLP:WUP=-1
    10:20:45.554 -> 8441 TSF:TRI:TSB
    10:20:45.589 -> 1
    10:20:45.623 -> 8483 !TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=NACK:1
    10:20:45.623 -> 8489 MCO:SLP:MS=1200,SMS=0,I1=1,M1=1,I2=255,M2=255
    10:20:45.623 -> 8495 TSF:TDI:TSL
    10:20:45.623 -> 8496 MCO:SLP:WUP=1
    10:20:45.623 -> 8498 TSF:TRI:TSB
    10:20:45.659 -> 0
    
    


  • This post is deleted!


  • This post is deleted!


  • @mrmuszynski CHILD_IDs are assigned by you in your sketch for the node. They are not assigned by the gateway or controller. As for the node ID I would strongly recommend setting that manually in your sketch as well. This will make it a static ID across reboots/reconnects and saves time working out where any future issues are in the system.

    #define MY_NODE_ID 193 ......This is what you need to assign static node id just change number for each node.... Numbers 1-253 are allowed I think..

    You can also add.....
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC

    This will ensure static routing if you want.

    If you still have probelms then post the sketch for each node to get help....



  • Thanks for the help, @skywatch! I've tried what you said, and still no luck... I feel like I must be making a silly mistake. I'm using the example code exactly for the gateway, and for the motion sensors, all I've done is add the code you suggested to define MY_NODE_ID, MY_PARENT_NODE, and MY_PARENT_NODE_IS_STATIC.

    For sensor one, I use 1 as MY_NODE_ID and CHILD_ID.
    For sensor two, I use 2 as MY_NODE_ID and CHILD_ID.

    I'm still getting the same behavior, though. Sensor one is working as expected, and sensor 2 repeatedly sends I_ID_REQUEST messages with no luck.

    Here's my code:

    Gateway:

    /**
    * 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-2020 Sensnology AB
    * Full contributor list: https://github.com/mysensors/MySensors/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
    * The ArduinoGateway prints data received from sensors on the serial link.
    * The gateway accepts input on serial which will be sent out on radio network.
    *
    * The GW code is designed for Arduino Nano 328p / 16MHz
    *
    * Wire connections (OPTIONAL):
    * - Inclusion button should be connected between digital pin 3 and GND
    * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
    *
    * LEDs (OPTIONAL):
    * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
    * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
    * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
    * - ERR (red) - fast blink on error during transmission error or receive crc error
    *
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    //#define MY_PJON
    
    // Set pin for PJON wired communication.
    //#define MY_PJON_PIN 12
    
    // 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
    
    // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <MySensors.h>
    
    void setup()
    {
    	// Setup locally attached sensors
    }
    
    void presentation()
    {
    	// Present locally attached sensors
    }
    
    void loop()
    {
    	// Send locally attached sensor data here
    }
    

    Node/Sensor 1:

    /*
     * 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-2020 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     *
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    //#define MY_PJON
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 1000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID 1   // Id of the sensor child
    
    #define MY_NODE_ID 1
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
    	pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Motion Sensor", "1.0");
    
    	// Register all sensors to gw (they will be created as child devices)
    	present(CHILD_ID, S_MOTION);
    }
    
    void loop()
    {
    	// Read digital motion value
    	bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
    	Serial.println(tripped);
    	send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    
    	// Sleep until interrupt comes in on motion sensor. Send update every two minute.
    	sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    

    Node/Sensor 2:

    /*
     * 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-2020 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     *
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    //#define MY_PJON
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 1000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID 2   // Id of the sensor child
    
    #define MY_NODE_ID 2
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
    	pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Motion Sensor", "1.0");
    
    	// Register all sensors to gw (they will be created as child devices)
    	present(CHILD_ID, S_MOTION);
    }
    
    void loop()
    {
    	// Read digital motion value
    	bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
    	Serial.println(tripped);
    	send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    
    	// Sleep until interrupt comes in on motion sensor. Send update every two minute.
    	sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    


  • @mrmuszynski OK - I see 2 possible issues here.....

    1. Your '#define' statements for your nodes and children need to be before the line #include<MySensors.h>.... This is most likely the issue here....if not...

    2. remove the #debug from the gateway as this may be writing to the serial port and causing an issue, but I am sure it is the first thing above..

    So node 1 shoule start like this.....

    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    #define MY_NODE_ID 1
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion //sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID 1   // Id of the sensor child
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 1000; // Sleep time between reports (in milliseconds)
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    

    Change node 2 similarly and try again....



  • #1 turned out to be right! Thanks for your help.

    I would love if you (or anyone else) could give some more context here for WHY this answer is correct, but I'm super happy to be unblocked.



  • @mrmuszynski I believe that it comes down to the fact that when mysensors include is 'run' it needs to already know the parameters it is running with. It can't start and then add things afterwards or it wouldn't know where to start.....For example, if it doesn't know what radio you are using it can't initialise it! ..... It's a bit like making a blueprint before building a house 😉

    Also of note is that you can use the same child_id on both nodes if you wish. It will not be a problem.



  • @skywatch That makes sense. I guess I didn't realize MySensors.h would actually reference the things I had written in the sketch. I have decent programming experience, by my Arduino/cpp experience is very thin.

    Another question for you... what exactly is the difference between a sensor and a node? Since you flash the code to an adruino that has both the radio and the sensor circuit on it... How do you even include more than one child in a single node?

    Thanks for fielding some basic questions! I really appreciate it since I feel like the docs on mysensors.org are missing some of these middle-level issues.



  • @mrmuszynski This might help....

    https://www.mysensors.org/about/network

    Sensors connect to nodes, nodes connect to the radio to send/receive sensor data via the gateway to the controller. Sometimes data flows the other way to control things like leds, relays, motors etc,

    A node can have up to 254 children I believe, but that would be a bit much I think. As to how you have a lot of children, well, you could attach 7 switches to digital pins 2-8 and then have them as child ids 0-7 like this....

    #define CHILD_ID_DOOR1 0 //D2 physical pin
    #define CHILD_ID_DOOR2 1 //D3
    #define CHILD_ID_DOOR3 2 //D4

    and so on.........

    Just make sure each child_id has a unique name and number or rhe presentation won't go too well...... 😉



  • @skywatch Just to add to your points on 254 max children, definitions, presentation, etc., which may help @mrmuszynski at some stage.
    I've an array in a sketch with 14 DS18B20 addresses, all paged in turn using the one wire protocol on a single pin, so it is entirely possible to hit the 254 children limit before looking at I2C devices.

    The beauty of the DS18B20 array is individual chips are "defined" sequentially, hence making presentation and fetching values available to a FOR loop, which makes for a highly compact sketch.


Log in to reply
 

Suggested Topics

  • 3
  • 6
  • 1
  • 8
  • 2

18
Online

11.4k
Users

11.1k
Topics

112.7k
Posts