Hello! I want to make the RSSI value sensor devices connected to the Wi-Fi router. My router is Keenetic giga 3.
Technical support Keenetic suggest to use the following address: http://192.168.1.1/rci/show/associations to parsiong RSSI value from connected devices.
The problem is that the authorization is through js script.
I tried use this script in the node.js and it works, but i have no idea how make a sensor in HA.
It have JSON and js
Blockquote
{
“name”: “rci-auth”,
“version”: “0.0.1”,
“description”: “”,
“main”: “rci-auth.js”,
“scripts”: {
“run”: “node rci-auth.js”
},
“author”: “eralde”,
“license”: “WTFPL”,
“dependencies”: {
“axios”: “^0.18.0”,
“js-md5”: “^0.7.3”,
“jssha”: “^2.3.1”
}
}
Summary
const axios = require(‘axios’);
const md5 = require(‘js-md5’);
const jsSHA = require(‘jssha’);
const KEENETIC_IP = ‘192.168.0.2’;
const LOGIN = ‘';
const PASSWORD = '*’;
const AUTH_URL = http://${KEENETIC_IP}/auth
;
const RCI_URL_PREFIX = http://${KEENETIC_IP}/rci
;
const getSha256Hash = (text) => {
const shaObj = new jsSHA(‘SHA-256’, ‘TEXT’);
shaObj.update(text);
return shaObj.getHash(‘HEX’);
};
const getMd5HashArg = (login, realm, password) => ${login}:${realm}:${password}
;
const getCryptedPass = (login, password, token, realm) => {
const md5Arg = getMd5HashArg(login, realm, password);
const md5Hash = md5(md5Arg);
return getSha256Hash(token + md5Hash);
}
const authPromise = new Promise((resolve, reject) => {
axios.get(AUTH_URL)
.then((res) => {
console.log(‘NO PASSWORD’);
resolve();
})
.catch((err) => {
const headers = err.response.headers;
const token = headers[‘x-ndm-challenge’];
const realm = headers[‘x-ndm-realm’];
// DEBUG OUTPUT
console.log(`TOKEN=<${token}>`);
console.log(`REALM=<${realm}>`);
console.log(headers);
const cookies = headers['set-cookie'][0].split(';');
// DEBUG OUTPUT
console.log(`COOKIES=<${cookies}`);
axios({
method: 'post',
url: AUTH_URL,
headers: {
Cookie: cookies[0]
},
data: {
login: LOGIN,
password: getCryptedPass(LOGIN, PASSWORD, token, realm)
}
})
.then((res) => {
console.log('AUTHORIZED!');
resolve(cookies[0]);
})
.catch((err) => {
console.log('ERROR', err);
reject();
});
});
});
authPromise.then((cookie) => {
let headers = {};
if (cookie) {
headers.Cookie = cookie;
}
axios({
method: ‘get’,
url: ${RCI_URL_PREFIX}/show/associations
,
headers: headers
})
.then(requestObj => {
console.log(requestObj.data);
});
})
And result from node.js
P.S.: sorry for my english…