diff --git a/q/mqtt.q b/q/mqtt.q index 00b996d..5c8e005 100644 --- a/q/mqtt.q +++ b/q/mqtt.q @@ -1,9 +1,12 @@ \d .mqtt -connX :`mqtt 2:(`connX;3); +connX:`mqtt 2:(`connX;3); init :`mqtt 2:(`init;1); pubx :`mqtt 2:(`pub ;4); sub :`mqtt 2:(`sub ;1); unsub:`mqtt 2:(`unsub;1); +isConnected:`mqtt 2:(`isConnected;1); +disconnect :`mqtt 2:(`disconnect;1); + pub:.mqtt.pubx[;;1;0] conn:{[tcpconn;pname;opt]connX[tcpconn;pname](enlist[`]!enlist(::)),opt} diff --git a/src/mqtt.c b/src/mqtt.c index b1ad85d..5b901a3 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -143,6 +143,28 @@ EXP K connX(K tcpconn,K pname, K opt){ return (K)0; } +/* Disconnect from an mqtt client + * timeout = length of time in ms to allow for the client to clean up prior to disconnection +*/ + +EXP K disconnect(K timeout){ + if(!MQTTClient_isConnected(client)) + return krr((S)"No client is currently connected"); + else{ + MQTTClient_disconnect(client,(time_t)timeout->i); + MQTTClient_destroy(&client); + } + return (K)0; +} + +EXP K isConnected(K UNUSED(x)){ + if(!MQTTClient_isConnected(client)) + return kb(0); + else + return kb(1); +} + + /* Publish a message to a specified topic * topic = topic name as a symbol * msg = message content as a string