Looking for advice on communicating with local Mesh nodes

I am working on building a mesh network comprised of an Argon gateway, and one or more Xenon repeater nodes. The basic functionality will be that the Xenons will poll their input ports (triggers) and communicate their state to the mesh. Based on their state, one or more different Xenon will set a specified port to a specified state.

As an example, think of several Xenons (A, B, C, and D), each with a pushbutton and a relay. Pressing the pushbutton on A might turn B’s relay on, and pressing the pushbutton on C might turn B and D’s relay off. I will have a locally served web-app that will be used to visually connect my virtual triggers and relays, and then send that design to the Argon.

For the communication between Xenons, I don’t want to use Particle.Publish and Particle.Subscribe for a couple of reasons:
I don’t want to suffer a delay between publishing a trigger event and receiving a response (I need faster than 1 per second, or bursts of 4 with a 4 second delay).
I may want to subscribe to more than 4 events.
I really don’t see the need to go through the cloud.

But using Mesh.Publish and Mesh.Subscribe poses additional questions:
When I use Mesh.Publish, how can I ensure only a specific Xenon acts? Do I have to put a string in the data with my event data and parse on subscribe?

A bigger question I have is how do I get my “design” data from my local web-app to my Argon?
If I register a function in the cloud and use a Webhook to call it, it only allows 63 characters in the String argument. I need to send more data than would fit in 63 characters for my “design”, and ideally I would like to send a JSON string so it can be more easily parsed by the Argon.
I thought about creating a webhook which points to my locally served site, but that would necessitate that the Argon trigger the webhook to update its design code, but I want the design code pushed to the Argon when changes are made.
I have also considered sending data to the Argon via WebSockets, but I am having difficulty finding which websockets library to include, and how I could configure it to receive emitted messages of a specific name.

I understand that I have asked a lot, but any advice on how to accomplish these would be much appreciated.

Steve

Mesh devices run 0.8.0, so the function call size limit is 622 bytes not 63 bytes, so you have a lot more room there.

Another technique is to use a multi-part publish and subscribe. Publish is limited to 622 bytes, but you can send the data in multiple chunks. The JsonParserGeneratorRK library is designed to handle JSON split into chunks like that efficiently.

Mesh.publish and Mesh.subscribe will probably work for your use. It still takes and event and data, and the event is a prefix, just like the Particle.publish and Particle.subscribe. There are two common techniques:

  • Targeting a device by making its event name be unique to that device.
  • Tagging the originator by using a common prefix but including the sender information as a suffix. Thus each device receives all of the events but can differentiate actions by who sent the event name suffix (without having to do device ID mapping).
1 Like

Great, thank you for the suggestions and quick reply. I will take a look at your JsonParserGenerator library.

Just to clarify, the Argon Reference docs state 63 characters limit for the String argument of a function call. Is this incorrect?

A cloud function is set up to take one argument of the String datatype. This argument length is limited to a max of 63 characters.

Also, the Argon Reference states a maximum of 255 bytes for optional data on Mesh.Publish. Is this also incorrect?

optional data (up to 255 bytes)

It really is 622 bytes. The problem is that since 0.8.0 is not a final release the change notes for 0.8.0 have not been merged into the docs yet.

But since mesh devices run 0.8.0-rc.25 it makes things confusing.

1 Like

OK, what I want is to push a relatively large JSON object or string to the Argon. If I use a webhook, even if I use multipart GET request from what I am understanding, I would still need to have the Argon trigger the webhook periodically to retrieve and then parse the data. I would rather have a way for my my server to push data to the Argon. What would be a good way to accomplish that?

What are the capabilities of the server? Can you do a particle.publish periodically from the server?

It is my own, so I could conceivably try… What would be required to send a particle.publish? Would I just need to install the Particle API? Or looking at the docs, if I simply need to add the Particle API Js via script in my html, I could try that.

Even still, how would I send a publish event longer than 622 bytes?

You use the Particle REST API from your preferred language. The Particle API JS is the one I’d use, because the library is full-featured and well-maintained (and I’m used to node.js).

In any case, the chunked response isn’t all that magical - you literally just break a large response into chunks and send them sequentially in the same way webhooks do, of the form eventname/1, eventname/2, … so you can send any response size you want. Though JsonParserGeneratorRK buffers in RAM, so really 40K or so is probably a practical limit.

2 Likes

Thank you again. As a novice, I rally appreciate the advice and support.

Another question: I have created a client under the Authentication tab in the Web Console. Using the REST API, how do I get a token using the client id and secret that was generated? I don’t see any examples under the OAuth Clients section of the Cloud API reference docs.