device
Websocket connection to receive state changes the given Device ID
info
Events are emitted only for subscribed fields. For example if you subscribe to the tags field, you will only receive push events when tags are modified on a device:
subscription {
device(id: $id) {
id
tags
}
}
Adding position would fire events when either the tags change OR a position is sent from the device:
subscription {
device(id: $id) {
id
tags
lastPosition {
position {
llaDec { lat lon alt }
}
timestamp
}
}
}
device(
id: ID!
): Device!
Arguments
device.id ● ID! non-null scalar common
Type
Device object devices
Contains information about a Device in the system
Code Samples
- JavaScript
- Python
- Go
const subscription = `
subscription DeviceSubscription($id: ID!) {
device(id: $id) {
id
label
tags {
key
value
}
lastPosition {
position {
llaDec {
lat
lon
alt
}
}
timestamp
}
}
}
`;
const variables = {
"id": "your-device-id"
};
// WebSocket subscription
const ws = new WebSocket('wss://graphql.pointonenav.com/subscriptions');
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'connection_init',
payload: {
Authorization: 'Bearer YOUR_TOKEN'
}
}));
ws.send(JSON.stringify({
id: '1',
type: 'start',
payload: {
query: subscription,
variables: variables
}
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data);
};
import requests
import json
import websocket
import threading
subscription = """
subscription DeviceSubscription($id: ID!) {
device(id: $id) {
id
label
tags {
key
value
}
lastPosition {
position {
llaDec {
lat
lon
alt
}
}
timestamp
}
}
}
"""
variables = {
"id": "your-device-id"
}
def on_message(ws, message):
data = json.loads(message)
print(json.dumps(data, indent=2))
def on_open(ws):
# Initialize connection
ws.send(json.dumps({
'type': 'connection_init',
'payload': {
'Authorization': 'Bearer YOUR_TOKEN'
}
}))
# Start subscription
ws.send(json.dumps({
'id': '1',
'type': 'start',
'payload': {
'query': subscription,
'variables': variables
}
}))
ws = websocket.WebSocketApp('wss://graphql.pointonenav.com/subscriptions',
on_message=on_message,
on_open=on_open)
ws.run_forever()
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"github.com/gorilla/websocket"
)
type GraphQLRequest struct {
Query string `json:"query"`
Variables interface{} `json:"variables"`
}
type WSMessage struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
Payload interface{} `json:"payload,omitempty"`
}
func main() {
subscription := `
subscription DeviceSubscription($id: ID!) {
device(id: $id) {
id
label
tags {
key
value
}
lastPosition {
position {
llaDec {
lat
lon
alt
}
}
timestamp
}
}
}`
variables := map[string]interface{}{
"id": "your-device-id",
}
u, _ := url.Parse("wss://graphql.pointonenav.com/subscriptions")
c, _, _ := websocket.DefaultDialer.Dial(u.String(), nil)
defer c.Close()
// Initialize connection
initMsg := WSMessage{
Type: "connection_init",
Payload: map[string]string{
"Authorization": "Bearer YOUR_TOKEN",
},
}
c.WriteJSON(initMsg)
// Start subscription
startMsg := WSMessage{
Type: "start",
ID: "1",
Payload: GraphQLRequest{
Query: subscription,
Variables: variables,
},
}
c.WriteJSON(startMsg)
// Read messages
for {
var msg map[string]interface{}
err := c.ReadJSON(&msg)
if err != nil {
break
}
fmt.Printf("%+v\n", msg)
}
}