Getting values from outside my nodes



  • I am adding more sensors and some of the values in my code I would like to be able to update dynamically. Like my smoothing counters, delays ect.

    I have seen there is a "request" function that I can use. I was wondering if anyone has any suggestions on how to utilize this with an mqtt gateway. I use openhab as my backend controller so if anyone has any suggestions or direction that would be helpful and prevent me from having to keep pulling my nodes and flashing them.

    Thanks!



  • Update: so I have taken one of my modules an added the following to the loop every 10 seconds.

    request(1, 24);
    

    I see messages hitting my mqtt broker
    0_1514586586276_8e663e5e-8b1e-4b1b-8ffd-3309b08f9c27-image.png

    The payload is blank. So I am trying to figure out how to get openhab to see the request (but the value isn't changing) and then be able to respond back with a value.

    Secondly, has anyone done this with openhab and been able to create a rule that can look for all NODES asking for a req?

    so maybe something like monitoring mygateway1-out/+/+/2/# or whatever watching for just requests?

    I am hoping there is a way to do this with openhab/mysensors directly, otherwise i may have to go to mqttwarn and monitor for requests and query openhab and respond. (not ideal)


  • Mod

    Look at the pulse energy meter sketch, it uses the request function to retrieve the last pulse count from controller



  • that part I was able to figure out. Was hoping someone had some working examples on how to get the controller to monitor for those requests and answer back.

    I think I got it working, but not sure if it's the right way to do it or not. Will post details momentarily.


  • Mod

    I think it should be taken care by the mysensors plug in without too much tinkering, but I haven't used Openhab


  • Hero Member

    @crankycoder said in Getting values from outside my nodes:

    that part I was able to figure out. Was hoping someone had some working examples on how to get the controller to monitor for those requests and answer back.

    I think it is as @gohan has said, if the controller supports request it will be handled automatically and returned to the asking node.

    You have to have code in your void receive(const MyMessage &message) to do something with the returning request. In Domoticz I have found it can take several hundred milliseconds for the request to return so you may have to wait before you get a result.

    Nodes can also request data directly from other nodes but you need to handle the request and return manually in that case as the controller will not be involved.

    You may find the info in this post of some use.
    I have also used request in this project where you can see the delay needed before reading the return.



  • @boots33 checking out those references.



  • So here is what I ended up doing. This may be long....

    First off, I put this code in to my node.

    if(currentMillis - previousMillisSettings >= 300000) 
      {
        previousMillisSettings = currentMillis;
        request(2, 24);
        wait(MESSAGEWAIT);
        request(2, 25);
        wait(MESSAGEWAIT);
        
      }
    

    So I am just requesting V_VAR1 and V_VAR2 for child sensor ID2.

    Ok, so, so far so good. However, openhab doesn't do anything with that since I am using the mysensors MQTT gateway. So I loaded up MQTT spy and saw the requests for the info.

    So now lets get openhab to monitor for that.

    2 new items created in the openhab config.

    String MasterBedRoomLightSleepTimeReq {mqtt="<[mqtt-brunkhome:mygateway1-out/200/2/2/0/24:state:default]"}
    String MasterBedRoomLightNumReadingsReq {mqtt="<[mqtt-brunkhome:mygateway1-out/200/2/2/0/25:state:default]"}
    

    just 2 items watching for those requests.

    Now 2 more items to be the configuration items.

    Number MasterBedroomLightSleepTime  
    Number MasterBedroomLightNumReadings
    
    

    Then I created 2 rules (I know it's getting long).

    rule "Request Sleep Time"
    when
            Item MasterBedRoomLightSleepTimeReq received update
    then
            logInfo("Bedroom","Bedroom Counter Requested")
            publish("mqtt-brunkhome","mygateway1-in/200/2/1/0/24",(MasterBedroomLightSleepTime.state).toString())
    
    
    
    
    rule "Request Num Readings"
    when
            Item MasterBedRoomLightNumReadingsReq received update
    then
            logInfo("Bedroom","Bedroom Light Sensor Reading Count")
            publish("mqtt-brunkhome","mygateway1-in/200/2/1/0/25",(MasterBedroomLightNumReadings.state).toString()))
    
    

    These 2 rules see's anytime there is something on those mqtt nodes, and responds back to the mqtt gateway with the info.

    Then in my node, I put the following in my receive()

    if (message.type==V_VAR1) {
        DEBUG_PRINT("Sleep Time Sent Back");
        SLEEPTIMEL = atoi(message.data);
        DEBUG_PRINTLN(atoi(message.data));
      }
      else if (message.type == V_VAR2)
        {
        DEBUG_PRINT("Read Count Sent Back");
        numReadings = atoi(message.data);
        DEBUG_PRINTLN(atoi(message.data));
      }
    

    And now my openhab is responding to config requests.

    I then went back and updated the number items to also push config too. So the node can come get the config, but if you change it, it also pushes real time too.

    Number MasterBedroomLightSleepTime  { mqtt=">[mqtt-brunkhome:mygateway1-in/200/2/1/0/24:command:*:default]" }
    Number MasterBedroomLightNumReadings  { mqtt=">[mqtt-brunkhome:mygateway1-in/200/2/1/0/25:command:*:default]" }
    

    SOOO.... here is my question..... is this even the right way to do this? I mean with this method for EVERY variable I have to create an item to watch for the request, one to hold the value of said variable, and a rule?

    Just wondering if anyone has done this with openhab or even something else that just uses the mqttgateway.

    PS. i am going to cross post this on the openhab community as well.



  • @crankycoder I do not know if I understood you correctly ...

    void request (uint8_t childSensorId, uint8_t variableType, uint8_t destination);

    Suppose you have a node with ID 100 sends request (1, 24); (= request (1, 24, 0))

    This means that the node with ID 100 requests the information with the last value for sensor 1 with the type VAR1 that is on the controller for the node with ID 100. (not at sensor 1 on the gateway (ID 0)

    Ie at such request of a node with ID 100 requests value as though at itself (that last value which is on the controller).

    request (1, 24);
    request (1, 24, 0);

    It is the same.

    ps/// I understood 🙂 .. on OpenHub there is no implementation of the MySensors module


Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 1
  • 6
  • 3
  • 1

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts