joepavitt / node-red-satellites

A web map app for Node-RED to put blobs on
Apache License 2.0
9 stars 12 forks source link

Feature request - Method to update TLE #12

Closed thebaldgeek closed 3 years ago

thebaldgeek commented 3 years ago

I am a heavy user of this node - I thank you all for putting it together.
The sats I track drift and I need to update the TLE every month. Its been two years now of updating the TLEs of 6 satellites by hand.... Its getting old.
Can we either have a way to parse the TLE via a payload, or better still, a way to inject the celestrak URL via a payload. Example of the URL: https://celestrak.com/satcat/tle.php?CATNR=33278
I'd like to be in control via an inject node as to when the TLE is updated as it impacts our tracking.

Thanks for your consideration.

dceejay commented 3 years ago

Hi,

not a node we use a lot to be honest - so any pull request would be looked upon favourably as you probably know more about this than we do tbh :-)

Looking at the code - you can leave the tle1 and 2 fields blank and pass in msg.tle1 and msg.tle2 ... does that help ? https://github.com/jdp1g09/node-red-satellites/blob/master/satellites.js#L86 etc

dceejay commented 3 years ago

@thebaldgeek - Any more thoughts ?

thebaldgeek commented 3 years ago

I am about 10 hours into working with this node and am very confused.
Sometimes it works by passing in tle data, other times it returns NaN for the position.

I could not get it work at all by passing in msg.tle1 and msg.tle2.
Looking at lines 21 to 28 of satellites.js it seems to imply that what the code is actually looking for is msg.payload to be a list of objects, namely timestamp and tle1 and tle2.

if (lines[i] !== undefined && lines[i+1] !== undefined && lines[i+2] !== undefined) { let s = {}; s.name = lines[i].replace("\n", "").trim(); i++; s.tle1 = lines[i].replace("\n", ""); i++; s.tle2 = lines[i].replace("\n", ""); sats.push(s);

By passing in such an object, I often get correct position data returned. Here is an example flow that sometimes works. [{"id":"63295574.b54f9c","type":"inject","z":"dac61f27.3a12b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1280,"y":1300,"wires":[["84ef30c1.0e0be"]]},{"id":"9526e2d8.36a8d","type":"debug","z":"dac61f27.3a12b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2370,"y":1240,"wires":[]},{"id":"84ef30c1.0e0be","type":"http request","z":"dac61f27.3a12b8","name":"get 98W TLE","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://celestrak.com/satcat/tle.php?CATNR=33278","tls":"","persist":false,"proxy":"","authType":"","x":1470,"y":1300,"wires":[["d44eee76.2cbe4"]]},{"id":"7ab3647e.2cc21c","type":"tle","z":"dac61f27.3a12b8","satid":"Inmarsat 4-F3","tle1":"","tle2":"","coordsys":"latlongdeg","name":"98W 4-F3","x":1960,"y":1240,"wires":[["865a64a7.4a8d78"]]},{"id":"6c2671f8.440cc","type":"debug","z":"dac61f27.3a12b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2010,"y":1320,"wires":[]},{"id":"865a64a7.4a8d78","type":"change","z":"dac61f27.3a12b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2150,"y":1240,"wires":[["9526e2d8.36a8d"]]},{"id":"d44eee76.2cbe4","type":"function","z":"dac61f27.3a12b8","name":"set","func":"list = msg.payload.split('\\n');\nlist[0] = new Date().getTime();\nflow.set(\"98list\", list);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1670,"y":1300,"wires":[[]]},{"id":"7c997e53.b3cde","type":"function","z":"dac61f27.3a12b8","name":"get 98list","func":"list = flow.get(\"98list\");\nlist[0] = new Date().getTime();\nmsg.payload = list;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1760,"y":1240,"wires":[["7ab3647e.2cc21c","6c2671f8.440cc"]]},{"id":"19dc8034.8b652","type":"inject","z":"dac61f27.3a12b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1510,"y":1180,"wires":[["7c997e53.b3cde"]]}]

Note that you need to first fire the http get part of the flow, this should happen once every 24 hours as NORAD only update this satellite TLE once a day. Once you get the list, then you can track the satellite by injecting the other timestamp as much as needed (every 15 minutes in my case).

If I can just work out why its inconsistent, we would be up and running and very happy as no PR would be required, the code is already there to accept TLE data via the flow.

thebaldgeek commented 3 years ago

Here is an updated example flow that well shows the node changing the payload: In this example I set msg.tle1, msg.tle2, msg.satid and msg.timestamp. The satellite node however, takes msg.tle1 and turns it into an array with a bad timestamp and thus returns NaN

[{"id":"63295574.b54f9c","type":"inject","z":"dac61f27.3a12b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1320,"y":1300,"wires":[["84ef30c1.0e0be"]]},{"id":"9526e2d8.36a8d","type":"debug","z":"dac61f27.3a12b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2070,"y":1240,"wires":[]},{"id":"84ef30c1.0e0be","type":"http request","z":"dac61f27.3a12b8","name":"get 98W TLE","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://celestrak.com/satcat/tle.php?CATNR=33278","tls":"","persist":false,"proxy":"","authType":"","x":1510,"y":1300,"wires":[["d44eee76.2cbe4","5b87a97e.9a6268"]]},{"id":"7ab3647e.2cc21c","type":"tle","z":"dac61f27.3a12b8","satid":"","tle1":"","tle2":"","coordsys":"latlongdeg","name":"98W 4-F3","x":1900,"y":1240,"wires":[["9526e2d8.36a8d"]]},{"id":"6c2671f8.440cc","type":"debug","z":"dac61f27.3a12b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1830,"y":1180,"wires":[]},{"id":"d44eee76.2cbe4","type":"function","z":"dac61f27.3a12b8","name":"set","func":"list = msg.payload.split('\\n');\n//list[0] = new Date().getTime();\nflow.set(\"98list\", list);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1710,"y":1300,"wires":[[]]},{"id":"7c997e53.b3cde","type":"function","z":"dac61f27.3a12b8","name":"get 98list","func":"list = flow.get(\"98list\");\n//list[0] = new Date().getTime();\nmsg.payload = list;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1480,"y":1240,"wires":[["92c1fc4c.63954","1f0641ef.f838fe"]]},{"id":"19dc8034.8b652","type":"inject","z":"dac61f27.3a12b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1320,"y":1240,"wires":[["7c997e53.b3cde"]]},{"id":"5b87a97e.9a6268","type":"debug","z":"dac61f27.3a12b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1714,"y":1353.6666259765625,"wires":[]},{"id":"1f0641ef.f838fe","type":"debug","z":"dac61f27.3a12b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1610,"y":1180,"wires":[]},{"id":"92c1fc4c.63954","type":"change","z":"dac61f27.3a12b8","name":"","rules":[{"t":"set","p":"tle1","pt":"msg","to":"payload[1]","tot":"msg"},{"t":"set","p":"tle2","pt":"msg","to":"payload[2]","tot":"msg"},{"t":"set","p":"satid","pt":"msg","to":"payload[0]","tot":"msg"},{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[2]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1660,"y":1240,"wires":[["7ab3647e.2cc21c","6c2671f8.440cc"]]}]

dceejay commented 3 years ago

Hi I have pushed a fix as 0.5.2 that now checks the payload properly... the payload is supposed to be be just a timestamp or array of timestamps - but it had duff tle data left in it.. - In your case it would be better just to delete msg.payload in that change node. Hopefully this fixes it for you.

thebaldgeek commented 3 years ago

Thanks for your help and patience on this. I had to wait about 2 hours before the change showed up in my pallet. Did the update and restarted Node-RED. The new version is different, it now no longer mangles the output.... The problem is that it does not output any position data at all. It just echos exactly what I put in. I am setting msg.satid, msg.tle1, msg.tle2 and msg.timestamp. That is exactly what comes out of the node. I don't get NaN as I don't get any lat/lon or any position data at all.

Here is my simple flow that I am testing with.

[{"id":"ff478ce1.f0b78","type":"inject","z":"d014f738.c3a538","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":840,"y":300,"wires":[["7f94c7f5.78a3d8"]]},{"id":"7aaf15aa.0224dc","type":"debug","z":"d014f738.c3a538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1590,"y":240,"wires":[]},{"id":"7f94c7f5.78a3d8","type":"http request","z":"d014f738.c3a538","name":"get 98W TLE","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://celestrak.com/satcat/tle.php?CATNR=33278","tls":"","persist":false,"proxy":"","authType":"","x":1030,"y":300,"wires":[["76626a71.02b424"]]},{"id":"30bd0a6b.dcf856","type":"tle","z":"d014f738.c3a538","satid":"","tle1":"","tle2":"","coordsys":"latlongdeg","name":"98W 4-F3","x":1420,"y":240,"wires":[["7aaf15aa.0224dc"]]},{"id":"7ee3cc64.1568f4","type":"debug","z":"d014f738.c3a538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1350,"y":180,"wires":[]},{"id":"76626a71.02b424","type":"function","z":"d014f738.c3a538","name":"set","func":"list = msg.payload.split('\n');\n//list[0] = new Date().getTime();\nflow.set(\"98list\", list);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1230,"y":300,"wires":[["d7e3839d.1f54f"]]},{"id":"ca011185.37668","type":"function","z":"d014f738.c3a538","name":"get 98list","func":"list = flow.get(\"98list\");\n//list[0] = new Date().getTime();\nmsg.payload = list;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":240,"wires":[["4735b9e9.3dbc68","64941ac2.789ef4"]]},{"id":"d39902e0.20b55","type":"inject","z":"d014f738.c3a538","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":840,"y":240,"wires":[["ca011185.37668"]]},{"id":"d7e3839d.1f54f","type":"debug","z":"d014f738.c3a538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1410,"y":300,"wires":[]},{"id":"64941ac2.789ef4","type":"debug","z":"d014f738.c3a538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1130,"y":180,"wires":[]},{"id":"4735b9e9.3dbc68","type":"change","z":"d014f738.c3a538","name":"","rules":[{"t":"set","p":"satid","pt":"msg","to":"payload[0]","tot":"msg"},{"t":"set","p":"tle1","pt":"msg","to":"payload[1]","tot":"msg"},{"t":"set","p":"tle2","pt":"msg","to":"payload[2]","tot":"msg"},{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":240,"wires":[["30bd0a6b.dcf856","7ee3cc64.1568f4"]]}]

dceejay commented 3 years ago

When I said msg.payload needs to be either a timestamp, or an array of timestamps, or not be present (as per the info) - then that is what it needs to be. If I change the change node to delete the payload I get a position.

[{"id":"ff478ce1.f0b78","type":"inject","z":"fc693193.01403","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":260,"wires":[["7f94c7f5.78a3d8"]]},{"id":"7aaf15aa.0224dc","type":"debug","z":"fc693193.01403","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":200,"wires":[]},{"id":"7f94c7f5.78a3d8","type":"http request","z":"fc693193.01403","name":"get 98W TLE","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://celestrak.com/satcat/tle.php?CATNR=33278","tls":"","persist":false,"proxy":"","authType":"","x":350,"y":260,"wires":[["76626a71.02b424"]]},{"id":"30bd0a6b.dcf856","type":"tle","z":"fc693193.01403","satid":"","tle1":"","tle2":"","coordsys":"latlongdeg","name":"98W 4-F3","x":740,"y":200,"wires":[["7aaf15aa.0224dc"]]},{"id":"7ee3cc64.1568f4","type":"debug","z":"fc693193.01403","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":140,"wires":[]},{"id":"76626a71.02b424","type":"function","z":"fc693193.01403","name":"set","func":"list = msg.payload.split('\\n');\n//list[0] = new Date().getTime();\nflow.set(\"98list\", list);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":260,"wires":[["d7e3839d.1f54f"]]},{"id":"ca011185.37668","type":"function","z":"fc693193.01403","name":"get 98list","func":"list = flow.get(\"98list\");\n//list[0] = new Date().getTime();\nmsg.payload = list;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":200,"wires":[["4735b9e9.3dbc68","64941ac2.789ef4"]]},{"id":"d39902e0.20b55","type":"inject","z":"fc693193.01403","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":200,"wires":[["ca011185.37668"]]},{"id":"d7e3839d.1f54f","type":"debug","z":"fc693193.01403","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":260,"wires":[]},{"id":"64941ac2.789ef4","type":"debug","z":"fc693193.01403","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":140,"wires":[]},{"id":"4735b9e9.3dbc68","type":"change","z":"fc693193.01403","name":"","rules":[{"t":"set","p":"satid","pt":"msg","to":"payload[0]","tot":"msg"},{"t":"set","p":"tle1","pt":"msg","to":"payload[1]","tot":"msg"},{"t":"set","p":"tle2","pt":"msg","to":"payload[2]","tot":"msg"},{"t":"set","p":"timestamp","pt":"msg","to":"","tot":"date"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":200,"wires":[["30bd0a6b.dcf856","7ee3cc64.1568f4"]]}]

but I have pushed 0.5.3 to try and catch this escape also.

thebaldgeek commented 3 years ago

dceejay. Thanks so much. I tried deleting each payload object (msg.payload[0]). Your flow and version 0.5.3. works great. Thanks so much. This will now allow us to move the project forward in two ways, we can automatically get the TLE each hour for low earth orbit satellites and we can start work on the antenna tracking unit built around a Pi Zero running Node-RED that will keep the antennas centered on the passing satellite.