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 using graphql-transport-ws protocol
const ws = new WebSocket('wss://graphql.pointonenav.com/subscriptions', 'graphql-transport-ws');
ws.onopen = () => {
// Initialize connection
ws.send(JSON.stringify({
type: 'connection_init',
payload: {
Authorization: 'Bearer YOUR_TOKEN'
}
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
// Wait for connection acknowledgement before subscribing
if (data.type === 'connection_ack') {
ws.send(JSON.stringify({
id: '1',
type: 'subscribe',
payload: {
query: subscription,
variables: variables
}
}));
return;
}
console.log(data);
};
import requests
import json
import websocket
import threading
subscribed = False
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):
global subscribed
data = json.loads(message)
print(json.dumps(data, indent=2))
# Subscribe after receiving connection acknowledgement
if not subscribed and data.get('type') == 'connection_ack':
ws.send(json.dumps({
'id': '1',
'type': 'subscribe',
'payload': {
'query': subscription,
'variables': variables
}
}))
subscribed = True
def on_open(ws):
# Initialize connection
ws.send(json.dumps({
'type': 'connection_init',
'payload': {
'Authorization': 'Bearer YOUR_TOKEN'
}
}))
ws = websocket.WebSocketApp('wss://graphql.pointonenav.com/subscriptions',
subprotocols=["graphql-transport-ws"],
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")
dialer := websocket.Dialer{
Subprotocols: []string{"graphql-transport-ws"},
}
c, _, _ := dialer.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)
// Prepare subscription message (sent after connection acknowledgement)
startMsg := WSMessage{
Type: "subscribe",
ID: "1",
Payload: GraphQLRequest{
Query: subscription,
Variables: variables,
},
}
// Read messages, wait for connection acknowledgement then subscribe
ackReceived := false
for {
var msg map[string]interface{}
err := c.ReadJSON(&msg)
if err != nil {
break
}
if !ackReceived {
if msgType, ok := msg["type"].(string); ok && msgType == "connection_ack" {
ackReceived = true
// Send subscription using graphql-transport-ws protocol
c.WriteJSON(startMsg)
}
}
fmt.Printf("%+v\n", msg)
}
}