SK
Signal K8mo ago
Simon

Simon - I would like to use a GPIO on a Raspber...

I would like to use a GPIO on a Raspberry Pi to record cumulative engine hours for a club vessel. I have some Python code that runs every 6 mins and, if the line is high, increments a value in a file. I would like to send this to the SignalK server on the same Pi. Is it as simple as adding a line similar to:
import requests
r = requests.put('http://localhost:3000/signalk/v1/api/vessels/self/engine/cumulativeHours', data ={"value": 710.1, "source": "gpio.engineFeed"})
print(r)
import requests
r = requests.put('http://localhost:3000/signalk/v1/api/vessels/self/engine/cumulativeHours', data ={"value": 710.1, "source": "gpio.engineFeed"})
print(r)
15 Replies
Simon
SimonOP8mo ago
Are the vessels/self/engine/cumulativeHours free text, or is there a canonical list?
Scott Bender
Scott Bender8mo ago
You cannot PUT to a path like this
Simon
SimonOP8mo ago
That's where I got the idea from "To change a value, a PUT request should be sent via HTTP or using a Signal K put delta." - How does one send the request to change a value then?
Scott Bender
Scott Bender8mo ago
“Note that this is very different than updating the current state of something. Use a delta update message to report the current / updated value of something, for example to report on the current wind speed from a sensor. See Delta Format” Not sure where you got that quote from? So you need at WebSocket connection. You also have to worry about authentication. What you are trying to do would probably be easier to do in node-red. Or you can make a python plugin.
Simon
SimonOP8mo ago
The website seems to have sent me to 1.5.0 which has that text under "Making a Request to Change a Value" Is there any documentation on Python plugins?
Scott Bender
Scott Bender8mo ago
GitHub
GitHub - SignalK/sk-plugin-python-demo: Demonstration of a SK serve...
Demonstration of a SK server plugin in Python. Contribute to SignalK/sk-plugin-python-demo development by creating an account on GitHub.
Scott Bender
Scott Bender8mo ago
More complex, should be super simple in node-red, and a very useful thing to learn. And note my link to the Keys Reference, propulsion/engine related paths and their units are listed there.
Simon
SimonOP8mo ago
I can't see in Node Red SignalK how to read from a file, but will have a look.
Scott Bender
Scott Bender8mo ago
You should be able to access gpio directly from node-red So, get rid of the python script and do everything in node-red
Simon
SimonOP6mo ago
I think the issue I've been banging up against is recording and recalling the previous state. So if for example, the engine has done 239.2 hours at shut down, I need to reimport that at switch on, but haven't worked out how yet.
Scott Bender
Scott Bender6mo ago
You can put it in persistent node-red storage. In the config for the plugin, In the “Settings Value” :
{ "default": { "module": "memory" }, "persist": { "module": "localfilesystem" } }
{ "default": { "module": "memory" }, "persist": { "module": "localfilesystem" } }
Scott Bender
Scott Bender6mo ago
Here’s a flow that stores and reads a global variable from there. https://github.com/SignalK/node-red-embedded/blob/master/examples/put-handler.json
GitHub
node-red-embedded/examples/put-handler.json at master · SignalK/no...
Node red nodes for use with the signalk-node-red plugin - SignalK/node-red-embedded
Scott Bender
Scott Bender6mo ago
(And sorry I’m so late! I totally missed your question about this)

Did you find this page helpful?