The NodeJS thread

I’m trying to talk to my radio in NodeJS via USB serial. At the moment, I’m already hitting a wall with the protobufs (which I have never touched before). Specifically, I’m trying to create the heoll message to tell the radio that I have connected but the protobuf message isn’t created correctly:

[…]

const root = protobuf.loadSync('Meshtastic-protobufs/mesh.proto');
const toRadio = root.lookupType('ToRadio');

[…]

  const message = toRadio.create({
    want_config_id: 12345678
  });
  const buffer = toRadio.encode(message).finish();
  console.log(util.inspect(toRadio.decode(buffer)));

The logged result is:
ToRadio {}

Does anybody have some good examples how to use more complex protobufs in NodeJS like those in Meshtastic?

Oh well, turns out, the parameter names in Node actually differ from the parameter names in the .proto file.

e.g. “want_config_id” in the proto file changes to “wantConfigId” in Node.

Did you get this to work? Very interested in communicating via USB serial using NodeJS.

Yeah, once you got your head wrapped around protobufs within protobufs within protobufs, it’s actually fairly trivial. I’ve been hit with a whole crapload of busy, so I didn’t manage to beautify my project and upload it to Github yet…

1 Like

Thanks for the reply @sgofferj, please push something when you can, curious to take a look, but without the time to start the journey on my own.

@sgofferj are you using the serialport package?
Also, take a look at the official library, it has protobufs decoding,encoding and generation functionality GitHub - meshtastic/meshtastic.js: Javascript library that provides an interface to Meshtastic devices

Jep, serialport. I actually looked at the meshtastic.js but that’s way over my skill level. Plus I have never looked at typescript before.
I’ll try to upload my code today or tomorrow.

1 Like