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. General Discussion
  3. Best way to send nodeDistance and parentNode

Best way to send nodeDistance and parentNode

Scheduled Pinned Locked Moved General Discussion
7 Posts 3 Posters 1.1k Views 3 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.
  • X Offline
    X Offline
    xefil
    wrote on last edited by
    #1

    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

    TheoLT mfalkviddM 2 Replies Last reply
    0
    • X xefil

      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

      TheoLT Offline
      TheoLT Offline
      TheoL
      Contest Winner
      wrote on last edited by TheoL
      #2

      @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.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xefil
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • X xefil

          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

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xefil
            wrote on last edited by
            #5

            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

            mfalkviddM 1 Reply Last reply
            0
            • X xefil

              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

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #6

              @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.

              X 1 Reply Last reply
              0
              • mfalkviddM mfalkvidd

                @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.

                X Offline
                X Offline
                xefil
                wrote on last edited by
                #7

                @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

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


                19

                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