first commit
This commit is contained in:
59
server/comman/mqqthttp.js
Normal file
59
server/comman/mqqthttp.js
Normal file
@ -0,0 +1,59 @@
|
||||
const axios=require("./mqttaxios");
|
||||
|
||||
async function queryDeviceStatus(deviceId) {
|
||||
try {
|
||||
const response = await axios.get('/api/v4/clients/', {
|
||||
params: {
|
||||
clientid: deviceId
|
||||
}
|
||||
});
|
||||
//cl console.log(response)
|
||||
const clients = response.data.data;
|
||||
if (clients.length > 0) {
|
||||
|
||||
console.log(clients[0].connected);
|
||||
console.log("on working");
|
||||
return clients[0].connected;
|
||||
} else {
|
||||
|
||||
console.log("not on working");
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function queryalldeviceonline() {
|
||||
const listofcliensidonline=new Array();
|
||||
try {
|
||||
const response = await axios.get('/api/v4/clients/');
|
||||
//cl console.log(response)
|
||||
const clients = response.data.data;
|
||||
|
||||
for (item in clients)
|
||||
{
|
||||
// console.log(clients[item])
|
||||
listofcliensidonline.push(clients[item].clientid);
|
||||
}
|
||||
|
||||
console.log(listofcliensidonline)
|
||||
return listofcliensidonline;
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return listofcliensidonline;
|
||||
}
|
||||
}
|
||||
|
||||
function queryDeviceStatus(clientid,list)
|
||||
{
|
||||
return list.includes(clientid);
|
||||
|
||||
|
||||
}
|
||||
|
||||
exports.queryalldeviceonline=queryalldeviceonline;
|
||||
//queryalldeviceonline()
|
Reference in New Issue
Block a user