Best way to send nodeDistance and parentNode



  • Hi all,

    In my nodes I'm using this method to send to my controller the distance and the parentNode to the master.
    I'm in doubt I'm using the correct presentation_ID. Here the snip of the code:

    (...)
    #define CHILD_ID_NODE 100
    int parentNode;
    int distance;
    MyMessage msgNodeVar1(CHILD_ID_NODE, V_VAR1);
    MyMessage msgNodeVar2(CHILD_ID_NODE, V_VAR2);
    (...)
    
    void presentation() {
    (...)
      present(CHILD_ID_NODE, S_POWER);
    (...)
    
    void loop() 
    {
    (...)
        parentNode = transportGetParentNodeId();
        send(msgNodeVar1.set(parentNode, 1));
        distance = transportGetDistanceGW();
        send(msgNodeVar2.set(distance, 1));
    

    This will create those informations available, via MQTT, on:
    parentNode: mygateway1-out/<node_id>/100/1/0/24
    distance: mygateway1-out/<node_id>/100/1/0/25

    How would you present it?
    I've this snip of code since 1.5. Meanwhile, updated to latest, the custom variables should be used.
    I hit some warning on HomeAssistant telling me warnings like:

    : sensor platform: node 20 child 100: S_POWER requires value_type V_WATT @ data[17]
    : sensor platform: node 20 child 100: S_POWER requires value_type V_KWH @ data[18]
    : sensor platform: node 20 child 100: S_POWER requires value_type V_VAR @ data[54]
    : sensor platform: node 20 child 100: S_POWER requires value_type V_VA @ data[55]
    : sensor platform: node 20 child 100: S_POWER requires value_type V_POWER_FACTOR @ data[56]
    

    I think it's to set a correct presentation.

    Let me know your opinion, thanks!

    Simon


  • Contest Winner

    @xefil Not sure what the V_VAR1 and V_VAR2 are meant for. But according to the MySensor library documentation https://www.mysensors.org/download/serial_api_20#variable-types you can't use V_VAR1 or V_VAR2 for a S_POWER node. You can use either one of these V_WATT, V_KWH, V_VAR, V_VA, V_POWER_FACTOR which is exactly as you can see in the HA warning.

    I haven't tried a DISTANCE sensor. But the documentation says there's an S_DISTANCE type, which supports the V_DISTANCE and V_UNIT_PREFIX variables.



  • Thanks @TheoL .
    Well, I'll try S_DISTANCE, but it's related to transportGetDistanceGW(); or to a distance sensor?
    The transportGetDistanceGW(); gets the distance in HOP to the gateway. If "0", it means it doesn't use any repeater to reach the gateway. BTW under presentation section of the API, I don't know what to use for personal variables, not related to sensors. Maybe S_CUSTOM with V_VAR<x> ?

    Simon


  • Mod

    @xefil you need to use different child id for each message.



  • Hello @mfalkvidd ,

    Wouldn't a problem, but why different child id?
    Wouldn't ok child_id 100 (in example), with presentation S_CUSTOM and setting V_VAR1 for parentNode and V_VAR2 for distanceGW?
    Why I need two different child id?

    Thanks!

    Simon


  • Mod

    @xefil I've never seen anyone reuse a child ID, and I think it would confuse most controllers. Just look at the presentation call: first the sketch would present the child as type X, then the sketch would present the same child as type Y. Will the controller use the first, the second, both or none of the presentations?

    But you may be right - maybe controllers can handle multiple data types per child id.



  • @mfalkvidd said in Best way to send nodeDistance and parentNode:

    @xefil I've never seen anyone reuse a child ID, and I think it would confuse most controllers. Just look at the presentation call: first the sketch would present the child as type X, then the sketch would present the same child as type Y. Will the controller use the first, the second, both or none of the presentations?

    But you may be right - maybe controllers can handle multiple data types per child id.

    Well @mfalkvidd maybe it's me that I'm making confusion.
    AFAYK, in case of HomeAssistant, it has an auto-discovery system which works, even if I don't like the naming convention it uses. BTW, using the above example, subscribing to MQTT server, I can get the values like follow:

    api doc:
    MY_MQTT_PUBLISH_TOPIC_PREFIX/FROM-NODE-ID/SENSOR-ID/CMD-TYPE/ACK-FLAG/SUB-TYPE

    example message published on topic prefix mygateway1-out from node 28, on V_VAR1, which has id 24, becomes:

    mygateway1-out/28/100/1/0/24

    The same way, message published on topic prefix mygateway1-out from node 28, on V_VAR2, which has id 25, becomes:

    mygateway1-out/28/100/1/0/25

    This gives me the ability to subscribe on it and check for changes, like the logs shows me:

    2018-12-31 08:37:09 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on mygateway1-out/28/100/1/0/24: b'0.0'
    2018-12-31 08:51:09 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on mygateway1-out/28/100/1/0/25: b'1.0'
    

    Looking deeper on what the controller recognize it during the presentation, using S_CUSTOM (id: 23) it's reassumed in this part of xml auto-generated:

        "28": {
            "protocol_version": "2.3.1",
            "battery_level": 0,
            "type": 18,
            "children": {
    <code_snipped>
                "100": {
                    "description": "Internal variables",
                    "id": 100,
                    "values": {
                        "24": "0.0",
                        "25": "1.0"
                    },
                    "type": 23
                }
            },
            "heartbeat": 0,
            "sketch_name": "node28Studio",
            "sketch_version": null,
            "sensor_id": 28
        },
    

    So, actually the infos are correctly sent. It's more a matter if the usage of the IDs is correct to avoid further conflicts, if any.
    That's the reason I'm asking 😉

    Thanks, Simon


 

341
Online

8.1k
Users

9.0k
Topics

95.4k
Posts