SK
Signal K3mo ago
matte

Metadata via api 2.11

hi, I'm working a little bit of an experiment and I am wondering if it's still possible to add custom meter data keys via API in the version 2.11? For example I would not like to use the existing one such as description et cetera I would also like to add for example equipment key as a another key with a value after. example { "equipment": "Engine_1" } can I still use the API to achieve this? I've tried round a lot but get some errors.
33 Replies
Teppo Kurki
Teppo Kurki3mo ago
Sorry i don’t understand what you are trying to do, please explain more, with examples
matte
matteOP3mo ago
I will try to explain I am trying to set metadata of a path using the put API /signalk/v1/api/vessels/self/' + item.fullKey + '/meta In older version like 1.7 if remeber it was possible to add custom keys as metadata and custom units when adding metadata via API. example
/meta example metadata Payload for the put request that have used in the past { "units": "knots", "euqipmentTag": "Engine" "serialNumer: "tet12345 } But since i cant ge this to work in 2.11 I was in the ui under browse data it was possible to metadat directly but only under pre defined keys like description etc My question is have the API changed ? and is it still possible to add custom keys under metadata or only using the predefined ones ?
Scott Bender
Scott Bender3mo ago
Nothing changed. You can use PUT to update meta data See the specification for details on how to use PUT
matte
matteOP3mo ago
@Scott Bender It is this documentation you refer to? https://signalk.org/specification/1.7.0/doc/put.html I am trying to get it work i have got so far that i get only 202 response Pending but noting updated Are there any more documentation how the metadata should look like? in the payload
Scott Bender
Scott Bender3mo ago
yes, that's the doc you will get Pending response from that once its done you should see your changes in baseDeltas.json ? here's the code from where the admin ui does it:
const saveMeta = (path, meta) => {
fetch(`/signalk/v1/api/vessels/self/${path.replaceAll('.', '/')}/meta`, {
method: 'PUT',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ value: meta }),
})
}
const saveMeta = (path, meta) => {
fetch(`/signalk/v1/api/vessels/self/${path.replaceAll('.', '/')}/meta`, {
method: 'PUT',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ value: meta }),
})
}
Also, in the pending reponse, there is a url you can call to get the final status and see if there were any errors
matte
matteOP3mo ago
The issue is that i dont have access ot the setting files, i need the one i am doing the study project with if we reach the file since we are running it in docker so i cant see it. Thanks for the exmaple. is the meta after value the stringified json object? like this but stringified "meta": { "discipline": "Naivgation", "key": "Position.Longitude", "topic": "Position.Longitude" },
Scott Bender
Scott Bender3mo ago
no "meta" the body should look like:
{ "value": { "discipline": "Naivgation", "key": "Position.Longitude", "topic": "Position.Longitude"}
{ "value": { "discipline": "Naivgation", "key": "Position.Longitude", "topic": "Position.Longitude"}
and note that you will be overwriting any eisting meta this way I think... actually not sure about that
matte
matteOP3mo ago
I get this in return but there is no meta data nor when i use the api or in ui { "state": "COMPLETED", "requestId": "e8392c1b-60c4-417d-a4f5-9ef444d0382e", "statusCode": 200, "href": "/signalk/v1/requests/e8392c1b-60c4-417d-a4f5-9ef444d0382e", "user": "admin" }
Scott Bender
Scott Bender3mo ago
you changed to not include "meta" in the body?
matte
matteOP3mo ago
yes
Scott Bender
Scott Bender3mo ago
what the exact path you are PUTing to? the ui won't show that meta data or will it... let me check
matte
matteOP3mo ago
this is my strinfied value. Do i need to give source key ?
Scott Bender
Scott Bender3mo ago
no, you don't need source
matte
matteOP3mo ago
In the old 1.7 it showed up This is my stringified payload "{"value":{"discipline":"Naivgation","key":"Position.Longitude","topic":"Position.Longitude"}}"
Scott Bender
Scott Bender3mo ago
looks good the ui now only shows "known" meta values which I would love to fix I'll put that on my list...
matte
matteOP3mo ago
Sounds good but i sthould still be possible to store it and return it in the api call?
Scott Bender
Scott Bender3mo ago
yes what's the path you are PUTing too? and what API are you calling to get the meta? let me do a quick test... works for me:
$ curl -k -X PUT -H "Content-Type: application/json" -d '{"value": {"displayName": "ACR"}}' http://localhost:3000/signalk/v1/api/vessels/self/electrical/venus-input/acr/state/meta
{"state":"PENDING","requestId":"1bbbd54e-80fb-4ec2-886c-792908b12772","statusCode":202,"href":"/signalk/v1/requests/1bbbd54e-80fb-4ec2-886c-792908b12772","action":{"href":"/signalk/v1/requests/1bbbd54e-80fb-4ec2-886c-792908b12772"}}$
$
$
$ curl http://localhost:3000/signalk/v1/api/vessels/self/electrical/venus-input/acr/state/meta
{"displayName":"ACR"}$
$ curl -k -X PUT -H "Content-Type: application/json" -d '{"value": {"displayName": "ACR"}}' http://localhost:3000/signalk/v1/api/vessels/self/electrical/venus-input/acr/state/meta
{"state":"PENDING","requestId":"1bbbd54e-80fb-4ec2-886c-792908b12772","statusCode":202,"href":"/signalk/v1/requests/1bbbd54e-80fb-4ec2-886c-792908b12772","action":{"href":"/signalk/v1/requests/1bbbd54e-80fb-4ec2-886c-792908b12772"}}$
$
$
$ curl http://localhost:3000/signalk/v1/api/vessels/self/electrical/venus-input/acr/state/meta
{"displayName":"ACR"}$
Scott Bender
Scott Bender3mo ago
$ curl -k -X PUT -H "Content-Type: application/json" -d '{"value":{"discipline":"Naivgation","key":"Position.Longitude","topic":"Position.Longitude"}}' http://localhost:3000/signalk/v1/api/vessels/self/navigation/position/meta
{"state":"PENDING","requestId":"f0e4bdcf-a8db-44f2-b6cd-b9d0ba347340","statusCode":202,"href":"/signalk/v1/requests/f0e4bdcf-a8db-44f2-b6cd-b9d0ba347340","action":{"href":"/signalk/v1/requests/f0e4bdcf-a8db-44f2-b6cd-b9d0ba347340"}}$
$ curl http://localhost:3000/signalk/v1/api/vessels/self/navigation/position/meta
{"description":"The position of the vessel in 2 or 3 dimensions (WGS84 datum)","properties":{"longitude":{"type":"number","description":"Longitude","units":"deg","example":4.98765245},"latitude":{"type":"number","description":"Latitude","units":"deg","example":52.0987654},"altitude":{"type":"number","description":"Altitude","units":"m"}},"discipline":"Naivgation","key":"Position.Longitude","topic":"Position.Longitude"}$
$ curl -k -X PUT -H "Content-Type: application/json" -d '{"value":{"discipline":"Naivgation","key":"Position.Longitude","topic":"Position.Longitude"}}' http://localhost:3000/signalk/v1/api/vessels/self/navigation/position/meta
{"state":"PENDING","requestId":"f0e4bdcf-a8db-44f2-b6cd-b9d0ba347340","statusCode":202,"href":"/signalk/v1/requests/f0e4bdcf-a8db-44f2-b6cd-b9d0ba347340","action":{"href":"/signalk/v1/requests/f0e4bdcf-a8db-44f2-b6cd-b9d0ba347340"}}$
$ curl http://localhost:3000/signalk/v1/api/vessels/self/navigation/position/meta
{"description":"The position of the vessel in 2 or 3 dimensions (WGS84 datum)","properties":{"longitude":{"type":"number","description":"Longitude","units":"deg","example":4.98765245},"latitude":{"type":"number","description":"Latitude","units":"deg","example":52.0987654},"altitude":{"type":"number","description":"Altitude","units":"m"}},"discipline":"Naivgation","key":"Position.Longitude","topic":"Position.Longitude"}$
works for me
matte
matteOP3mo ago
i am thinking if there could be some permissions issues with the file
Scott Bender
Scott Bender3mo ago
you should get an error from the PUT request in that case I can double check that...
matte
matteOP3mo ago
that works actually then i had a little special path that where it did not work
Scott Bender
Scott Bender3mo ago
yep, I get a failure if there are permission issues
{"state":"FAILURE","message":"Unable to save to defaults file"}
{"state":"FAILURE","message":"Unable to save to defaults file"}
matte
matteOP3mo ago
it works but i want make it work on this path Machinery.SteeringGear.1.Pump.2.State
Scott Bender
Scott Bender3mo ago
$ curl -k -X PUT -H "Content-Type: application/json" -d '{"value": {"displayName": "The Pump"}}' http://localhost:3000/signalk/v1/api/vessels/self/Machinery/SteeringGear/1/Pump/2/State/meta
{"state":"PENDING","requestId":"ae267bdc-463c-4550-bba1-75d3dbc765ea","statusCode":202,"href":"/signalk/v1/requests/ae267bdc-463c-4550-bba1-75d3dbc765ea","action":{"href":"/signalk/v1/requests/ae267bdc-463c-4550-bba1-75d3dbc765ea"}}$
$
$
$ curl http://localhost:3000/signalk/v1/api/vessels/self/Machinery/SteeringGear/1/Pump/2/State/meta
{"displayName":"The Pump"}$
$ curl -k -X PUT -H "Content-Type: application/json" -d '{"value": {"displayName": "The Pump"}}' http://localhost:3000/signalk/v1/api/vessels/self/Machinery/SteeringGear/1/Pump/2/State/meta
{"state":"PENDING","requestId":"ae267bdc-463c-4550-bba1-75d3dbc765ea","statusCode":202,"href":"/signalk/v1/requests/ae267bdc-463c-4550-bba1-75d3dbc765ea","action":{"href":"/signalk/v1/requests/ae267bdc-463c-4550-bba1-75d3dbc765ea"}}$
$
$
$ curl http://localhost:3000/signalk/v1/api/vessels/self/Machinery/SteeringGear/1/Pump/2/State/meta
{"displayName":"The Pump"}$
matte
matteOP3mo ago
for some reason i got it to work now. I restarted signalk then it worked better thanks for all help
Scott Bender
Scott Bender3mo ago
odd ur welcome
matte
matteOP3mo ago
Just from a courious question, how many data points / paths do you think a singalk can handle at second level?
Scott Bender
Scott Bender3mo ago
really hard to give a number because it's going to be about memory and CPU I have 700+ paths on my boat and recording it all in influxdb, this is on a 16G pi 4, no performance issues
matte
matteOP3mo ago
that is cool We are doing a research project conneting a large ship simulator which have around 1800 signals to prove that the maritime industry would benift of apis
Scott Bender
Scott Bender3mo ago
should be able to handle it fine given decent hardware
matte
matteOP3mo ago
Yes we will see, thanks for the help we continue tommorow
Teppo Kurki
Teppo Kurki3mo ago
Please share more about your project later. And i am also interested in your take on apis in this field

Did you find this page helpful?