Hi.
I'm hoping for some help to requesting some data from a DEVICE. Normally I can do it with CURL(), but I can only access to the device by using websocket:
Authentication is done by JSON data - an it's the same with requesting data.
I've got some information:
websocket: wss://658608ab.in.larnitech.com:8443/api
Authorization: {"request": "authorize", "key": "999999999999"}
And then I have examples of different requests, e.g.
Get list of devices: {"request":"getDevices"}
I've looked around the web and came up with the code below, but I still don't have my request included. And I think there are repetitions in the header, but probably also something that doesn't fit.
I’m stuck.
I'm hoping for some help to requesting some data from a DEVICE. Normally I can do it with CURL(), but I can only access to the device by using websocket:
Authentication is done by JSON data - an it's the same with requesting data.
I've got some information:
websocket: wss://658608ab.in.larnitech.com:8443/api
Authorization: {"request": "authorize", "key": "999999999999"}
And then I have examples of different requests, e.g.
Get list of devices: {"request":"getDevices"}
I've looked around the web and came up with the code below, but I still don't have my request included. And I think there are repetitions in the header, but probably also something that doesn't fit.
I’m stuck.
PHP:
$key = '99999999999';
$host = 'wss://658608ab.in.larnitech.com:8443/api';
$port = -1; //Use -1 when you don't use PORT
$local = 'https://mydomaene.dk';
$login = [
'request' => 'authorize',
'key' => $key
];
$login=json_encode($login);
$data = [
'request' => 'getDevices'
];
$data=json_encode($data);
$head = "GET / HTTP/1.1"."\r\n".
"Upgrade: WebSocket"."\r\n".
"Connection: Upgrade"."\r\n".
"Origin: $local"."\r\n".
"Host: $host"."\r\n".
"Sec-WebSocket-Version: 13"."\r\n".
"Sec-WebSocket-Key: $key"."\r\n".
"Content-Length: ".strlen($login)."\r\n"."\r\n";
$sock = fsockopen($host, $port, $errno, $errstr, 30);