So I’ve been playing with this with fake data for the last hour since I saw your post and I think I can get you up and running with this widget. This might be good enough depending on what you want to do with the data, but first, a few caveats:
The widget as it stands was designed for a LoRa partner so it has not really been tested in the context of MQTT devices. This is actually a pretty minor caveat since most of the LoRa stuff boils down to MQTT under the hood.
It doesn’t currently have data history, or a proper tie in with our Triggers system (you can add it to a trigger ‘IF’ statement, but the UI doesn’t know how to handle the 3 values).
Since we don’t have any official multi-value widgets yet for MQTT, the
virtualWrite() statement wasn’t designed for it either. What I’ve got below should work great, but if you use too many decimal places or very large numbers for all 3 values, you could overrun the maximum for sending data and see issues. Probably not a big deal with real-world accelerometer data unless you have crazy precision, and you could always round things in code. A library update that will handle this caveat is coming soon.
With all that said, the format to send this data is pretty straightforward:
Cayenne.virtualWrite(channel, "[x,y,z]", "accel", "type");
so, a real example:
Cayenne.virtualWrite(1, "[2,1,3]", "accel", "g");
You can note that
type is just a text label, so if your data is in meters per second squared or whatever other unit, you can label however you’d like. It’s not involved in any calculation or conversion.
Finally I should note that the
"[2,1,3]" part with the actual data is being passed as a single string to compensate for
virtualWrite() not being ready for multi variables like this as mentioned above. So you’ll have to use string manipulation functions to construct a text string in that format before passing it into the
virtualWrite() statement – you won’t be able to pass it the direct sensor data as int/float variables or anything like that. This will also be resolved when we update the library for multivariable support.