Gbox 4.20
Grow box automation and monitoring - <a href='https://sites.google.com/site/growboxguy/'>https://sites.google.com/site/growboxguy/</a>
 
Loading...
Searching...
No Matches
ELClientMqtt.h
Go to the documentation of this file.
1
7// Copyright (c) 2016 by B. Runnels and T. von Eicken
8
9#ifndef _EL_CLIENT_MQTT_H_
10#define _EL_CLIENT_MQTT_H_
11
12#include <stdint.h>
13#include "FP.h"
14#include "ELClient.h"
15
16// Class to send and receive MQTT messages. This class should be used with a singleton object
17// because the esp-link implementation currently only supports a single MQTT server, so there is
18// no value in instantiating multiple ELClientMqtt objects (although it's possible).
19// All the server settings are made in esp-link and esp-link takes care to automatically
20// reconnect and retry if the connection is lost. This means that on the arduino side the only
21// code that is necessary is to send and receive messsages.
23 public:
24 // Initialize with an ELClient object
26
27 // setup transmits the set of callbacks to esp-link. It assumes that the desired callbacks
28 // have previously been attached using something like mqtt->connectedCb.attach(myCallbackFun).
29 // After setup is called either the connectedCb or the disconnectedCb is invoked to provide
30 // information about the initial connection status.
31 void setup(void);
32
33 // callbacks that can be attached prior to calling setup
39 // subscribe to a topic, the default qos is 0. When messages are recevied for the topic the
40 // data callback is invoked.
41 void subscribe(const char* topic, uint8_t qos=0);
42 void subscribe(const __FlashStringHelper* topic, uint8_t qos=0);
43
44 // publish a message to a topic
45 void publish(const char* topic, const uint8_t* data,
46 const uint16_t len, uint8_t qos=0, uint8_t retain=0);
47 void publish(const char* topic, const char* data,
48 uint8_t qos=0, uint8_t retain=0);
49 void publish(const __FlashStringHelper* topic, const __FlashStringHelper* data,
50 const uint16_t len, uint8_t qos=0, uint8_t retain=0);
51 void publish(const char* topic, const __FlashStringHelper* data,
52 const uint16_t len, uint8_t qos=0, uint8_t retain=0);
53 void publish(const __FlashStringHelper* topic, const uint8_t* data,
54 const uint16_t len, uint8_t qos=0, uint8_t retain=0);
55
56 // set a last-will topic & message
57 void lwt(const char* topic, const char* message, uint8_t qos=0, uint8_t retain=0);
58 void lwt(const __FlashStringHelper* topic, const __FlashStringHelper* message,
59 uint8_t qos=0, uint8_t retain=0);
60
61 private:
62 ELClient* _elc;
63};
64
65#endif // _EL_CLIENT_MQTT_H_
Definitions for ELClient.
Core Utility - Templated Function Pointer Class.
FP< void, void * > publishedCb
FP< void, void * > disconnectedCb
void lwt(const char *topic, const char *message, uint8_t qos=0, uint8_t retain=0)
Set MQTT last will.
void publish(const char *topic, const uint8_t *data, const uint16_t len, uint8_t qos=0, uint8_t retain=0)
Subscribe to MQTT topic.
FP< void, void * > connectedCb
void subscribe(const char *topic, uint8_t qos=0)
Subscribe to MQTT topic.
void setup(void)
Setup mqtt.
FP< void, void * > dataCb
API abstraction for a Function Pointers.
Definition FP.h:136