Understanding JS Event API

If you are asking a question, please follow this template:

  1. My goal is:
    Be able to send my own events with data sent on Trigger and received by Handler
  2. My actions are:
    I have followed the documentation and have something similar to this set up
let DEVICE_BASE_EVENT = Event.baseNumber("DEV");

if (!Event.regBase(DEVICE_BASE_EVENT, "DEVICE")) {
  die("Failed to register base device event number");
}
let eventStatus = {status: "running"}
Event.trigger(DEVICE_BASE_EVENT, eventStatus);
  1. The result I see is:
    This fails with argument #1 not a ptr

I then changed this to essentially a string and it compiles and runs. However, I am not sure what evData actually is.

let eventStatus = JSON.stringify({status: "running"});
Event.trigger(DEVICE_BASE_EVENT, eventStatus);

Event.on(DEVICE_UPDATE_EVENT, function(ev, evdata, ud) {
  print(ev);
  print(evdata);
  print(ud);
}, null);

Which outputs

[May  6 22:36:57.631] 1145394688 
[May  6 22:36:57.634] <foreign_ptr@3ffde424> 
[May  6 22:36:57.636] null 
  1. My expectation & question is:
    I was assuming this was a basic event bus with events that contained event data being passed to handlers. I can not work out how to leverage this system and send and receive event data.

Can anyone provide an example for me?

I have workarounds for the design I am looking for but it would be ideal to understand how to really use this Event Bus correctly.

Thank you very much, enjoy focusing on business logic rather than plumbing using Mongoose OS.

My knowledge of mJS is limited… my guess is that when you pass a string what you get is a pointer to the string and you should JSON.parse it back to get an object.
If I understand correcty the source code here, the mJS methods are basically wrappers for the C functions, so you have to pass a pointer.