General client libraries for WebSocket and MQTT.
This library expects messages to be received as JSON. Each key in the JSON array will generate an evenet handled by the 'on' method. 'on' methods include on("connect",...) and on("disconnect",...); The 'on' method on('notJSON',...) will handle messages with no or invalid JSON encoding. The 'on' method on("data",...) will overwrite JSON decoding and handle the full message, exept for the message "ping" that will return a message "pong" (for keep alive);
Uses the followng libraries:
WebSocketsClient.h https://github.com/brandenhall/Arduino-Websocket/
ArduinoJson.h https://github.com/bblanchon/ArduinoJson/blob/master/ArduinoJson.h
#include <socclient.h>
SOCCLIENT wsc;
void connect(char * host, int port);
void send(char * key, char * data);
void on(String topic, wscb func); // func = [] (char * data) {};
void loop();
This library connects to a MQTT-broker as a client.
Uses the followng libraries:
PubSubClient.h https://github.com/knolleary/pubsubclient
#include <mqttclient.h>
MQTTCLIENT mqtt;
void begin(char * clientid, char * host, int port, char * user, char * pass);
void on(String topic, mqttcb func); // func = [] (char * data) {};
void onNotFound(mqttnotfoundcb func); // func = [] (char * topic, char * data) {};
void publish(char* topic, String value);
void publish(char* topic, String value, bool retain);
void subscribe(char* topic);
void unsubscribe(char* topic);
void loop();