Created
January 4, 2024 17:39
-
-
Save mpolinowski/d7c1c6e28e8760410bd461f0eb1f447b to your computer and use it in GitHub Desktop.
INSTAR WQHD 2k+ Camera CGI Commands / REST API - Get camera state using javascript:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getRequest = { | |
cgiGetCommand: 'getmqttattr', | |
cameraIp: '192.168.2.125', | |
cameraPort: '80', | |
authToken: '7PZv8N63c7wYYRxBw39pnRYNRnbdaBTTaK' | |
} | |
const fetchDataWithAuthHeader = async (getRequest) => { | |
try { | |
const customHeaders = new Headers() | |
customHeaders.append('Authorization', 'Bearer ' + getRequest.authToken) | |
const response = await fetch( | |
'http://' + getRequest.cameraIp + ':' + getRequest.cameraPort + '/' + 'param.cgi?cmd=' + getRequest.cgiGetCommand, | |
{ | |
method: 'GET', | |
headers: customHeaders | |
} | |
) | |
if (!response.ok) { | |
throw new Error(`ERROR :: Request failed with status ${response.status}`) | |
} | |
const textResponse = await response.text() | |
console.log(textResponse) | |
const cleanedTextResponse = textResponse | |
.replace('cmd="getmqttattr";', '{"') | |
.replace('response="200";', '}') | |
.replace(/=/g, '":') | |
.replace(/";/g, '","') | |
.replace(/\s/g, '') | |
.replace(/","}/g, '"}'); | |
const jsonData = JSON.parse(cleanedTextResponse) | |
console.log(`Enable Broker: ${jsonData.mq_enable},\nWebsocket Support: ${jsonData.mq_broker_ws},\nWebsocket Port: ${jsonData.mq_broker_ws_port},\nWebsocket Port SSL: ${jsonData.mq_broker_ws_portssl},\nTLS Version: ${jsonData.mq_broker_min_tls},\nExternal Broker IP: ${jsonData.mq_host},\nBroker Port: ${jsonData.mq_port},\nBroker Port SSL: ${jsonData.mq_portssl},\nEnable Encryption: ${jsonData.mq_ssl},\nEnable Authentication: ${jsonData.mq_auth},\nUsername: ${jsonData.mq_user},\nTLS Certificate Verification: ${jsonData.mq_insecure},\nMQTT Prefix: ${jsonData.mq_prefix},\nMQTT LWT: ${jsonData.mq_lwt},\nMQTT LWT on: ${jsonData.mq_lwmon},\nMQTT LWT off: ${jsonData.mq_lwmoff},\nMQTT Client ID: ${jsonData.mq_clientid},\nMQTT QoS Level: ${jsonData.mq_qos}`) | |
} | |
catch (error) { | |
console.log('ERROR :: ', error.message) | |
} | |
} | |
fetchDataWithAuthHeader(getRequest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get Auth Token
Run Script