Handels the MQTT connection.
More...
#include <myMQTT.h>
|
| myMQTT (String hostname, const int BrokerIP1, const int BrokerIP2, const int BrokerIP3, const int BrokerIP4, const int BrokerPort) |
| Construct a new my M Q T T object. More...
|
|
void | init (WiFiClient *myClient, void(*pToCallback)(char *, unsigned char *, unsigned int)) |
|
bool | subscribe (const String topic) |
| subsribes to MQTT topic on Server More...
|
|
bool | unsubscribe (const String topic) |
| unsubsribes from MQTT topic on Server More...
|
|
bool | publishMessage (const String topic, const String msg) |
| handles outgoing MQTT messages to Server More...
|
|
bool | loop () |
| This should be called regularly to allow the client to process incoming messages and maintain its connection to the server. More...
|
|
Handels the MQTT connection.
https://pubsubclient.knolleary.net
Definition at line 32 of file myMQTT.h.
◆ myMQTT()
myMQTT::myMQTT |
( |
String |
hostname, |
|
|
const int |
BrokerIP1, |
|
|
const int |
BrokerIP2, |
|
|
const int |
BrokerIP3, |
|
|
const int |
BrokerIP4, |
|
|
const int |
BrokerPort |
|
) |
| |
Construct a new my M Q T T object.
- Parameters
-
hostname | - the client ID to use when connecting to the server |
BrokerIP1 | - broker IP distributed in 4 values (192) |
BrokerIP2 | - broker IP distributed in 4 values (186) |
BrokerIP3 | - broker IP distributed in 4 values (1) |
BrokerIP4 | - broker IP distributed in 4 values (2) |
BrokerPort | - MQTT connection port |
Definition at line 19 of file myMQTT.cpp.
◆ connectToMQTT()
void myMQTT::connectToMQTT |
( |
| ) |
|
|
private |
Connects to the MQTT-server.
If the server isn't already connected a new connection will be established If the connection fails then there will be a 3 Sec dealy.
Definition at line 93 of file myMQTT.cpp.
◆ decodeMQTTstate()
String myMQTT::decodeMQTTstate |
( |
int |
errorcode | ) |
|
|
private |
Decodes the Error Values from MQTT state() and returns a description.
- Parameters
-
errorcode | - errorvalue from client |
- Returns
- String - Errordescription
Definition at line 122 of file myMQTT.cpp.
◆ init()
void myMQTT::init |
( |
WiFiClient * |
myClient, |
|
|
void(*)(char *, unsigned char *, unsigned int) |
pToCallback |
|
) |
| |
- Parameters
-
myClient | - pointer to WiFiClient object |
pToCallback | - pointer to Callback-Function |
Definition at line 33 of file myMQTT.cpp.
◆ loop()
This should be called regularly to allow the client to process incoming messages and maintain its connection to the server.
- Returns
- true - he client is still connected
-
false - the client is no longer connected
Definition at line 101 of file myMQTT.h.
◆ MQTTConnectionFailed()
void myMQTT::MQTTConnectionFailed |
( |
| ) |
|
|
private |
Writes Error-Message about MQTT connection.
Definition at line 116 of file myMQTT.cpp.
◆ publishMessage()
bool myMQTT::publishMessage |
( |
const String |
topic, |
|
|
const String |
msg |
|
) |
| |
handles outgoing MQTT messages to Server
Beware though that the default packet size supported by the PubSub client is 128 bytes. You can increase this limit by editing the value lof MQTT_MAX_PACKET_SIZE in PubSubClient.h
- Parameters
-
topic | - the topic to publish to (const char[]) |
msg | - the message to publish (const char[]) |
- Returns
- true - publish succed
-
false - publish failes
Definition at line 75 of file myMQTT.cpp.
◆ subscribe()
bool myMQTT::subscribe |
( |
const String |
topic | ) |
|
subsribes to MQTT topic on Server
Check if the client is connected to the server if not call connectToMQTT()
- Parameters
-
topic | - the topic to subscribe to (const char[]) |
- Returns
- true - sending the subscribe succeeded. The request completes asynchronously.
-
false - sending the subscribe failed, either connection lost, or message too large.
Definition at line 41 of file myMQTT.cpp.
◆ unsubscribe()
bool myMQTT::unsubscribe |
( |
const String |
topic | ) |
|
unsubsribes from MQTT topic on Server
Check if the client is connected to the server
- Parameters
-
topic | - the topic to unsubscribe from (const char[]) |
- Returns
- true - sending the unsubscribe succeeded. The request completes asynchronously.
-
false - sending the unsubscribe failed, either connection lost, or message too large.
Definition at line 58 of file myMQTT.cpp.
◆ myMQTTclient
PubSubClient myMQTT::myMQTTclient |
|
private |
instance of PubSubClient
Definition at line 132 of file myMQTT.h.
◆ pBrokerIP
IPAddress myMQTT::pBrokerIP |
|
private |
the IP-address of the server/broker
Definition at line 130 of file myMQTT.h.
◆ pBrokerPort
const int myMQTT::pBrokerPort |
|
private |
port to connect to MQTT
Definition at line 131 of file myMQTT.h.
◆ pHostname
Contains Hostname/Client ID.
Definition at line 129 of file myMQTT.h.
The documentation for this class was generated from the following files: