start work on lora ingest app
All checks were successful
Build Docker containers / Build (push) Successful in 16s
All checks were successful
Build Docker containers / Build (push) Successful in 16s
This commit is contained in:
103
lora/index.js
Normal file
103
lora/index.js
Normal file
@ -0,0 +1,103 @@
|
||||
const { Mesh, Mqtt, Portnums, Telemetry, Config, Channel } = require("@meshtastic/protobufs");
|
||||
const { fromBinary, toBinary, create } = require("@bufbuild/protobuf");
|
||||
const { LoraStream } = require("./LoraStream");
|
||||
const { MeshtasticStream } = require("./MeshtasticStream");
|
||||
|
||||
const net = require('net');
|
||||
|
||||
const client = new net.Socket();
|
||||
const IP = '192.168.10.117';
|
||||
const PORT = 4403;
|
||||
|
||||
function sendHello() {
|
||||
const data = create(Mesh.ToRadioSchema, {
|
||||
payloadVariant: {
|
||||
case: "wantConfigId",
|
||||
value: 1,
|
||||
}
|
||||
});
|
||||
sendToDevice(toBinary(Mesh.ToRadioSchema, data));
|
||||
}
|
||||
|
||||
function sendToDevice(data) {
|
||||
const bufferLength = data.length;
|
||||
const header = new Uint8Array([
|
||||
0x94,
|
||||
0xC3,
|
||||
(bufferLength >> 8) & 0xFF,
|
||||
bufferLength & 0xFF,
|
||||
]);
|
||||
data = new Uint8Array([...header, ...data]);
|
||||
client.write(data);
|
||||
}
|
||||
|
||||
client.connect(PORT, IP, function() {
|
||||
console.log('Connected');
|
||||
sendHello();
|
||||
});
|
||||
|
||||
const meshtasticStream = new MeshtasticStream();
|
||||
client.pipe(new LoraStream()).pipe(meshtasticStream);
|
||||
meshtasticStream.on('data', (data) => {
|
||||
parseMeshtastic(data['$typeName'], data);
|
||||
})
|
||||
|
||||
function parseMeshtastic(typeName, data) {
|
||||
switch(typeName) {
|
||||
case Mesh.MeshPacketSchema.typeName:
|
||||
onMeshPacket(data);
|
||||
break;
|
||||
case Mesh.NodeInfoSchema.typeName:
|
||||
console.log('node info');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function onMeshPacket(envelope) {
|
||||
const payloadVariant = envelope.payloadVariant.case;
|
||||
|
||||
if (payloadVariant === 'encrypted') {
|
||||
// attempt decryption
|
||||
}
|
||||
|
||||
const dataPacket = envelope.payloadVariant.value;
|
||||
const portNum = dataPacket.portnum;
|
||||
|
||||
if (!portNum) {
|
||||
return;
|
||||
}
|
||||
|
||||
let schema = null;
|
||||
switch (portNum) {
|
||||
case Portnums.PortNum.POSITION_APP:
|
||||
schema = Mesh.PositionSchema;
|
||||
break;
|
||||
case Portnums.PortNum.TELEMETRY_APP:
|
||||
schema = Telemetry.TelemetrySchema;
|
||||
break;
|
||||
case Portnums.PortNum.TEXT_MESSAGE_APP:
|
||||
// no schema?
|
||||
break;
|
||||
case Portnums.PortNum.WAYPOINT_APP:
|
||||
schema = Mesh.WaypointSchema;
|
||||
break;
|
||||
case Portnums.PortNum.TRACEROUTE_APP:
|
||||
schema = Mesh.RouteDiscoverySchema;
|
||||
break;
|
||||
case Portnums.PortNum.NODEINFO_APP:
|
||||
schema = Mesh.NodeInfoSchema;
|
||||
break;
|
||||
case Portnums.PortNum.NEIGHBORINFO_APP:
|
||||
schema = Mesh.NeighborInfoSchema;
|
||||
break;
|
||||
case Portnums.PortNum.MAP_REPORT_APP:
|
||||
schema = Mqtt.MapReportSchema;
|
||||
break;
|
||||
}
|
||||
|
||||
if (schema !== null) {
|
||||
console.log(dataPacket);
|
||||
const decodedData = fromBinary(schema, dataPacket.payload);
|
||||
console.log(decodedData);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user