Possible to create AtoNs with SignalK API?
I am looking for a way to create AtoNs with a Python app using SignalK to forward to NMEA 2000 PGN 129041 and NMEA 0183 !AIVDM.
Is it possible to PUT or POST an ATON?
Is it possible to PUT or POST an ATON?
24 Replies
You need to use WebSockets and send deltas. https://signalk.org/specification/1.7.0/doc/
Depending on where you are getting the data. Might be easier to do with node-red.
node-red instead of Python or instead of WebSockets?
Both
We have an existing app in Python, so it will have to start there I think.
I still seem to be missing something. Sending auth request works, but no response to sending AtoN. What am I doing wrong?
There won’t be any response.
import asyncio
from websockets import connect
async def hello(uri):
async with connect(uri) as websocket:
message = await websocket.recv()
print(message)
login_msg ='{"requestId": "1234-45653-343454","login": {"username": "sample","password": "fakepassword"}}'
print(f'\n send >> {login_msg}')
await websocket.send(login_msg)
message = await websocket.recv()
print(f'\n recv << {message}')
# update
sampleAton = '{"context": "atons.urn:mrn:imo:mmsi:123456789","updates": [{"values": [{"path": "navigation.position.longitude","value": -117.23770},{"path": "navigation.position.latitude","value": 32.78577},{"path": "name","value": "XXX--XXX"},{"path": "virtual","value": "true"},{"path": "atonType.name","value": "Special Mark"}]}]}'
# full
# sampleAton = "{'source': {'label': 'can0', 'type': 'NMEA2000', 'pgn': 129041, 'src': '1', 'canName': 'c03282004a6ea6f0', 'deviceInstance': 0}, 'timestamp': '2024-08-25T22:40:14.568Z', 'values': [{'path': '', 'value': {'name': 'PYTHON-111-004'}}, {'path': 'navigation.position', 'value': {'longitude': -117.23770, 'latitude': 32.78577}}, {'path': 'design.length', 'value': {'overall': 40}}, {'path': 'atonType', 'value': {'id': 9, 'name': 'Beacon, Cardinal N'}}, {'path': 'design.beam', 'value': 60}, {'path': 'virtual', 'value': False}, {'path': 'offPosition', 'value': True}, {'path': '', 'value': {'mmsi': '105103837'}}, {'path': 'sensors.ais.class', 'value': 'ATON'}], '$source': 'can0.c03282004a6ea6f0'}"
await websocket.send(sampleAton)
print("\n sent >>",sampleAton)
message = await websocket.recv()
print(f'\n recv << message')
asyncio.run(hello("ws://localhost:3000/signalk/v1/stream?subscribe=none"))
The new AtoN does not show on OpenCPN or other attached plotters.Name is not formed correctly
Anything in the Data Browser?
Let me see if I can find a good example…
Yes, I see both in data browser. Maybe I don't have forwarding correct. An example would be awesome as well. Thank you!!
your position data is wrong too
(and yes, it's not really strait forward!)
I will base my request on your example. In the docs at https://signalk.org/specification/1.7.0/doc/request_response.html#websockets-and-other-full-duplex-protocols, it talks about a response to a websocket request. Should I not expect one?
No, won't get a response for sending deltas
How about full requests?
what do you mean "full reuest"?
Don't deltas just modify a previously sent packet?
no...
So if only the position changed, I could send that but not virtual, name, etc.
yes
as long as the "context" is the same
Ok, that makes sense.
Is there a way to ensure that SK got the request?
not really, you can assume it got it as long as you don't get any errors from the websocket libraries
Gotcha. I can't thank you enough for the help. Thanks.
ur welcome!
oh, didn't think of this before, but there's a way to make a python plugin. then you don't have to worry about managing a websocket and the python process.
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.
Awesome. I'll look into it. My marks are showing up on OpenCPN and a Raymarine MFD. Just have to figure out why the Garmin is being stubborn. But that's not a SK issue. Thanks again.
Where is the best place to look for the SK data model? I looked through the documentation but didn't see anything describing what to send for PGN 129041 - Aids to Navigation Report. Looking for Position Accuracy and AIS Transeiver Info.