Get coordinates of a satellite from http request

Updated flow that solves the timestamp issue, and shows that the prepopulated values from the node config take precedence over any configuration set by the message object. If you check the code, it verifies it doesn't care about msg.tle1 and msg.tle2.

[{"id":"d654e484.15bf58","type":"inject","z":"1f20f9bb.524146","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1220,"wires":[["4db729cd.98173"]]},{"id":"4db729cd.98173","type":"http request","z":"1f20f9bb.524146","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://celestrak.com/satcat/tle.php?CATNR=44109","tls":"","persist":false,"proxy":"","authType":"","x":150,"y":1280,"wires":[["b6d25ac1.e0c27"]]},{"id":"b6d25ac1.e0c27","type":"split","z":"1f20f9bb.524146","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":150,"y":1340,"wires":[["dea2ab0.a701dd8"]]},{"id":"4e14cbcf.6e9724","type":"tle","z":"1f20f9bb.524146","satid":"BLUEWALKER 1  ","tle1":"1 44105U 19018AD  20099.11563392  .00001300  00000-0  43406-4 0  9998","tle2":"2 44105  97.4795 168.9341 0059630 107.2691 253.5087 15.31277171 57050","coordsys":"latlongdeg","name":"(TLE prefilled with BLUEWALKER 1 data)","x":240,"y":1540,"wires":[["b4494ddc.8d245"]]},{"id":"b4494ddc.8d245","type":"debug","z":"1f20f9bb.524146","name":"Message coming out of TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":220,"y":1600,"wires":[]},{"id":"dea2ab0.a701dd8","type":"switch","z":"1f20f9bb.524146","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":130,"y":1400,"wires":[["45092131.d93f58"],["5205a604.c26b3"],["721315d6.d00c4c"],["89f21cab.96098"]]},{"id":"45092131.d93f58","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"satid","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1340,"wires":[["1df4d812.287138"]]},{"id":"5205a604.c26b3","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tel1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1380,"wires":[["1df4d812.287138"]]},{"id":"721315d6.d00c4c","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tel2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1420,"wires":[["1df4d812.287138"]]},{"id":"1df4d812.287138","type":"join","z":"1f20f9bb.524146","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":1400,"wires":[["320515f8.80ca82"]]},{"id":"89f21cab.96098","type":"change","z":"1f20f9bb.524146","name":"set timestamp","rules":[{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1460,"wires":[["1df4d812.287138"]]},{"id":"87d12307.e68de","type":"debug","z":"1f20f9bb.524146","name":"Message going into TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1010,"y":1460,"wires":[]},{"id":"320515f8.80ca82","type":"change","z":"1f20f9bb.524146","name":"put timestamp back in payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"timestamp","tot":"msg"},{"t":"delete","p":"timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1460,"wires":[["4e14cbcf.6e9724","87d12307.e68de"]]}]

Edit:
Flow that instead used msg.tle1/2 rather than msg.tel1/2, no difference in output

[{"id":"d654e484.15bf58","type":"inject","z":"1f20f9bb.524146","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1220,"wires":[["4db729cd.98173"]]},{"id":"4db729cd.98173","type":"http request","z":"1f20f9bb.524146","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://celestrak.com/satcat/tle.php?CATNR=44109","tls":"","persist":false,"proxy":"","authType":"","x":150,"y":1280,"wires":[["b6d25ac1.e0c27"]]},{"id":"b6d25ac1.e0c27","type":"split","z":"1f20f9bb.524146","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":150,"y":1340,"wires":[["dea2ab0.a701dd8"]]},{"id":"4e14cbcf.6e9724","type":"tle","z":"1f20f9bb.524146","satid":"BLUEWALKER 1  ","tle1":"1 44105U 19018AD  20099.11563392  .00001300  00000-0  43406-4 0  9998","tle2":"2 44105  97.4795 168.9341 0059630 107.2691 253.5087 15.31277171 57050","coordsys":"latlongdeg","name":"(TLE prefilled with BLUEWALKER 1 data)","x":240,"y":1540,"wires":[["b4494ddc.8d245"]]},{"id":"b4494ddc.8d245","type":"debug","z":"1f20f9bb.524146","name":"Message coming out of TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":220,"y":1600,"wires":[]},{"id":"dea2ab0.a701dd8","type":"switch","z":"1f20f9bb.524146","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":130,"y":1400,"wires":[["45092131.d93f58"],["5205a604.c26b3"],["721315d6.d00c4c"],["89f21cab.96098"]]},{"id":"45092131.d93f58","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"satid","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1340,"wires":[["1df4d812.287138"]]},{"id":"5205a604.c26b3","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tle1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1380,"wires":[["1df4d812.287138"]]},{"id":"721315d6.d00c4c","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tle2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1420,"wires":[["1df4d812.287138"]]},{"id":"1df4d812.287138","type":"join","z":"1f20f9bb.524146","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":1400,"wires":[["320515f8.80ca82"]]},{"id":"89f21cab.96098","type":"change","z":"1f20f9bb.524146","name":"set timestamp","rules":[{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1460,"wires":[["1df4d812.287138"]]},{"id":"87d12307.e68de","type":"debug","z":"1f20f9bb.524146","name":"Message going into TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1010,"y":1460,"wires":[]},{"id":"320515f8.80ca82","type":"change","z":"1f20f9bb.524146","name":"put timestamp back in payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"timestamp","tot":"msg"},{"t":"delete","p":"timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1460,"wires":[["4e14cbcf.6e9724","87d12307.e68de"]]}]

Flow that has an empty TLE node instead (no output, all values NaN):

[{"id":"d654e484.15bf58","type":"inject","z":"1f20f9bb.524146","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1220,"wires":[["4db729cd.98173"]]},{"id":"4db729cd.98173","type":"http request","z":"1f20f9bb.524146","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://celestrak.com/satcat/tle.php?CATNR=44109","tls":"","persist":false,"proxy":"","authType":"","x":150,"y":1280,"wires":[["b6d25ac1.e0c27"]]},{"id":"b6d25ac1.e0c27","type":"split","z":"1f20f9bb.524146","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":150,"y":1340,"wires":[["dea2ab0.a701dd8"]]},{"id":"4e14cbcf.6e9724","type":"tle","z":"1f20f9bb.524146","satid":"","tle1":"","tle2":"","coordsys":"latlongdeg","name":"(TLE not prepopulated)","x":180,"y":1540,"wires":[["b4494ddc.8d245"]]},{"id":"b4494ddc.8d245","type":"debug","z":"1f20f9bb.524146","name":"Message coming out of TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":220,"y":1600,"wires":[]},{"id":"dea2ab0.a701dd8","type":"switch","z":"1f20f9bb.524146","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":130,"y":1400,"wires":[["45092131.d93f58"],["5205a604.c26b3"],["721315d6.d00c4c"],["89f21cab.96098"]]},{"id":"45092131.d93f58","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"satid","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1340,"wires":[["1df4d812.287138"]]},{"id":"5205a604.c26b3","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tle1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1380,"wires":[["1df4d812.287138"]]},{"id":"721315d6.d00c4c","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tle2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1420,"wires":[["1df4d812.287138"]]},{"id":"1df4d812.287138","type":"join","z":"1f20f9bb.524146","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":1400,"wires":[["320515f8.80ca82"]]},{"id":"89f21cab.96098","type":"change","z":"1f20f9bb.524146","name":"set timestamp","rules":[{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1460,"wires":[["1df4d812.287138"]]},{"id":"87d12307.e68de","type":"debug","z":"1f20f9bb.524146","name":"Message going into TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1010,"y":1460,"wires":[]},{"id":"320515f8.80ca82","type":"change","z":"1f20f9bb.524146","name":"put timestamp back in payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"timestamp","tot":"msg"},{"t":"delete","p":"timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1460,"wires":[["4e14cbcf.6e9724","87d12307.e68de"]]}]

Yes that's my problem.
Moreover, it sends 4 data to TLE instead of 1.

Arugh, I just realized that I had prefilled in the TLE node and so I was getting false results (arugh).
However this should be an easy PR to check for the inputs and use them in the node. Let me take a look.

All right I've got a fix for the code. If you want to try it out, go to the
.node-red/node_modules/node-red-contrib-satellites
folder and edit satellites.js
go to line 76 which is var satellites = []; and add the following

        // override tle1 if passed suitable value
            if  ('satid' in msg)  {
                if ( (typeof msg.satid === 'string') && (msg.satid.length < 1024) ) {
                    node.satid = msg.satid
                }
            }
        // override tle1 if passed suitable value
            if  ('tle1' in msg)  {
                if ( (typeof msg.tle1 === 'string') && (msg.tle1.length < 1024) ) {
                    node.tle1 = msg.tle1
                }
            }
        // override tle1 if passed suitable value
            if  ('tle2' in msg)  {
                if ( (typeof msg.tle2 === 'string') && (msg.tle2.length < 1024) ) {
                    node.tle2 = msg.tle2
                }
            }

Save the file and stop/start NR then try the second flow (using msg.tle1/2) that @afelix provided.

Let me know if it works for you.

Rather than use a split etc this may be a case where a simple function node can do it all much more cleanly. (Alongside the fix for the node itself)

I'm sorry but i don't understand what i have to do in my flow.
I changed the code as you said but i don't know what to change on NR.
btw yes i used a split instead

1 Like

PR created for the node and an example also provided.
@dceejay your right, the function would be simpler, but the split/join should be easier for someone new to understand.

I'll put together a flow with the function also.

Now try this flow that @afelix provided

[{"id":"d654e484.15bf58","type":"inject","z":"1f20f9bb.524146","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1220,"wires":[["4db729cd.98173"]]},{"id":"4db729cd.98173","type":"http request","z":"1f20f9bb.524146","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://celestrak.com/satcat/tle.php?CATNR=44109","tls":"","persist":false,"proxy":"","authType":"","x":150,"y":1280,"wires":[["b6d25ac1.e0c27"]]},{"id":"b6d25ac1.e0c27","type":"split","z":"1f20f9bb.524146","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":150,"y":1340,"wires":[["dea2ab0.a701dd8"]]},{"id":"4e14cbcf.6e9724","type":"tle","z":"1f20f9bb.524146","satid":"BLUEWALKER 1  ","tle1":"1 44105U 19018AD  20099.11563392  .00001300  00000-0  43406-4 0  9998","tle2":"2 44105  97.4795 168.9341 0059630 107.2691 253.5087 15.31277171 57050","coordsys":"latlongdeg","name":"(TLE prefilled with BLUEWALKER 1 data)","x":240,"y":1540,"wires":[["b4494ddc.8d245"]]},{"id":"b4494ddc.8d245","type":"debug","z":"1f20f9bb.524146","name":"Message coming out of TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":220,"y":1600,"wires":[]},{"id":"dea2ab0.a701dd8","type":"switch","z":"1f20f9bb.524146","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":130,"y":1400,"wires":[["45092131.d93f58"],["5205a604.c26b3"],["721315d6.d00c4c"],["89f21cab.96098"]]},{"id":"45092131.d93f58","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"satid","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1340,"wires":[["1df4d812.287138"]]},{"id":"5205a604.c26b3","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tle1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1380,"wires":[["1df4d812.287138"]]},{"id":"721315d6.d00c4c","type":"change","z":"1f20f9bb.524146","name":"","rules":[{"t":"set","p":"tle2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1420,"wires":[["1df4d812.287138"]]},{"id":"1df4d812.287138","type":"join","z":"1f20f9bb.524146","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":1400,"wires":[["320515f8.80ca82"]]},{"id":"89f21cab.96098","type":"change","z":"1f20f9bb.524146","name":"set timestamp","rules":[{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1460,"wires":[["1df4d812.287138"]]},{"id":"87d12307.e68de","type":"debug","z":"1f20f9bb.524146","name":"Message going into TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1010,"y":1460,"wires":[]},{"id":"320515f8.80ca82","type":"change","z":"1f20f9bb.524146","name":"put timestamp back in payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"timestamp","tot":"msg"},{"t":"delete","p":"timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1460,"wires":[["4e14cbcf.6e9724","87d12307.e68de"]]}]

Same result for me :confused:
Dunno is i'm doing something wrong but the timestamp overwrite again.

And as you can see, i have still a lot of response from TLE (4) one for each msg.

You didn't use the join node to join the four mesages together.

Try this simpler flow using a function instead of the split/join (a @dceejay suggestion)

[{"id":"736f681c.fb3ea8","type":"inject","z":"6eeba0c2.aa0738","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":560,"wires":[["70029dca.401c34"]]},{"id":"70029dca.401c34","type":"http request","z":"6eeba0c2.aa0738","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://celestrak.com/satcat/tle.php?CATNR=44109","tls":"","persist":false,"proxy":"","authType":"","x":130,"y":620,"wires":[["dcbe4635.b98e6"]]},{"id":"dcbe4635.b98e6","type":"function","z":"6eeba0c2.aa0738","name":"Move the data to the override values","func":"var p = msg.payload.split(\"\\n\");\nmsg.satid = p[0]\nmsg.tle1 =  p[1]\nmsg.tle2 =  p[2]\nmsg.payload = Date.now()\n\nreturn msg;","outputs":1,"noerr":0,"x":210,"y":680,"wires":[["4f94285d.8cc2f"]]},{"id":"4f94285d.8cc2f","type":"tle","z":"6eeba0c2.aa0738","satid":"BLUEWALKER 1  ","tle1":"","tle2":"2 44105  97.4795 168.9341 0059630 107.2691 253.5087 15.31277171 57050","coordsys":"latlongdeg","name":"(TLE prefilled with BLUEWALKER 1 data)","x":220,"y":740,"wires":[["f26379b6.1eb2f8"]]},{"id":"f26379b6.1eb2f8","type":"debug","z":"6eeba0c2.aa0738","name":"Message coming out of TLE node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":200,"y":800,"wires":[]}]

@JustSeen just sent me a message (he hit his post limit) that this solved the issue.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.