Navigation

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

    Best posts made by marcusvdt

    • How to deal with a request for information from controller?

      I'm building some sensors and planning to use a self build controller in the future. For the meantime, I'm sending commands from my computer through a serial terminal to the gateway which them forwards these commands to the nodes.
      I'm trying to figure out how to make the node respond to a req message from the controller and to send the acks as requested.

      This is what I'm sending from the controller:
      51;99;2;1;2;\n
      Which to me, means:
      node id: 51
      child id:99
      message type: 2 (req)
      ack: 1 (request ack)
      sub type: 1 (V_LIGHT)
      payload: none

      The purpose of this message is to get the current status of a light actuator. I need this because this light actuator has a button to control the lights. My sketch does inform the gateway when I switch the light on/off through the button attached to the node, but I want to deal with the case where the communication may have failed between the node and the gateway at the time the button has been used to control the lights. This situation could be the controller is down for some reason, there is something interfering with the radio comms, etc.

      Well, I suppose I need to deal with the ack response and the req response in my sketch. Am I right?
      If so, I'm looking for examples on how to differentiate between a message that is sent from the controller to the node (obviously through the gateway) to either change the light status OR to request the current light status. I know the sub-type of the message would change from 1 to 2 respectively, but I don't know what is the way to read this value from the incoming messages.
      The other thing I'm looking for, is if the ack response is automatically generated and sent from the controller, and if not, how do I read an ack incoming message and how do I respond to it. A simple function example is well enough.

      Please correct me if I'm wrong in any of my previous statements.

      Thanks!

      posted in Troubleshooting
      marcusvdt
      marcusvdt
    • RE: How to deal with a request for information from controller?

      Well, it seems nobody has either the motivation or the answer itself... Wonder if I should have posted this question in the Development forum instead...
      I've been researching and doing some trial and error since I posted the question, and it seems I found a way of doing it. Not sure if this is the correct way because I just did not find any documentation about it, but I'll share my discoveries anyway since it can help others.

      It seems the ack part is done automatically by the library itself. I've been able to see ack messages returning from the gateway to the controller without doing any treatment myself in my sketch.

      Regarding how to differentiate "req" messages sent from the controller to a node, I've been able to detect if a message is a "req" one by reading the value of mGetCommand(message) in my sketch. If this is equal to 2, then it is a "req" message, if it is equal to 1, then it is a "set" message.

      void incomingMessage(const MyMessage &message) {
      //debug only
      //Serial.print("message.destination=");
      //Serial.println(message.destination);
      //Serial.print("message.type=");
      //Serial.println(message.type);
      //Serial.print("message.sensor");
      //Serial.println(message.sensor);
      
      int comando = mGetCommand(message);
      //Serial.print("comando=");
      //Serial.println(comando);
      
        if (message.type==V_LIGHT) {
          //comando=2 means information has been requested from controller, so we will send it back.
          //comando=1 means a new status has been received from controller to the node, so we will act as requested.
          if (comando==2){
            gw.send(lightMsg.set(digitalRead(lightPin)));
          }
          if (comando==1){
            // Change relay state
            setLightState(message.getBool(), false); 
            // Write some debug info
            Serial.print("Incoming light status:");
            Serial.println(message.getBool());
          }
         }
        if (message.type==V_VAR1) {
          // Toggle program mode
          if (programModeActive == false){     // If we're not in programming mode, turn it on.
            programmingmode(1);
          } else {                             // If we are in programing mode, turn it off.
            programmingmode(0);
          } 
          // Write some debug info
          Serial.print("Toggled program mode:");
          Serial.println(message.getBool()); 
        }
      }
      

      And below are the tests that show what I mentioned.

      Sent this, which sets the light child 99 on node 51 to 1 (on), requesting an ack
      51;99;1;1;2;1

      0;0;3;0;14;Gateway startup complete.
      0;0;3;0;9;send: 0-0-51-51 s=99,c=1,t=2,pt=0,l=1,st=ok:1
      0;0;3;0;9;read: 51-51-0 s=99,c=1,t=2,pt=0,l=1:1
      51;99;1;1;2;1
      

      The last one is the ack itself that returned from the gateway to the controller.

      Then sent this, which requests the status of light child 99 on node 51, requesting an ack. Should return the ack and the response containing the current status of the light (1).
      51;99;2;1;2;anything

      0;0;3;0;9;send: 0-0-51-51 s=99,c=2,t=2,pt=0,l=8,st=ok:anything
      0;0;3;0;9;read: 51-51-0 s=99,c=2,t=2,pt=0,l=8:anything
      51;99;2;1;2;anything
      0;0;3;0;9;read: 51-51-0 s=99,c=1,t=2,pt=2,l=2:1
      51;99;1;0;2;1
      

      This "51;99;2;1;2;anything" is the ack generated automatically by the library, and this "51;99;1;0;2;1" is the response that my program performs. Correct!

      Then sent this, which sets the light child 99 on node 51 to 0 (off), requesting an ack
      51;99;1;1;2;0

      0;0;3;0;9;send: 0-0-51-51 s=99,c=1,t=2,pt=0,l=1,st=ok:0
      0;0;3;0;9;read: 51-51-0 s=99,c=1,t=2,pt=0,l=1:0
      51;99;1;1;2;0
      

      The last one above is the ack generated automatically by the library.

      Then sent this, which requests the status of light child 99 on node 51, requesting an ack. Should return the ack and the response containing the current status of the light (0).
      51;99;2;1;2;anything

      0;0;3;0;9;send: 0-0-51-51 s=99,c=2,t=2,pt=0,l=8,st=ok:anything
      0;0;3;0;9;read: 51-51-0 s=99,c=2,t=2,pt=0,l=8:anything
      51;99;2;1;2;anything
      0;0;3;0;9;read: 51-51-0 s=99,c=1,t=2,pt=2,l=2:0
      51;99;1;0;2;0
      

      This "51;99;2;1;2;anything" is the ack generated automatically by the library, and this "51;99;1;0;2;0" is the response that my program performs. Correct!

      posted in Troubleshooting
      marcusvdt
      marcusvdt