mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-26 14:26:59 +02:00
first poc for power set via mqtt
This commit is contained in:
parent
84cd0c419b
commit
dccd04ab42
5 changed files with 19 additions and 7 deletions
|
@ -12,6 +12,8 @@
|
|||
|
||||
class mqtt {
|
||||
public:
|
||||
PubSubClient *mClient;
|
||||
|
||||
mqtt() {
|
||||
mClient = new PubSubClient(mEspClient);
|
||||
mAddressSet = false;
|
||||
|
@ -35,6 +37,10 @@ class mqtt {
|
|||
snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic);
|
||||
}
|
||||
|
||||
void setCallback(void (*func)(const char* topic, byte* payload, unsigned int length)){
|
||||
mClient->setCallback(func);
|
||||
}
|
||||
|
||||
void sendMsg(const char *topic, const char *msg) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg"));
|
||||
char top[64];
|
||||
|
@ -79,25 +85,25 @@ class mqtt {
|
|||
|
||||
void loop() {
|
||||
//DPRINT(F("m"));
|
||||
//if(!mClient->connected())
|
||||
// reconnect();
|
||||
if(!mClient->connected())
|
||||
reconnect();
|
||||
mClient->loop();
|
||||
}
|
||||
|
||||
private:
|
||||
void reconnect(void) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect"));
|
||||
DPRINTLN(DBG_INFO, F("mqtt.h:reconnect"));
|
||||
if(!mClient->connected()) {
|
||||
if((strlen(mUser) > 0) && (strlen(mPwd) > 0))
|
||||
mClient->connect(DEF_DEVICE_NAME, mUser, mPwd);
|
||||
else
|
||||
mClient->connect(DEF_DEVICE_NAME);
|
||||
}
|
||||
mClient->subscribe("home/huette/powerset");
|
||||
}
|
||||
|
||||
WiFiClient mEspClient;
|
||||
PubSubClient *mClient;
|
||||
|
||||
|
||||
bool mAddressSet;
|
||||
uint16_t mPort;
|
||||
char mUser[MQTT_USER_LEN];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue