Skip to content

Internal API Host

Jannes P edited this page May 18, 2018 · 2 revisions

Request

pair

pairs with a peripheral for the first time (or if the pairing was lost)

{
    context: "server",
    message_type: "request", 		
    message_code: "pair",
    data: { code: string }				//the pairing code that is displayed on the peripheral
}

response data:

{
    success: boolean
    id: int //peripheral id of the peripheral that got paired
}

get_available_peripherals

retrieves all available, already paired peripherals that are connected to the server

{
    context: "server",
    message_type: "request", 		
    message_code: "get_available_peripherals",
    data: null					//not used
}

response data:

{
	devices: [
    	{ id: number, name: string },	//id is a unique public identifier
        ...
    ]
}

connect_to_peripheral

connects to the peripheral with the given id

after a positive response came back from the server you are allowed to send 'device' context messages

{
    context: "server",
    message_type: "request", 		
    message_code: "connect_to_peripheral",
    data: { id: number }				//the id of the peripheral
}

response data:

{
	success: boolean
        id: int
}

disconnect_from_peripheral

disconnects from the currently connected peripheral without cutting the WebSocket connection

{
    context: "server",
    message_type: "request", 		
    message_code: "disconnect_from_peripheral",
    data: null
}

response data:

{
	success: boolean
}

unpair

removes the peripheral from the list of paired peripherals

{
    context: "server",
    message_type: "request", 		
    message_code: "pair",
    data: { id: number }				//the id of the peripheral you want to remove
}

response data:

{
	success: boolean
}