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. Development
  3. resend if st=fail

resend if st=fail

Scheduled Pinned Locked Moved Development
9 Posts 4 Posters 6.3k 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.
  • n3roN Offline
    n3roN Offline
    n3ro
    wrote on last edited by
    #1

    Hello everybody,

    has anyone built a function that resend the signal, if "st=fail" is detected?
    I've already looked at the API and ACK. But have become not really smart of it.

    This would be great for some devices like relay, alarm, ....

    Best Regards,
    n3ro

    pimatic + MySensors + Homeduino + z-way
    https://github.com/n3roGit/MySensors_n3ro

    AWIA 1 Reply Last reply
    0
    • n3roN n3ro

      Hello everybody,

      has anyone built a function that resend the signal, if "st=fail" is detected?
      I've already looked at the API and ACK. But have become not really smart of it.

      This would be great for some devices like relay, alarm, ....

      Best Regards,
      n3ro

      AWIA Offline
      AWIA Offline
      AWI
      Hero Member
      wrote on last edited by
      #2

      @n3ro you can use and catch the Ack value yourself and make sure the message arrives.

      n3roN 1 Reply Last reply
      0
      • AWIA AWI

        @n3ro you can use and catch the Ack value yourself and make sure the message arrives.

        n3roN Offline
        n3roN Offline
        n3ro
        wrote on last edited by
        #3

        @AWI do you have code example for me?

        pimatic + MySensors + Homeduino + z-way
        https://github.com/n3roGit/MySensors_n3ro

        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          gw.send() returns false when no ack was received.

          1 Reply Last reply
          1
          • n3roN Offline
            n3roN Offline
            n3ro
            wrote on last edited by
            #5

            Hey :)

            I have just build this test function to resend a signal if failed.
            But i don't know how to execute the ge.send in the string ("// execute code").

            #include <MySensor.h>
            #include <SPI.h>
            
            #define SENSOR_INFO "Test sensor"
            #define NODE_ID 200
            #define CHILD_ID 1
            #define OPEN 1
            #define CLOSE 0
            
            MySensor gw;
            MyMessage msg(CHILD_ID, V_TRIPPED);
            
            void setup()
            {
              gw.begin(NULL, NODE_ID, false);
              gw.sendSketchInfo(SENSOR_INFO, "1.0");
              gw.present(CHILD_ID, S_DOOR);
            }
            
            void loop()
            {
              gwack("gw.send(msg.set(OPEN));");
              delay(500);
            }
            void gwack(char code[])
            {
              int repeat = 0;
              boolean sendOK = false;
              Serial.println(code); // string to execute
            
              while ((sendOK == false) or (repeat <= 10))
              {
                if (code) // execute code
                {
                  Serial.println("OK");
                  sendOK = true;
                }
                else
                {
                  Serial.println("NOT OK!!");
                  sendOK = false;
                }
                repeat++;
              }
            }
            

            Any ideas? :)

            pimatic + MySensors + Homeduino + z-way
            https://github.com/n3roGit/MySensors_n3ro

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rickmontana83
              wrote on last edited by
              #6

              That's not going to work the way you wrote it. That would require the Arduino to be able to compile code, which is asking a bit much of the little micro. :-)

              I would either do the retry-on-fail logic directly inline in your loop() function, or put the gw.send() call in gwack() and pass the msg value as a reference/pointer to gwack.

              n3roN 1 Reply Last reply
              0
              • R rickmontana83

                That's not going to work the way you wrote it. That would require the Arduino to be able to compile code, which is asking a bit much of the little micro. :-)

                I would either do the retry-on-fail logic directly inline in your loop() function, or put the gw.send() call in gwack() and pass the msg value as a reference/pointer to gwack.

                n3roN Offline
                n3roN Offline
                n3ro
                wrote on last edited by
                #7

                @rickmontana83 said:

                put the gw.send() call in gwack() and pass the msg value as a reference/pointer to gwack.

                What do you mean? :)
                Like this?

                void loop()
                {
                //gw.send(msg.set(OPEN));
                  gwresend("msg.set","OPEN");
                  delay(500);
                }
                void gwresend(char msgcode[],char option[])
                {
                  int repeat = 0;
                  boolean sendOK = false;
                
                  while ((sendOK == false) or (repeat <= 10))
                  {
                    if (gw.send(msgcode(option)) // execute code
                    {
                      Serial.println("OK");
                      sendOK = true;
                    }
                    else
                    {
                      Serial.println("NOT OK!!");
                      sendOK = false;
                    }
                    repeat++;
                  }
                }
                

                (code is not working ;) )

                I'm very surprised that there is not already such a function.

                pimatic + MySensors + Homeduino + z-way
                https://github.com/n3roGit/MySensors_n3ro

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rickmontana83
                  wrote on last edited by
                  #8

                  I'd be surprised if that even compiles. (Does it?)

                  I meant you should set up the message in loop, then pass the completed message to gwresend like:

                  msg.set(OPEN);
                  gwresend(msg);

                  The signature for gwresend will be something like:

                  void gwresend(MyMessage &msg)

                  The execute code line would then just be:

                  if (gw.send(msg)) { ...

                  Don't take this the wrong way, but this is more of a basic C++ language question. You might want to poke around on StackOverflow for examples to better understand the language (like the pass by reference that I suggested above, which, being from a C background, I've always found a bit scary.)

                  1 Reply Last reply
                  0
                  • n3roN Offline
                    n3roN Offline
                    n3ro
                    wrote on last edited by n3ro
                    #9

                    Jeah now its working :)

                    #include <MySensor.h>
                    #include <SPI.h>
                    
                    #define SENSOR_INFO "Test sensor"
                    #define NODE_ID 200
                    #define CHILD_ID 1
                    #define OPEN 1
                    #define CLOSE 0
                    
                    MySensor gw;
                    MyMessage msg(CHILD_ID, V_TRIPPED);
                    
                    int repeat = 0;
                    boolean sendOK = false;
                    int repeatdelay = 0;
                    
                    void setup()
                    {
                      gw.begin(NULL, NODE_ID, false);
                      gw.sendSketchInfo(SENSOR_INFO, "1.0");
                      gw.present(CHILD_ID, S_DOOR);
                    }
                    
                    void loop()
                    {
                      resend((msg.set(OPEN)), 5);
                    delay(500);
                    
                    }
                    void resend(MyMessage &msg, int repeats)
                    {
                      int repeat = 1;
                      int repeatdelay = 0;
                      boolean sendOK = false;
                    
                      while ((sendOK == false) and (repeat < repeats)) {
                        if (gw.send(msg)) {
                          sendOK = true;
                        } else {
                          sendOK = false;
                          Serial.print("FEHLER ");
                          Serial.println(repeat);
                          repeatdelay += 250;
                        } repeat++; delay(repeatdelay);
                      }
                    }```

                    pimatic + MySensors + Homeduino + z-way
                    https://github.com/n3roGit/MySensors_n3ro

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


                    10

                    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