Skip to content

Commit

Permalink
Add Marcel.SendMessage() function
Browse files Browse the repository at this point in the history
  • Loading branch information
destroyedlolo committed Feb 1, 2016
1 parent 2a9fb92 commit 05c313b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/).
2 changes: 1 addition & 1 deletion src/Alerting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions src/Alerting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions src/Lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -132,6 +145,7 @@ static int lmVersion(lua_State *L){
}

static const struct luaL_reg MarcelLib [] = {
{"SendMessage", lmSendMsg},
{"RiseAlert", lmRiseAlert},
{"ClearAlert", lmClearAlert},
{"MQTTPublish", lmPublish},
Expand Down

0 comments on commit 05c313b

Please sign in to comment.