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. Bug Reports
  3. problem to code?

problem to code?

Scheduled Pinned Locked Moved Bug Reports
7 Posts 3 Posters 2.9k Views
  • 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.
  • Michel - ItM Offline
    Michel - ItM Offline
    Michel - It
    wrote on last edited by Michel - It
    #1
    
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    //#include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySensor.h>
    #include <SPI.h>
    #include "Bounce2.h"
    
    //char sketch_name[] = "Multy-Relay";
    //char sketch_ver[]  = "0.1";
    
    #define RELAY_ON 0                      // switch around for realy HIGH/LOW state
    #define RELAY_OFF 1
    #define DEBUG On
    //
    MySensor gw;
    
    #define RADIO_ID 45                    // radio Id, whatever channel you assigned to
    #define noRelays 2
    const int relayPin[] = {3,4}; //  switch around pins to your desire
    const int buttonPin[] = {6,7}; //  switch around pins to your desire
    
    class Relay             // relay class, store all relevant data (equivalent to struct)
    {
    public: 
      int buttonPin;                    // physical pin number of button
      int relayPin;                     // physical pin number of relay
      byte oldValue;                    // last Values for key (debounce)
      boolean relayState;               // relay status (also stored in EEPROM)
    };
    
    Relay Relays[noRelays];
    Bounce debouncer[noRelays];
    MyMessage msg[noRelays];
    
    void setup()
    {
      gw.begin(incomingMessage, RADIO_ID, true);
      delay(500);
      gw.sendSketchInfo("Bar-Multy-Relay&Interruttori", "0.4");
      delay(500);
    
      // Initialize Relays with corresponding buttons
      for (int i = 0; i < noRelays; i++)
      {
        Relays[i].buttonPin = buttonPin[i];              // assign physical pins
        Relays[i].relayPin = relayPin[i];
        msg[i].sensor = i;                                   // initialize messages
        msg[i].type = V_LIGHT;
        debouncer[i] = Bounce();                        // initialize debouncer
        debouncer[i].attach(buttonPin[i]);
        debouncer[i].interval(5);
        pinMode(Relays[i].buttonPin, INPUT_PULLUP);
        pinMode(Relays[i].relayPin, OUTPUT);
        Relays[i].relayState = gw.loadState(i);                               // retrieve last values from EEPROM
        digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
        gw.send(msg[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
        gw.present(i, V_LIGHT);                               // present sensor to gateway
        delay(250);
    
      }
    }
    
    void loop()
    {
      gw.process();
      for (byte i = 0; i < noRelays; i++)
      {
        debouncer[i].update();
        byte value = debouncer[i].read();
        //if (value != Relays[i].oldValue && value == 0)
        if (value != Relays[i].oldValue)
        {
          Relays[i].relayState = !Relays[i].relayState;
          gw.send(msg[i].set(Relays[i].relayState ? true : false));
          digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);
          gw.saveState( i, Relays[i].relayState );
        }                 // save sensor state in EEPROM (location == sensor number)
    
        Relays[i].oldValue = value;
    
      }
    }
    
    // process incoming message
    void incomingMessage(const MyMessage &message)
    {
    
      if (message.type == V_LIGHT)
      {
        if (message.sensor < noRelays)            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
        {
          Relays[message.sensor].relayState = message.getBool();
          digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
          gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
        }
      }
    }
    
    

    REport

    send: 44-44-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=fail:0
    send: 44-44-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=fail:1.5.4
    send: 44-44-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
    repeater started, id=44, parent=0, distance=0
    send: 44-44-0-0 s=255,c=3,t=11,pt=0,l=25,sg=0,st=fail:Bar-Multy-Relay&Interrutt
    send: 44-44-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:0.4
    send: 44-44-0-0 s=0,c=1,t=2,pt=2,l=2,sg=0,st=fail:0
    find parent
    send: 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    send: 44-44-0-0 s=0,c=0,t=2,pt=0,l=0,sg=0,st=fail:
    send: 44-44-0-0 s=1,c=1,t=2,pt=2,l=2,sg=0,st=fail:0
    send: 44-44-0-0 s=1,c=0,t=2,pt=0,l=0,sg=0,st=fail:
    send: 44-44-0-0 s=0,c=1,t=2,pt=2,l=2,sg=0,st=fail:1
    send: 44-44-0-0 s=1,c=1,t=2,pt=2,l=2,sg=0,st=fail:1
    
    <<< reset button
    
    send: 44-44-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=fail:0
    send: 44-44-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=fail:1.5.4
    send: 44-44-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
    repeater started, id=44, parent=0, distance=0
    send: 44-44-0-0 s=255,c=3,t=11,pt=0,l=25,sg=0,st=fail:Bar-Multy-Relay&Interrutt
    send: 44-44-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:0.4
    send: 44-44-0-0 s=0,c=1,t=2,pt=2,l=2,sg=0,st=fail:1
    find parent
    send: 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    send: 44-44-0-0 s=0,c=0,t=2,pt=0,l=0,sg=0,st=fail:
    send: 44-44-0-0 s=1,c=1,t=2,pt=2,l=2,sg=0,st=fail:1
    send: 44-44-0-0 s=1,c=0,t=2,pt=0,l=0,sg=0,st=fail:
    send: 44-44-0-0 s=0,c=1,t=2,pt=2,l=2,sg=0,st=fail:0
    send: 44-44-0-0 s=1,c=1,t=2,pt=2,l=2,sg=0,st=fail:0
    

    :triumph:

    1 Reply Last reply
    0
    • Michel - ItM Offline
      Michel - ItM Offline
      Michel - It
      wrote on last edited by
      #2

      alt text
      alt text

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

        "st=fail" means the receiving node or gateway has problems sending ack back to the sending node.

        Its probably a hardware/radio issue (power and/or range). Try adding a capacitor (http://www.mysensors.org/build/connect_radio#connecting-a-decoupling-capacitor) to the receiving radio, change powersource, move receiver/sender closer to each other or build a repeater.

        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
        1
        • D Offline
          D Offline
          DavidZH
          wrote on last edited by
          #4

          It might be the board you're using. I had similar issues when I was building my weather node with the same proto-board. After I switched to single sided board it worked immediately. The copper might reflect RF-energy back to the radio and your Arduino that interfere with the transmission.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sundberg84
            Hardware Contributor
            wrote on last edited by sundberg84
            #5

            Also the relays can cause problems - they cause spikes in the circuit which the radio dislikes. Try replacing the relays with leds or something and see what happens.

            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
            1
            • Michel - ItM Offline
              Michel - ItM Offline
              Michel - It
              wrote on last edited by
              #6

              the problem was the radio module nrf24, replacing it I solved

              ps
              when you see lots of nrf24 not buy them on the cheap. thank you all for the support

              1 Reply Last reply
              1
              • Michel - ItM Offline
                Michel - ItM Offline
                Michel - It
                wrote on last edited by Michel - It
                #7

                the project
                http://forum.mysensors.org/topic/3721/2-switch-2-relay/2

                1 Reply Last reply
                0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                17

                Online

                12.1k

                Users

                11.2k

                Topics

                113.4k

                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