freakent / node-red-contrib-sunevents

A node for node-red that generates events based on the position of the Sun at the appropriate time of day.
Apache License 2.0
15 stars 13 forks source link

V3 Beta Testers #21

Closed freakent closed 3 years ago

freakent commented 3 years ago

There is a new V3 of this node. if you want to be a Beta tester, follow the instructions below and leave replies below.

V3 works a little differently than previous version, please take a look at the README documentation and look at the example flow.

To install, change to your node-red user directory (maybe $HOME/.node-red) and enter: npm install freakent/node-red-contrib-sunevents.git#v3

or

npm install https://github.com/freakent/node-red-contrib-sunevents/archive/3.0-beta.tar.gz

nmbath commented 3 years ago

Do you have a version that does not need git. Unfortunately the VenusOS does not have git installed and I can not find a way of installing it.

freakent commented 3 years ago

Try this: npm install https://github.com/freakent/node-red-contrib-sunevents.git#v3

This just uses pure npm and https.

-- update -- actually it does still use git so if you can't use git try this instead: npm install https://github.com/freakent/node-red-contrib-sunevents/archive/3.0-beta.tar.gz

nmbath commented 3 years ago

still get an error...

npm install https://github.com/freakent/node-red-contrib-sunevents.git#v3 npm ERR! path git npm ERR! code ENOENT npm ERR! errno ENOENT npm ERR! syscall spawn git npm ERR! enoent Error while executing: npm ERR! enoent undefined ls-remote -h -t https://github.com/freakent/node-red-contrib-sunevents.git npm ERR! enoent npm ERR! enoent npm ERR! enoent spawn git ENOENT npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

nmbath commented 3 years ago

manually downloaded the gift to my local machine, pushed via ssh to the remote machine and ran:

npm install ../testing/node-red-contrib-sunevents

It's on and will do some testing

freakent commented 3 years ago

Glad you got it downloaded. If you have to go through it again, it looks like this should work. npm install https://github.com/freakent/node-red-contrib-sunevents/archive/3.0-beta.tar.gz

nmbath commented 3 years ago

Not sure what other systems provide, but my GPS sources comes through as an integer and not text. Is there anyway to handle both?

image
freakent commented 3 years ago

Actually that was my mistake passing them as strings in the example flow. I just ran a test and it works with either numbers or strings. Clearly numbers would be the preferred option. Are you having problems with the numeric latitude and longitude?

freakent commented 3 years ago

How often does the Victron pass new lat and long values into the flow? I am wondering whether I should create some sort of GPS throttle node so only coordinates more than say 10nm or that are more than 1 hour since last update are let through.

nmbath commented 3 years ago

It provides an update once every 5 seconds. I am sure if a feed from SignalK was taken it could me much faster than that. So your idea of throttling would be useful. I have managed this with the following and using a delay node, which will only allow one message following a reset.

I will go back and check my flow. I also had to process the output of the GPS as it outputs separate Lat and Lng and need to merge these into a single message.

[{"id":"296f17d7.dd09c8","type":"tab","label":"Sun Event Testing","disabled":false,"info":""},{"id":"5fe0a5ac.f2d44c","type":"victron-input-gps","z":"296f17d7.dd09c8","service":"com.victronenergy.gps.ve_ttyUSB3","path":"/Position/Latitude","serviceObj":{"service":"com.victronenergy.gps.ve_ttyUSB3","name":"NMEA-0183 GPS (USB3)","paths":[{"path":"/Altitude","type":"float","name":"Altitude (m)"},{"path":"/Course","type":"float","name":"Course (Deg)"},{"path":"/Fix","type":"integer","name":"Fix"},{"path":"/NrOfSatellites","type":"integer","name":"Number of satellites"},{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},{"path":"/Speed","type":"float","name":"Speed (m/s)"}]},"pathObj":{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},"name":"","x":210,"y":120,"wires":[["6c6104a7.020d64"]]},{"id":"add7f925.f54f3","type":"victron-input-gps","z":"296f17d7.dd09c8","service":"com.victronenergy.gps.ve_ttyUSB3","path":"/Position/Longitude","serviceObj":{"service":"com.victronenergy.gps.ve_ttyUSB3","name":"NMEA-0183 GPS (USB3)","paths":[{"path":"/Altitude","type":"float","name":"Altitude (m)"},{"path":"/Course","type":"float","name":"Course (Deg)"},{"path":"/Fix","type":"integer","name":"Fix"},{"path":"/NrOfSatellites","type":"integer","name":"Number of satellites"},{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},{"path":"/Speed","type":"float","name":"Speed (m/s)"}]},"pathObj":{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},"name":"","x":200,"y":160,"wires":[["1c93f768.b83d51"]]},{"id":"600d1656.e9f58","type":"sun-events","z":"296f17d7.dd09c8","testmode":false,"verbose":"N","topic":"","name":"Sun Events","x":830,"y":260,"wires":[["e6610efc.aa2558"]]},{"id":"e6610efc.aa2558","type":"debug","z":"296f17d7.dd09c8","name":"Sun Event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":220,"wires":[]},{"id":"9c9056dc.30825","type":"join","z":"296f17d7.dd09c8","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":120,"wires":[["b5f62fcc.0a31b8","e6e93a61.8a24f8"]]},{"id":"2967314f.86be3e","type":"debug","z":"296f17d7.dd09c8","name":"GPS Passed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":140,"wires":[]},{"id":"e6e93a61.8a24f8","type":"throttle","z":"296f17d7.dd09c8","name":"Delay","throttleType":"reset","timeLimit":0,"timeLimitType":"seconds","countLimit":0,"blockSize":0,"locked":false,"x":820,"y":160,"wires":[["2967314f.86be3e","600d1656.e9f58"]]},{"id":"f8e3d0f2.2be458","type":"inject","z":"296f17d7.dd09c8","name":"","props":[{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"00 00 *","once":false,"onceDelay":0.1,"topic":"","x":520,"y":360,"wires":[["e6e93a61.8a24f8","14ab5c55.38f2b4"]]},{"id":"14ab5c55.38f2b4","type":"debug","z":"296f17d7.dd09c8","name":"Trigger","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":380,"wires":[]},{"id":"b5f62fcc.0a31b8","type":"debug","z":"296f17d7.dd09c8","name":"GPS Available","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":100,"wires":[]},{"id":"1c93f768.b83d51","type":"function","z":"296f17d7.dd09c8","name":"Convert Number to String","func":"var newMsg = {payload:{ }}\nnewMsg.payload.longitude = String(msg.payload);\nreturn newMsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":220,"wires":[["9c9056dc.30825"]]},{"id":"6c6104a7.020d64","type":"function","z":"296f17d7.dd09c8","name":"Convert Number to String","func":"var newMsg = {payload:{ }}\nnewMsg.payload.latitude = String(msg.payload);\nreturn newMsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":40,"wires":[["9c9056dc.30825"]]}]

nmbath commented 3 years ago

I can confirm it is working OK with numbers. For some reason last night it wasn't and only seemed to start when I switched to text....

image

Updated flow: [{"id":"296f17d7.dd09c8","type":"tab","label":"Sun Event Testing","disabled":false,"info":""},{"id":"5fe0a5ac.f2d44c","type":"victron-input-gps","z":"296f17d7.dd09c8","service":"com.victronenergy.gps.ve_ttyUSB3","path":"/Position/Latitude","serviceObj":{"service":"com.victronenergy.gps.ve_ttyUSB3","name":"NMEA-0183 GPS (USB3)","paths":[{"path":"/Altitude","type":"float","name":"Altitude (m)"},{"path":"/Course","type":"float","name":"Course (Deg)"},{"path":"/Fix","type":"integer","name":"Fix"},{"path":"/NrOfSatellites","type":"integer","name":"Number of satellites"},{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},{"path":"/Speed","type":"float","name":"Speed (m/s)"}]},"pathObj":{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},"name":"","x":210,"y":120,"wires":[["c4045c8.158c5a"]]},{"id":"add7f925.f54f3","type":"victron-input-gps","z":"296f17d7.dd09c8","service":"com.victronenergy.gps.ve_ttyUSB3","path":"/Position/Longitude","serviceObj":{"service":"com.victronenergy.gps.ve_ttyUSB3","name":"NMEA-0183 GPS (USB3)","paths":[{"path":"/Altitude","type":"float","name":"Altitude (m)"},{"path":"/Course","type":"float","name":"Course (Deg)"},{"path":"/Fix","type":"integer","name":"Fix"},{"path":"/NrOfSatellites","type":"integer","name":"Number of satellites"},{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},{"path":"/Speed","type":"float","name":"Speed (m/s)"}]},"pathObj":{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},"name":"","x":200,"y":160,"wires":[["bad83cfb.60bae"]]},{"id":"600d1656.e9f58","type":"sun-events","z":"296f17d7.dd09c8","testmode":false,"verbose":"N","topic":"","name":"Sun Events","x":830,"y":260,"wires":[["e6610efc.aa2558"]]},{"id":"e6610efc.aa2558","type":"debug","z":"296f17d7.dd09c8","name":"Sun Event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":220,"wires":[]},{"id":"9c9056dc.30825","type":"join","z":"296f17d7.dd09c8","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":120,"wires":[["b5f62fcc.0a31b8","e6e93a61.8a24f8"]]},{"id":"2967314f.86be3e","type":"debug","z":"296f17d7.dd09c8","name":"GPS Passed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":140,"wires":[]},{"id":"e6e93a61.8a24f8","type":"throttle","z":"296f17d7.dd09c8","name":"Delay","throttleType":"reset","timeLimit":0,"timeLimitType":"seconds","countLimit":0,"blockSize":0,"locked":false,"x":820,"y":160,"wires":[["2967314f.86be3e","600d1656.e9f58"]]},{"id":"f8e3d0f2.2be458","type":"inject","z":"296f17d7.dd09c8","name":"","props":[{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"00 00 *","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":520,"y":360,"wires":[["e6e93a61.8a24f8","14ab5c55.38f2b4"]]},{"id":"14ab5c55.38f2b4","type":"debug","z":"296f17d7.dd09c8","name":"Trigger","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":380,"wires":[]},{"id":"b5f62fcc.0a31b8","type":"debug","z":"296f17d7.dd09c8","name":"GPS Available","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":100,"wires":[]},{"id":"bad83cfb.60bae","type":"change","z":"296f17d7.dd09c8","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.longitude","tot":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":180,"wires":[["9c9056dc.30825"]]},{"id":"c4045c8.158c5a","type":"change","z":"296f17d7.dd09c8","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.latitude","tot":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":120,"wires":[["9c9056dc.30825"]]}]

nmbath commented 3 years ago

Thinking about the filtering.

For most use cases I would think that one update a day is OK. Updates every 10nm seems a little overkill as things will not change that much time wise over that distance. Doing it hourly also seems over kill from my perspective.

Maybe add an option into the node to allow the user to configure what they want to trigger a re-calc on. The re-calc could be triggered by time or distance moved, or both. So for example if position has changed by > N nm or every N time period. Another example could be if position has changed by > n nm or every day at 00:00.

A further alternatively allow the node to react to a trigger, which is basically a recalculation message. When it receives the recalculation message it takes the next GPS input and recalculates. It then ignores all further GPS messages until the next recalculation messages arrives.

freakent commented 3 years ago

I think I can simplify your work around by using globals. I don't have access to the Victron nodes so I simulated the GPS nodes using inject node. How do you tell which is latitude and longitude from the Victron nodes? Try this:

[{"id":"f10f1911.0d5928","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"7ed2700.7d9ad9","type":"inject","z":"f10f1911.0d5928","name":"Fake Victron GPS Input (Latitude)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1.501364","payloadType":"num","x":200,"y":100,"wires":[["a7098192.563ad"]]},{"id":"133e413c.d490af","type":"inject","z":"f10f1911.0d5928","name":"Fake Victron GPS Input (Longitude)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-0.1440787","payloadType":"num","x":210,"y":180,"wires":[["83eeb23b.83ec8"]]},{"id":"a7098192.563ad","type":"change","z":"f10f1911.0d5928","name":"","rules":[{"t":"set","p":"latitude","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":100,"wires":[[]]},{"id":"83eeb23b.83ec8","type":"change","z":"f10f1911.0d5928","name":"","rules":[{"t":"set","p":"longitude","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":180,"wires":[[]]},{"id":"bec53378.d5ba5","type":"inject","z":"f10f1911.0d5928","name":"Inject from Global","props":[{"p":"payload.latitude","v":"latitude","vt":"global"},{"p":"payload.longitude","v":"longitude","vt":"global"}],"repeat":"","crontab":"00 12 *","once":false,"onceDelay":0.1,"topic":"","x":140,"y":300,"wires":[["9bb49816.5ff1d8"]]},{"id":"9bb49816.5ff1d8","type":"sun-events","z":"f10f1911.0d5928","testmode":"N","verbose":"N","topic":"","name":"","x":440,"y":320,"wires":[["3f2e386d.e75748"]]},{"id":"3f2e386d.e75748","type":"debug","z":"f10f1911.0d5928","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":720,"y":320,"wires":[]}]

nmbath commented 3 years ago

I'v learnt something today. Much cleaner and simple.

With a solution like this, it is possible to inject updated positions at any time. So does the node need filtering?

freakent commented 3 years ago

Possibly not. But I can think of some other uses for a GPS throttler.

I'll add this flow to the examples too.

freakent commented 3 years ago

How has anybody been getting on with this new version? Any issues?

nmbath commented 3 years ago

Mine is working fine. actually need to move the boat to test the GPS feed properly.

nmbath commented 3 years ago

Just checked BBC Weather for the boats locations and it is reporting sunrise as

image

Noe Red is reporting it as

image

Once I can move the boat more than a hundred miles, I'll let you know if everything is OK. I expect it will be

freakent commented 3 years ago

29th March

freakent commented 3 years ago

Hi Everyone, you may have noticed that I have not yet pushed this live yet. I am still contemplating whether I should bring back the GPS lat and long in the node's config page so as not to break people's existing flows. I suspect few people will read the documentation and I might get complaints that their flows have broken? The values supplied via msg.payload would override those set in the config. Any thoughts?

nmbath commented 3 years ago

Great idea, means if people for some reason do not have a GPS, and are static they can still use.

Maybe have a switch to allow the node to be auto-configured if GPS is fed in, or show when it is using static data verses external GPS data.

freakent commented 3 years ago

V3 was pushed live this morning. You many get an error about unrecognised type. I was planning the change the name of node slightly in v3 but I realised in final testing that it would break everyone’s existing v2 flows, so the needs of the many outweighed the needs of the few. Thanks for your feedback. If you pull in the new version of the flow it should be fine.