Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. amemo06
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by amemo06

    • RE: 💬 Relay

      Hi Everyone,
      maybe the below will help people facing random incorrect behaviors.
      In sample from december 2016 /mysensors/MySensors/examples/RelayActuator/RelayActuator.ino, there is something which could be seen as a bug.

      In my case, I have used that sample to control a lot of relais. I noticed some rare but really annoying errors. From time to time a relay got switched incorrectly.
      Annoying and strange as coding was pretty straightforward. All relais are coded to act in pulse mode.

                digitalWrite(message.sensor-1+RELAY_1, RELAY_OFF);
                wait(1000);
                digitalWrite(message.sensor-1+RELAY_1, RELAY_ON);
      

      And this is the reason of the bug.

      Explanation.
      During that second of wait, a lot of things may occurs. Due to the 'message' declaration, it is possible that the 'message' is getting changed.
      Typically a ping may come and as result the 'message' is not anymore the same.

      For that reason I would suggest the code to be changed a little bit.

      void receive(const MyMessage &message_orig)
      {
        MyMessage message;
        message = message_orig;
      

      This way, the function works with a local copy and you are sure nothing can change during the processing.

      Anyway, thanks for the sample it was nevertheless very helpful

      posted in Announcements
      amemo06
      amemo06
    • RE: 💬 Relay

      @gohan This is not in the original coding. I needed something like a wait in order to make a relay pulse.
      The wait increases the risk or the frequency of the trouble. Removing it does not solves the issue.
      Processing of the function will always take time. And the message can still changes before reaching the end like it is show in the second trace.

      posted in Announcements
      amemo06
      amemo06
    • RE: 💬 Relay

      @BulldogLowell said in 💬 Relay:

      MsTimer2::

      Thanks for the MSTimer, I was not aware of it.
      And yes, definitively, having a wait() is probably the worst I could have written. Active wait cannot stay.
      My intention, in the stuff I develop, was to remove it asap and probably by handling the wait time in the loop with flags.

      Maybe I was not clear enough about my intention when I opened this thread. I have no issue with what I develop. I already had several ways to solves this. And now, I have a new one with MSTimer. Again thanks.

      I only wanted to raise the fact void receive(const MyMessage &message) may lead to trouble as 'message' content may change during processing of that function.
      And if, like many, you are not skilled enough to code/debug.., you will face erratic issues and real difficulty to understand what is going wrong.

      posted in Announcements
      amemo06
      amemo06