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?
24 Replies
Scott Bender
Scott Bender4mo ago
You need to use WebSockets and send deltas. https://signalk.org/specification/1.7.0/doc/
Scott Bender
Scott Bender4mo ago
Depending on where you are getting the data. Might be easier to do with node-red.
AlienTechnology
AlienTechnologyOP4mo ago
node-red instead of Python or instead of WebSockets?
Scott Bender
Scott Bender4mo ago
Both
AlienTechnology
AlienTechnologyOP4mo ago
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?
Scott Bender
Scott Bender4mo ago
There won’t be any response.
AlienTechnology
AlienTechnologyOP4mo ago
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.
Scott Bender
Scott Bender4mo ago
Name is not formed correctly Anything in the Data Browser? Let me see if I can find a good example…
AlienTechnology
AlienTechnologyOP4mo ago
Yes, I see both in data browser. Maybe I don't have forwarding correct. An example would be awesome as well. Thank you!!
Scott Bender
Scott Bender4mo ago
{
"updates": [
{
"values": [
{
"path": "",
"value": {
"name": "SW"
}
},
{
"path": "navigation.position",
"value": {
"longitude": -76.3847132,
"latitude": 38.99384
}
},
{
"path": "atonType",
"value": {
"id": 13,
"name": "Beacon, Port Hand"
}
},
{
"path": "virtual",
"value": true
},
{
"path": "offPosition",
"value": false
},
{
"path": "",
"value": {
"mmsi": "993672315"
}
},
{
"path": "sensors.ais.class",
"value": "ATON"
}
]
}
],
"context": "atons.urn:mrn:imo:mmsi:993672315"
}
{
"updates": [
{
"values": [
{
"path": "",
"value": {
"name": "SW"
}
},
{
"path": "navigation.position",
"value": {
"longitude": -76.3847132,
"latitude": 38.99384
}
},
{
"path": "atonType",
"value": {
"id": 13,
"name": "Beacon, Port Hand"
}
},
{
"path": "virtual",
"value": true
},
{
"path": "offPosition",
"value": false
},
{
"path": "",
"value": {
"mmsi": "993672315"
}
},
{
"path": "sensors.ais.class",
"value": "ATON"
}
]
}
],
"context": "atons.urn:mrn:imo:mmsi:993672315"
}
your position data is wrong too (and yes, it's not really strait forward!)
AlienTechnology
AlienTechnologyOP4mo ago
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?
Scott Bender
Scott Bender4mo ago
No, won't get a response for sending deltas
AlienTechnology
AlienTechnologyOP4mo ago
How about full requests?
Scott Bender
Scott Bender4mo ago
what do you mean "full reuest"?
AlienTechnology
AlienTechnologyOP4mo ago
Don't deltas just modify a previously sent packet?
Scott Bender
Scott Bender4mo ago
no...
AlienTechnology
AlienTechnologyOP4mo ago
So if only the position changed, I could send that but not virtual, name, etc.
Scott Bender
Scott Bender4mo ago
yes as long as the "context" is the same
AlienTechnology
AlienTechnologyOP4mo ago
Ok, that makes sense. Is there a way to ensure that SK got the request?
Scott Bender
Scott Bender4mo ago
not really, you can assume it got it as long as you don't get any errors from the websocket libraries
AlienTechnology
AlienTechnologyOP4mo ago
Gotcha. I can't thank you enough for the help. Thanks.
Scott Bender
Scott Bender4mo ago
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.
Scott Bender
Scott Bender4mo 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.
AlienTechnology
AlienTechnologyOP3mo ago
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.
Want results from more Discord servers?
Add your server