GPS microservice API Reference
Developers can chose any programming language to develop gps app.
All that app needs to do is to invoke well know GPS service API's to configure and retrieve gps data.
This document talks in detail the steps to do that.Most of the code snaphots are here in python.
The GPS Microservice is available as a IOx installable and appears as below in the Microservice name-space.
An application should declare dependency on GPS service in its package.yaml.Once the dependency is declared, IOx hosting framework would ensure that GPS service is deployed before the application can be deployed on the IOx enabled device.Also the App package.yaml needs to be an oauth client.This required to get access token which is provided as part of any request to NBI.
App can have any other logic/functionality apart from the steps mentioned here.
Please tune the cpu, memory and disk requirements based on testing and profiling.Below snapshot is just an example.
Below is snapshot of package.yaml section which highlights the above mentioned requirements
```
depends-on:
packages:
-
name: "IOxGPS"
version: "1.5.0"
resources:
profile: custom
cpu: "100"
disk: "10"
memory: "30"
oauth: [OauthClient]
client_id = os.environ["OAUTH_CLIENT_ID"]
client_secret = os.environ["OAUTH_CLIENT_SECRET"]
server_ip = os.environ["OAUTH_TOKEN_SERVER_IPV4"]
server_port = os.environ["OAUTH_TOKEN_SERVER_PORT"]
api_path = os.environ["OAUTH_TOKEN_API_PATH"]
token_url = "https://"+server_ip+":"+server_port+api_path
Do a POST call on the url derived above
print "client_id: "+client_id
print "client_secret: "+client_secret
print "token_url: "+token_url
tokens = urlparse.urlparse(token_url)
if tokens.scheme == 'https':
con = httplib.HTTPSConnection(tokens.netloc)
else:
con = httplib.HTTPConnection(tokens.netloc)
con.request(
"POST",
tokens.path,
urlencode({'grant_type': 'client_credentials'}),
{
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + base64.b64encode("%s:%s" % (client_id, client_secret))
}
)
Parse the access token from the JSON response.
response = con.getresponse()
if response.status / 100 != 2:
raise Exception("oauth token url returned %s" % response.status)
access_token = json.loads(response.read())['access_token']
con.close()
POST on https://nbi_IP_ADDRESS:nbi_TCP_9999_PORT/api/v1/mw/gps/config
Sample JSON payload for above API
{
"gps-interval-seconds": 5,
"streaming-enabled": true,
"topic" : "gps"
}
nbi_IP_ADDRESS is the env variable exposed to the app.It provides NBI IP to communicate to.
nbi_TCP_9999_PORT is env variable exposed to the app.It provides NBI Port
{
"value": {
"gps-interval-seconds": 5,
"streaming-enabled": true,
"topic": "gps"
}
}
{
"message": {
"altitude": "5454.000000",
"latitude": "42.915249",
"longitude": "75.041801",
"return-code": "200",
"timestamp": "Sun Dec 17 23:13:05 2017"
},
"topic": "gps"
}
{
"definitions": {},
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/example.json",
"type": "object",
"properties": {
"message": {
"$id": "/properties/message",
"type": "object",
"properties": {
"altitude": {
"$id": "/properties/message/properties/altitude",
"type": "string",
"title": "The Altitude Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"5454.000000"
]
},
"latitude": {
"$id": "/properties/message/properties/latitude",
"type": "string",
"title": "The Latitude Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"42.915249"
]
},
"longitude": {
"$id": "/properties/message/properties/longitude",
"type": "string",
"title": "The Longitude Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"75.041801"
]
},
"return-code": {
"$id": "/properties/message/properties/return-code",
"type": "string",
"title": "The Return-code Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"200"
]
},
"timestamp": {
"$id": "/properties/message/properties/timestamp",
"type": "string",
"title": "The Timestamp Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Sun Dec 17 23:15:05 2017"
]
}
}
},
"topic": {
"$id": "/properties/topic",
"type": "string",
"title": "The Topic Schema.",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"gps"
]
}
}
}
{
"message": {
"description": "GPS data not available. Check the IOS configuration",
"return-code": "404"
},
"topic": "gps"
}