Get Specific Device Information

Get Specific Device Information

There is a really simple solution to use Mobile-detect here: https://github.com/serbanghita/Mobile-Detect/

Enjoy!

Get device information (such as product, model) from adb command

The correct way to do it would be:

adb -s 123abc12 shell getprop

Which will give you a list of all available properties and their values. Once you know which property you want, you can give the name as an argument to getprop to access its value directly, like this:

adb -s 123abc12 shell getprop ro.product.model

The details in adb devices -l consist of the following three properties: ro.product.name, ro.product.model and ro.product.device.

Note that ADB shell ends lines with \r\n, which depending on your platform might or might not make it more difficult to access the exact value (e.g. instead of Nexus 7 you might get Nexus 7\r).

How to retrieve data for specific ewelink device using node.js?

I have tested your code and made some changes to make it work.

Sample Image

It is not necessary to reconnect within the loop to get the device information.

Another problem is that you must use element.deviceid instead of element.id

var http = require("http");
const ewelink = require("ewelink-api");
const url = require("url");
var devices;
var connection;
var newConnection;
var auth;
var onlineDevice;
//var device;

console.log("====================");
console.log(Date());
console.log("====================");

//create a server object:
http
.createServer(
function (req, res) {
res.write(timestampLC() + " - Ewelink - " + Date() + "\n");
const queryObject = url.parse(req.url, true).query;
console.log(timestampLC() + " - Executing function inside Server...");
eweRetrieve(res, queryObject);
} // function in createserver
) // createserver
.listen(8080); //the server object listens on port 8080

function printOfflineDevice(res, device) {
res.write(timestampLC() + " - Name: " + device.name + "\n");
res.write(timestampLC() + " - Type: " + device.type + "\n");
res.write(timestampLC() + " - Brand name:" + device.brandName + "\n");
res.write(timestampLC() + " - Model: " + device.productModel + "\n");
res.write(timestampLC() + " - Url: " + device.deviceUrl + "\n");
}

////////////////////

async function eweRetrieve(res, queryObject) {
res.write(timestampLC() + " - Attempting connection of user ");
console.log(timestampLC() + " - Attempting user connection...");
console.log(queryObject.bypass)
if (queryObject.bypass) {
res.write("tugsbayar.g@gmail.com'\n");
try {
res.write(timestampLC() + " - Trying...\n");
connection = new ewelink({
email: "tugsbayar.g@gmail.com",
password: "mdk06tgs6",
region: "as"
});
res.write(timestampLC() + " - Ewelink - user DEBUG connected\n");
} catch {
res.write(
timestampLC() + " - Fail 001 - no connection available for DEBUG user\n"
);
return 1;
}
} else {
console.log(queryObject.user)
res.write("'" + queryObject.user + "'\n");
try {
res.write(timestampLC() + " - Trying...\n");
connection = new ewelink({
email: queryObject.user,
password: queryObject.pass
//region: "it"
});

res.write(
timestampLC() +
" - >>> Initial login SUCCESS: user " +
connection.email +
" connected\n"
);
res.write(timestampLC() + " - ID: " + connection.APP_ID + "\n");
res.write(timestampLC() + " - SEC: " + connection.APP_SECRET + "\n");
//console.log(timestampLC() + "*** connection data ****", connection);
} catch {
res.write(
timestampLC() + " - Fail 002 - no connecion available for real user\n"
);
return 2;
}

//credentialsLogin(res, connection);
try {
console.log(timestampLC() +" - Credentials...\n");
res.write(timestampLC() +" - Credentials...");
auth = await connection.getCredentials();
res.write("SUCCESS! <<<<<<<<<<\n");
console.log("access token: ", auth.at);
console.log("api key: ", auth.user.apikey);
console.log("region: ", auth.region);
} catch {
res.write(timestampLC() + "***ERROR*** - cannot login\n");
console.log(timestampLC() + "***ERROR*** - cannot login\n");
}
}

//listAllDevices(res, connection);
/* get all devices */
try {
res.write(timestampLC() + " - Connected. Reading devices list...\n");
devices = await connection.getDevices();
} catch {
res.write(timestampLC() + " - Fail 003 - no devices\n");
console.log(timestampLC() + " - No devices found.");
return 3;
}
//console.log("=== Begin devices list ===");
//console.log(devices);
//console.log("=== End devices list ===");

res.write(timestampLC() + " - Found n." + devices.length + " devices\n\n");
console.log(timestampLC() + " - Found n. " + devices.length + " devices\n\n");
console.log(timestampLC() + " - Reading info...");

/* get specific device info */
for (var x = 0; x < devices.length; x++) {
res.write(timestampLC() + " - Device n. " + (x + 1) + "\n");
var element = devices[x];
res.write(timestampLC() + " - Id: " + element.deviceid + "\n");
res.write(timestampLC() + " - Online: " + element.online + "\n");
console.log(element);
if (element.online) {
res.write(timestampLC() + " - Device '" +
element.name +
"' is online, fetching data...\n" );
// try {
// console.log("CREDENTIALS:\n", auth.at);
// console.log(auth.region);
// newConnection = new ewelink({
// at: auth.at,
// region: auth.region
// });
// console.log(timestampLC() + ">>>>>>>>>>>New connection ok! >>>>>>>>>>>>> Scarico dati online di", element.name , "\n")
//
// } catch {
// res.write(timestampLC() + " - *****ERROR: cannot read*****\n");
// console.log(
// timestampLC() +
// "!!!!!!!!!!!!! NON RIUSCITO per " +
// element.name +
// " !!!!!!!!!!!!!!!"
// );
// }

try {
console.log("provo.");
/*var deviceConnection = new ewelink({
at: auth.at,
region: auth.region
}); */
console.log(element.id)
onlineDevice = await connection.getDevice(element.deviceid);
res.write(timestampLC() + " - DATA:\n");
console.log(timestampLC() + "***********************\n", onlineDevice , "<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
} catch {
res.write(timestampLC() + " - ***** ONLINE ERROR: cannot retrieve *****\n");
console.log(
timestampLC() +
"!!!!!!!!!!!!! Impossibile scaricare dati per " +
element.name +
" !!!!!!!!!!!!!!!"
);
}

//printDevice(res, device);
} else {
printOfflineDevice(res, element);
}
res.write(timestampLC() + " - ------------\n\n");
}

/* toggle device */
//await connection.toggleDevice('1000aea4dd');
res.end(); //end the response
}

eweRetrieve().catch(function () {
console.log(timestampLC() + " - retrieve failed");
});

function timestampLC() {
let d = new Date();
return d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}

Get the latest events of a specific type from a specific device

Answer from the support-team:

currently there is no way to revert the order of events. Besides
dateFrom and dateTo you can also use creationFrom and creationTo. This
will take the creationTime (server side timestamp when event was
created) instead of the time (that is send within the event) But the
order will still be oldest -> newest.

Best approach currently would be to use a good estimated time range
(so you don't end up with 0 events in the response) where the
dateTo/creationTo is in the future. If you add to the query params
withTotalPages=true the result will give you the total pages in the
statistics part.

Knowing the total pages you can you can do the query again but with
currentPage=XX instead of withTotalPages=true and take the last
element.

We have this functionality on measurements and audits where you can
add the parameter revert=true. I will add an improvement that we
extend this to the other APIs but at the moment you are limited to the
workaround.

Get parent information of a USB device C++

CM_Locate_DevNode opens a device handle given a device ID;

CM_Get_Parent finds the parent device;

CM_Get_Device_ID_Size and CM_Get_Device_ID take the device handle and return the device ID.

Sample:

#include <Windows.h>
#include <setupapi.h>
#include <cfgmgr32.h>
#include <tchar.h>
#include <stdio.h>
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))

#pragma comment (lib, "setupapi.lib")

int main()
{
HDEVINFO hDevInfo;
GUID guid;
BYTE buffer[1024];
DWORD dwRequiredSize;
DEVINST devInstParent;
SP_DEVICE_INTERFACE_DATA devInterfaceData;
SP_DEVINFO_DATA devInfoData;
PSP_DEVICE_INTERFACE_DETAIL_DATA pDevDetail;
CONFIGRET status;
TCHAR szDeviceInstanceID[MAX_DEVICE_ID_LEN];
BOOL bSuccess;

guid = GUID_DEVINTERFACE_VOLUME;
hDevInfo = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE) {
return 1;
}

for (DWORD dwIndex = 0;; dwIndex++)
{
ZeroMemory(&devInterfaceData, sizeof(devInterfaceData));
devInterfaceData.cbSize = sizeof(devInterfaceData);

if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &guid, dwIndex, &devInterfaceData)) {
DWORD dwErrorCode = GetLastError();
if (dwErrorCode == ERROR_NO_MORE_ITEMS)
break;
else
return 1;
}

ZeroMemory(&devInfoData, sizeof(devInfoData));
devInfoData.cbSize = sizeof(devInfoData);
pDevDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buffer;
pDevDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

// Get device interface detail data to get Device Instance from
// SP_DEVINFO_DATA and Device Path from SP_DEVICE_INTERFACE_DETAIL_DATA
bSuccess = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInterfaceData,
pDevDetail,// SP_DEVICE_INTERFACE_DETAIL_DATA
sizeof(buffer), &dwRequiredSize, &devInfoData); // SP_DEVINFO_DATA

status = CM_Get_Parent(&devInstParent, devInfoData.DevInst, 0);
if (status == CR_SUCCESS)
{
status = CM_Get_Device_ID(devInstParent, szDeviceInstanceID, ARRAY_SIZE(szDeviceInstanceID), 0);
if (status == CR_SUCCESS)
_tprintf(TEXT(" %s\n"), szDeviceInstanceID);
}
else
{
continue;
}
}

return 0;
}

Debug result:

1

2



Related Topics



Leave a reply



Submit