Register a Javascript crontab callback

I am trying to register a Javascript crontab callback as in the following:

ffi('void mgos_crontab_register_handler(char*, void (*)(char*, char*, userdata), userdata)')(
	"vlx_cron", function(foo,bar,baz){
		print("vlx_cron cb", JSON.stringify([foo,bar,baz]));
	}, null);

When the crontab fires the log says no handler is found:

... Cron job 1 is firing: "vlx_cron" ... 
... No actual handler for the cron action "vlx_cron"  

What is wrong and how looks a working ffi call to mgos_crontab_register_handler?

You have to write some wrappers in C to be able to do that.
The signatures of mgos_crontab_register_handler and mgos_crontab_cb use struct mg_str.

mgos_crontab_cb
mgos_crontab_register_handler

This was something of a PIA for me as well, but thankfully someone in the Gitter chat helped me with the code, so i’m happy to share it with you:

I also added this in the Awesome Mongoose OS list as well under Code Snippets section:

Hi @tripflex,

I was stubling about this today and was wondering if you could give me some more hints were you put the crontab.c, crontab.js and how you register your callbacks in the end?

That would be very helpful.

Thanks a lot!

Please read the docs and ask specific questions