Announcement

Collapse
No announcement yet.

Obtaining value [circular] after changing msg.payload.value to msg. payload

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Obtaining value [circular] after changing msg.payload.value to msg. payload

    When I set the msg.payload.value to msg.payload I obtain an indication value [Circular]. See below (flow included)

    How to do this correctly?

    Click image for larger version

Name:	Capture NR circular.PNG
Views:	390
Size:	34.5 KB
ID:	1445848

    Click image for larger version

Name:	Capture circ 2.PNG
Views:	344
Size:	14.1 KB
ID:	1445849

    [{"id":"3c8e903b.90212","type":"tab","label":"Nibe","disabled ":false,"info":""},{"id":"b949ada3.97d59","type":"inject","z ":"3c8e903b.90212","name":"Dummy","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1200","crontab":"","once":true,"onceDelay":"0,1", "topic":"update","payload":"{"value":"dummy"}","payloadType" :"json","x":180,"y":340,"wires":[["3ce4167c.0516aa"]]},{"id":"a20f8b5d.7f33e8","type":"hs-device","z":"3c8e903b.90212","name":"Unknown Unknown Node Red 1 Control","device":"3078","server":"dd4ee359.4f957","feature" :"3079","reportonstartup":false,"x":720,"y":620,"wires":[[]]},{"id":"5fb845af.43dcfc","type":"modbus-flex-getter","z":"3c8e903b.90212","name":"","showStatusActivities ":false,"showErrors":false,"logIOActivities":false,"server": "d995411c.f4522","useIOFile":false,"ioFile":"","useIOForPayl oad":false,"emptyMsgOnFail":false,"keepMsgProperties":false, "x":370,"y":420,"wires":[["6cb34614.45a1d8","b3d2f132.0daae"],[]]},{"id":"3ce4167c.0516aa","type":"function","z":"3c8e903b.90 212","name":"","func":"msg.payload = { \n 'fc': 3,\n 'unitid': 1,\n 'address': 40004 ,\n 'quantity': 1 };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x ":180,"y":420,"wires":[["5fb845af.43dcfc"]]},{"id":"cc09cba3.6b0668","type":"debug","z":"3c8e903b.90212 ","name":"","active":true,"tosidebar":true,"console":false," tostatus":true,"complete":"payload","targetType":"msg","stat usVal":"payload","statusType":"auto","x":510,"y":20,"wires":[]},{"id":"6cb34614.45a1d8","type":"debug","z":"3c8e903b.90212 ","name":"","active":true,"tosidebar":true,"console":false," tostatus":true,"complete":"payload","targetType":"msg","stat usVal":"payload","statusType":"auto","x":610,"y":420,"wires" :[]},{"id":"b3d2f132.0daae","type":"change","z":"3c8e903b.90212 ","name":"","rules":[{"t":"set","p":"payload.value","pt":"msg","to":"payload","to t":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x" :460,"y":540,"wires":[["8b8bdb3e.8aea48","a20f8b5d.7f33e8"]]},{"id":"8b8bdb3e.8aea48","type":"debug","z":"3c8e903b.90212 ","name":"","active":true,"tosidebar":true,"console":false," tostatus":true,"complete":"payload.value","targetType":"msg" ,"statusVal":"payload.status","statusType":"auto","x":680,"y ":540,"wires":[]},{"id":"dd4ee359.4f957","type":"hs-server","name":"TEAPHomeSeerServer01","host":"192.168.1.99", "port":"80"},{"id":"d995411c.f4522","type":"modbus-client","name":"Nibe","clienttype":"simpleser","bufferComman ds":true,"stateLogEnabled":false,"queueLogEnabled":false,"tc pHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","seri alPort":"/dev/ttyr03","serialType":"RTU","serialBaudrate":"9600","serialDa tabits":"8","serialStopbits":"1","serialParity":"none","seri alConnectionDelay":"100","unit_id":"1","commandDelay":"1","c lientTimeout":"2100","reconnectOnTimeout":true,"reconnectTim eout":"2000","parallelUnitIdsAllowed":true}]

    ---
    John
    Attached Files

    #2
    Workaround is to use the Move function.

    Any idea why it is not working as I use the set normally.

    ---
    John

    Comment


      #3
      Sometimes you need to delete msg.payload before ‘’ set msg.payload.xxxx to msg.payload.

      Not 100% sure this is happening . I think this is when there is a more then one entry in msg.payload.xxx

      Depending of your usage , you maybe need to transfer the msg.payload.value to something like msg.tmp first.

      Comment


        #4
        Originally posted by MattL0 View Post
        Sometimes you need to delete msg.payload before ‘’ set msg.payload.xxxx to msg.payload.

        Not 100% sure this is happening . I think this is when there is a more then one entry in msg.payload.xxx

        Depending of your usage , you maybe need to transfer the msg.payload.value to something like msg.tmp first.
        That will not do the trick so I stick to the move action.

        ---

        John

        Comment


          #5
          When msg.payload has subvalues such as msg.payload.value, it is an Object. It will remain an object until you change it to something different. Just assigning it a value does not do this. I prefer using a Change node and setting the following:
          Set msg.oldPayload To msg.payload
          Delete msg.payload
          Set msg.payload To msg.oldPayload.value

          If you do not want to carry the old payload forward, you can try using just the last 2 items and change msg.oldPayload.value to msg.payload.value. I am not certain but the change node may retain the old payload values through all the sets via a temporary variable. I have always just carried the information forward as I often need it later.

          You can also remove your remove your Function node if it is just setting values for the payload. They are not efficient and should be avoided. You could do it with the Inject node. Import this and if you need strings instead of numbers, change them.

          Code:
          [{"id":"574aff16.7e25f","type":"inject","z":"c49a99b5.f9e668","name":"","props":[{"p":"payload.fc","v":"3","vt":"num"},{"p":"payload.unitid","v":"1","vt":"num"},{"p":"payload.address","v":"40004 ","vt":"num"},{"p":"payload.quantity","v":"1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":320,"y":300,"wires":[[]]}]
          Karl S
          HS4Pro on Windows 10
          1070 Devices
          56 Z-Wave Nodes
          104 Events
          HSTouch Clients: 3 Android, 1 iOS
          Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

          Comment


            #6
            Originally posted by ksum View Post
            When msg.payload has subvalues such as msg.payload.value, it is an Object. It will remain an object until you change it to something different. Just assigning it a value does not do this. I prefer using a Change node and setting the following:
            Set msg.oldPayload To msg.payload
            Delete msg.payload
            Set msg.payload To msg.oldPayload.value

            If you do not want to carry the old payload forward, you can try using just the last 2 items and change msg.oldPayload.value to msg.payload.value. I am not certain but the change node may retain the old payload values through all the sets via a temporary variable. I have always just carried the information forward as I often need it later.

            You can also remove your remove your Function node if it is just setting values for the payload. They are not efficient and should be avoided. You could do it with the Inject node. Import this and if you need strings instead of numbers, change them.

            Code:
            [{"id":"574aff16.7e25f","type":"inject","z":"c49a99b5.f9e668","name":"","props":[{"p":"payload.fc","v":"3","vt":"num"},{"p":"payload.unitid","v":"1","vt":"num"},{"p":"payload.address","v":"40004 ","vt":"num"},{"p":"payload.quantity","v":"1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":320,"y":300,"wires":[[]]}]
            Set Delete Set is not working so I'm using move.

            Thanks for the suggestion. But to read multiple registers there should be a delay between each read.

            ---
            John

            Comment


              #7
              I see what you are doing now and think I understand what the problem is. I BELIEVE you are trying to get the keys from msg.payload into msg.payload.value. But value is a key of msg.payload. I believe the Change node may not be removing the old values but using pointers, meaning you are looking at the same information and since msg.payload.value is an object inside the msg.payload object you get a circular reference.
              Karl S
              HS4Pro on Windows 10
              1070 Devices
              56 Z-Wave Nodes
              104 Events
              HSTouch Clients: 3 Android, 1 iOS
              Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

              Comment

              Working...
              X