Skip to content

Commit

Permalink
Fixed IP publish to mqtt and publish device data on every connection …
Browse files Browse the repository at this point in the history
…check
  • Loading branch information
danimtb committed Jan 22, 2017
1 parent d3858cd commit 8432a2f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../info/NetworkInfo.h"

#define FW "sonoff-touch-custom"
#define FW_VERSION "0.0.2"
#define FW_VERSION "0.0.4"

IPAddress ip(192, 168, 1, IP_NUMBER);
IPAddress gateway(192, 168, 1, 1);
Expand Down Expand Up @@ -60,15 +60,18 @@ void connectWifi()

void publishDeviceInfo()
{
Serial.println("Publising device information...");
Serial.println("Publishing device information...");

char ip[3];
sprintf(ip, "%d", IP_NUMBER);

client.publish(deviceNameTopic, DEVICE_NAME);
client.publish(deviceIpTopic, IP_NUMBER);
client.publish(deviceIpTopic, ip);
client.publish(deviceTypeTopic, DEVICE_TYPE);
client.publish(fwTopic, FW);
client.publish(fwVersionTopic, FW_VERSION);

Serial.println("Publising device information done!");
Serial.println("Publishing device information done!");
}

void checkConnectivity()
Expand Down Expand Up @@ -106,12 +109,8 @@ void checkConnectivity()
else
{
Serial.println("MQTT connection OK");

if(!connected)
{
publishDeviceInfo();
connected = true;
}
publishDeviceInfo();
connected = true;
}
}
}
Expand Down

0 comments on commit 8432a2f

Please sign in to comment.