Round-about way to make a sleepable relay node



  • Hi all,

    I'm trying to make a node which is solar powered to control a few relays to automate our sprinklers. In order to get power consumption to a reasonable, sustainable level i will need to sleep the nodes.

    In order to allow the nodes to sleep without missing their messages to change state i am considereing employing a middle man node which the controller changes the state of the sprinkler on then the actual sprinkler nodes wake up, request the sprinkler state from the middle man node and change their state to suit. If the middle man node doesn't hear from the sprinkler node for a set period of time (say 10 mins) it changes the state of the sprinkler back to the original and pushes this change to the gateway (and thus controller) in the same way a button would.

    Here is a crappy diagram of what im trying to achieve-
    diagram dropbox link it that doesn't work https://www.dropbox.com/s/amhwu6maicnxi5p/middle man node diagram.png?dl=0

    I'm encountering one main issues implementing this approach-

    1- using the Requesting data function- how do i specify the varible i want? say the middle na node has an array of 20 sprinklers, what sprinkler node they are attached to, and their state. can i send the request for var1 meaning sprinkler one for the current node (node n) and then in the middle man node extract the destination node (the sprinkler node) id along with which custom variable requested (1 to 5) to tell which of the multiple attached sprinklers to turn on? Is there an example sketch using the request data function to get data from another node i can see (i couldn't find one)?

    it is mainly the "handle the reply message yourself in the destination node" and extracting the node and sensor id from the state request message recieved by the middle man node parts i cannot solve. Can i just construct the msg using the constructors here http://www.mysensors.org/download/sensor_api_15#MyMessage ? judging from the message stucture the sending nodes id isn't included in the header, how is the middle man node to determine who to send the data back to?

    sorry for all the questions, they seem little and i could probably resolve them myself if anyone has some examples of a node getting and receiving a variable from another node. Thanks for any and all input everyone!

    BTW- Currently i have the nodes built and was planing on waiting for a controller to implement the smart sleep feature in mysensors 1.5, however i have given up on waiting. Adding the feature to domotics was beyond my abilities (i tried) unfortunately).


  • Contest Winner

    @dsiee This answer is to explain the basics for node 2 node communications

    To respond to node 2 node requests the incomingMessage() function needs to be changed in such a way that it responds to requests
    In this example, for the answering node, one can request for temperature, humidity and pressure

    void incomingMessage(const MyMessage &message) 
    {
       //  Check for incoming node to node request
       if (mGetCommand(message) == C_REQ) {
             MyMessage msg;
             mSetCommand(msg, C_SET);
             msg.setType(message.type);
             msg.setSensor(message.sensor);
             msg.setDestination(message.sender);
             bool bHandled = true;
             switch (message.sensor) {
               case CHILD_ID_HUM:
                   msg.setType(V_HUM);
                   msg.set(lastHum, 1);
                   break;
                   
               case CHILD_ID_TEMP:
                   msg.setType(V_TEMP);
                   msg.set(lastTemp, 1);
                   break;
    
               case CHILD_ID_BARO:
                   msg.setType(V_PRESSURE);
                   msg.set(lastPressure, 0);
                   break;
    
              default:
                   bHandled = false; 
                   break;
             }
             if (bHandled) {
                 gw.send(msg); 
             }
        } else {
           // do normal message handling stuff
           switch  (message.type) {
               case V_STATUS:
                   // Do something useful
                   break;
        }
    }
    

    With this call one can perform the request

    gw.request( TEMP_SENS_ID,  V_TEMP, WEATHER_NODE_ID);
    

    And the requesting node should hande incoming data in incomingMessage()

    void incomingMessage(const MyMessage &message) {
       // We only expect one type of message from controller. But we better check anyway.
       if (message.isAck()) {
           Serial.println(F("GW ack"));
       }
      switch (message.type) {
    	case V_TEMP:
    	   // Write some debug info
    	   Serial.print(F("Temp received: "));
    	   Serial.print(message.sensor);
    	   Serial.print(F(" : "));
    	   Serial.println((int)message.getFloat());
    	   break;
    
    	case V_HUM:
    	   // Write some debug info
    	   Serial.print(F("Humidity received: "));
    	   Serial.print(message.sensor);
    	   Serial.print(F(" : "));
    	   Serial.println(message.getInt(), HEX);
    	   break;
    
    	case V_PRESSURE:
    	   // Write some debug info
    	   Serial.print(F("Pressure received: "));
    	   Serial.print(message.sensor);
    	   Serial.print(F(" : "));
    	   Serial.println(message.getInt());
    	   break;
       }
    }
    


  • @BartE Thanks so much! That explains just about everything i needed. Glad the see that message.sender exists as it was integral to my plan of attack!

    Thanks again, I really appreciate it!


Log in to reply
 

Suggested Topics

55
Online

11.4k
Users

11.1k
Topics

112.6k
Posts