This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pushing data from Python to SignalK?
#1
Hello,
 
I am facing a problem with pushing data from Python to SignalK, which I cannot solve (although I think the solution might be trivial):
 
I am collecting data (e.g. from a sensor) in Python and want send them to SignalK using the Python Requests post() or put() method, but none of them is working.
 
  • When I use the post() method, I get error 404 with the message: “Cannot POST /signalk/v1/api/vessels/self/environment/test/temperature”
  • When I use the put() method, I get error 405 with: “PUT not supported for environment.test.temperature”
 
Here is the code I use:

Code:
import requests
LOGIN2 = {"username":"name","password":"pwd”}
DATA3 = {"value":1.52, "source":"anysource"}
url1 = 'http://localhost:3000/signalk/v1/auth/login'
url2 = 'http://localhost:3000/signalk/v1/api/vessels/self/environment/cpu/temperature'

r = requests.post(url=url1, json=LOGIN2)
cookie = r.cookies
while True:
    r = requests.post(url = url2, data = DATA3, cookies=cookie)
#    r = requests.put(url = url2, data = DATA3, cookies=cookie)

 
I also experience the same error messages when I use "curl PUT ..." or "curl POST ..." from the terminal...

Can anybody give me a hint what I might do wrong here?
Reply
#2
there is not much python for signalk yet, but see this:

https://github.com/pypilot/pypilot/blob/...signalk.py


I do not use GET an POST, instead use websockets for streaming data. This is more efficient also.

The problem I now face is, the websocket to signalk_node_server is supposed to be bidirectional, at least I read this somewhere, but it is not receiving signalk, it is only transmitting signalk, and I don't have a solution for this other than to add a udp port connection and have the python script dump the data there and add this to the server as an input, but I prefer to avoid this route.
Reply
#3
Dear Sean,

thanks for your reply. I will test your library once back from my sailing trip.

What is strange nevertheless is, that I can push and pull data (with requests.get and requests.put) to the path /signalk/v1/api/vessels/self/notifications/navigation/anchor/state, but it does not work for the path /signalk/v1/api/vessels/self/environment/cpu/temperature. So I was wondering if I do something wrong here (syntax?) ...

Cheers,

Tom
Reply
#4
As Sean said in Signal K updates to sensor values should be sent over WebSocket as Signal K deltas.

(2020-07-13, 03:11 AM)seandepagnier Wrote: The problem I now face is, the websocket to signalk_node_server is supposed to be bidirectional, at least I read this somewhere, but it is not receiving signalk, it is only transmitting signalk, and I don't have a solution for this other than to add a udp port connection and have the python script dump the data there and add this to the server as an input, but I prefer to avoid this route.

The WebSocket connection is bidirectional and you can send deltas that are processed by the server. But if you have security enabled and you have not provided credentials the server will silently ignore your deltas. Is this the case? If not please post an issue at https://github.com/SignalK/signalk-serve...issues/new, sending deltas over ws is used routinely.
Reply
#5
1)  I am using zeroconf to find the address of the service with swname of signalk-server.
2)  I connect to this address with http://<address>/signalk to find the websocket url
3)  I connect to this websocket url and receive signalk deltas.   The subscriptions work but my messages sent seem to be ignored.
How can I tell if encryption is required?   Would it be possible for the server to send a message informing if messages are dropped?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)