diff --git a/README.md b/README.md index 6b248f5..a3d3374 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,12 @@ Have a look on provided file which contains comprehensive explanation of known d #Lua custom methods :# Following methods are exposed to Lua code through **Marcel** object : +* **Marcel.MQTTPublish(** topic, value **)** : Publish a value to MQTT broker + * **Marcel.RiseAlert(** topic**,** message **)** : Tells Marcel about an alert condition * **Marcel.ClearAlert(** topic **)** : Clear an alert condition -* **Marcel.MQTTPublish(** topic, value **)** : Publish a value to MQTT broker +* **Marcel.SendMessage(** title **,** Text **)** : send a message using AlertCommand facility. Generally used to send a mail (which is not considered as an alert) * **Marcel.Hostname()** : As the name said, host's name * **Marcel.ClientID()** : Configured MQTT client id @@ -54,5 +56,5 @@ Marcel knows the following options : Have a look on provided configuration file to guess the syntax used (I'm busy, a full documentation will come later). #Side note# -The name is a tribute to my late rabbit that passed away some days before I did started this project : he stayed at home to keep our house. RIP. +The name is a tribute to my late rabbit that passed away some days before I did started this project : he stayed at home as keeper. RIP. > Written with [StackEdit](https://stackedit.io/). diff --git a/src/Alerting.c b/src/Alerting.c index 52933ab..91ccd39 100644 --- a/src/Alerting.c +++ b/src/Alerting.c @@ -42,7 +42,7 @@ static void sendSMS( const char *msg ){ } } -static void AlertCmd( const char *id, const char *msg ){ +void AlertCmd( const char *id, const char *msg ){ const char *p = cfg.AlertCmd; size_t nbre=0; /* # of %t% in the string */ diff --git a/src/Alerting.h b/src/Alerting.h index ce17291..03b3aa7 100644 --- a/src/Alerting.h +++ b/src/Alerting.h @@ -23,6 +23,7 @@ extern struct DList alerts; extern void init_alerting(void); extern void RiseAlert(const char *id, const char *msg); extern void AlertIsOver(const char *id); +extern void AlertCmd( const char *id, const char *msg ); extern void rcv_alert(const char *id, const char *msg); diff --git a/src/Lua.c b/src/Lua.c index c45147f..51a6842 100644 --- a/src/Lua.c +++ b/src/Lua.c @@ -72,6 +72,19 @@ void execUserFuncEvery( struct _Every *ctx ){ pthread_mutex_unlock( &onefunc ); } +static int lmSendMsg(lua_State *L){ + if(lua_gettop(L) != 2){ + fputs("*E* In your Lua code, SendMessage() requires 2 arguments : title and message\n", stderr); + return 0; + } + + const char *topic = luaL_checkstring(L, 1); + const char *msg = luaL_checkstring(L, 2); + AlertCmd( topic, msg ); + + return 0; +} + static int lmRiseAlert(lua_State *L){ if(lua_gettop(L) != 2){ fputs("*E* In your Lua code, RiseAlert() requires 2 arguments : topic, message\n", stderr); @@ -132,6 +145,7 @@ static int lmVersion(lua_State *L){ } static const struct luaL_reg MarcelLib [] = { + {"SendMessage", lmSendMsg}, {"RiseAlert", lmRiseAlert}, {"ClearAlert", lmClearAlert}, {"MQTTPublish", lmPublish},