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. Relay Sketch (1.6dev ) failed messages cause relay to activate.

Relay Sketch (1.6dev ) failed messages cause relay to activate.

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • greglG Offline
    greglG Offline
    gregl
    Hero Member
    wrote on last edited by
    #1

    I'm wondering if anyone can reproduce this.

    Using the Relay actuator sketch as a base, im adding a switch ( so as to make a garage door opener/monitor) - i have this all working, except for when i encounter a failed transmission, the relay activates!

    Here is a sketch with minimal modifications from the example RelayActuator sketch - in effect all ive added to it, is to send some packets frequently, in order to generate some fail messages.: ( im running it on a rBoard -mini )

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Example sketch showing how to control physical relays. 
     * This example will remember relay state after power failure.
     * http://www.mysensors.org/build/relay
     */ 
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    #define MY_NODE_ID 4
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensor.h>
    
    #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    
    #define CHILD_ID_R1 8
    
    MyMessage doorLockMsg(CHILD_ID_R1, V_LOCK_STATUS);
    int value = 1;
    
    void setup()  
    { 
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay", "1.0");
    
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
      }
    }
    
    
    void loop() 
    {
     //generate some traffic
    
    	
    	if (value == 3000) {
    		
    		//Serial.println(value);
    		
    		send(doorLockMsg.set(value == HIGH ? 1 : 0));
    		value = 0;
    		}
    	value++ ;
    
    
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }
    
    

    Serial output looks like this:

    
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=**fail:0**
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    

    every time the fail:0 appears the relay toggles! I know its not going through the void recieve function, as there are no prints due to 'Serial.print("Incoming change for sensor:");'

    It also occurs at the intialisation phase, when the sketchname/version is sent.

    Starting repeater (RNNRA-, 2.0.0-beta)
    Radio init successful.
    send: 4-4-0-0 s=255,c=3,t=15,pt=1,l=1,sg=0,st=ok:0
    send: 4-4-0-0 s=255,c=0,t=18,pt=0,l=10,sg=0,st=fail:2.0.0-beta
    send: 4-4-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    send: 4-4-0-0 s=255,c=3,t=11,pt=0,l=5,sg=0,st=fail:Relay
    send: 4-4-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
    send: 4-4-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    Init complete, id=4, parent=0, distance=1
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    3000
    send: 4-4-0-0 s=8,c=1,t=36,pt=2,l=2,sg=0,st=ok:0
    

    Is anyone able/interested in trying to reproduce this? or any ideas what may be the cause? I will setup another arduino and relay to see if its hardware specific, but id be surprised if it was!

    Cheers,
    Greg

    1 Reply Last reply
    0
    • greglG Offline
      greglG Offline
      gregl
      Hero Member
      wrote on last edited by
      #2

      I have been able to reproduce it on a another arduino and relay. ( nano IO shield + relay board )

      but... if i move the relay from D4 to D8 there is no issue! Failed messages do not cause the relay to activate.

      Could the radio be somehow driving D4 ??

      1 Reply Last reply
      0
      • greglG Offline
        greglG Offline
        gregl
        Hero Member
        wrote on last edited by
        #3

        Ive been digging, and in MyConfig.h i see this:

        // The Error LED default pin
        #ifndef MY_DEFAULT_ERR_LED_PIN
        	#if defined(ARDUINO_ARCH_ESP8266)
        		#define MY_DEFAULT_ERR_LED_PIN 7
        	#else
        		#define MY_DEFAULT_ERR_LED_PIN 4
        	#endif
        #endif
        

        Could this be the cause?

        and if so shouldnt it be disabled by default due to line 141,
        //#define MY_LEDS_BLINKING_FEATURE

        ?

        1 Reply Last reply
        0
        • sundberg84S Offline
          sundberg84S Offline
          sundberg84
          Hardware Contributor
          wrote on last edited by
          #4

          Hi!

          Have a look here: http://forum.mysensors.org/topic/2749/1-6-gateway-possible-error/11
          Maybe something to do with this?

          Controller: Proxmox VM - Home Assistant
          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

          1 Reply Last reply
          0
          • greglG Offline
            greglG Offline
            gregl
            Hero Member
            wrote on last edited by
            #5

            Yeah -right on! In my sketch ive set them to use unused analogue pins
            #define MY_DEFAULT_TX_LED_PIN A0
            #define MY_DEFAULT_RX_LED_PIN A1
            #define MY_DEFAULT_ERR_LED_PIN A2

            ...problem went away. ;-)

            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.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