-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathget_sensor_telemetry.js
More file actions
50 lines (38 loc) · 1.57 KB
/
get_sensor_telemetry.js
File metadata and controls
50 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import TCPConnection from "../src/connection/tcp_connection.js";
import CayenneLpp from "../src/cayenne_lpp.js";
// create connection
const connection = new TCPConnection("10.1.0.75", 5000);
// wait until connected
connection.on("connected", async () => {
// we are now connected
console.log("Connected");
// find contact
// const contact = await connection.findContactByName("Liam's Water Tank");
// const contact = await connection.findContactByPublicKeyPrefix([0xc9, 0xe1, 0x50, 0x58]);
// const contact = await connection.findContactByPublicKeyPrefix(Buffer.from("c9e15058", "hex"));
const contact = await connection.findContactByPublicKeyPrefix(Buffer.from("c9e15058af33781743b222bc98105abe7429cf46f7212f767ff2a7ce1bea5dcb", "hex"));
if(!contact){
console.log("Contact not found");
await connection.close();
return;
}
// get sensor telemetry
console.log("Fetching telemetry...");
const telemetry = await connection.getTelemetry(contact.publicKey);
// disconnect
await connection.close();
// parse telemetry
const parsedTelemetry = CayenneLpp.parse(telemetry.lppSensorData);
// find telemetry on channel 1
const selfVoltageTelemetry = parsedTelemetry.find((item) => item.channel === 1 && item.type === CayenneLpp.LPP_VOLTAGE);
// make sure telemetry found
if(selfVoltageTelemetry == null){
console.log("Telemetry Missing");
return;
}
console.log({
voltage: selfVoltageTelemetry.value,
});
});
// connect to meshcore device
await connection.connect();