Feed Ipaddress by MQTT
This commit is contained in:
parent
286844dd6d
commit
967c6c736f
@ -8,6 +8,7 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname)
|
||||
int MqttPublish(double temp, double pressure);
|
||||
int MqttDhtPublish(float temp, float humidity);
|
||||
int MqttDryPublish(int dry);
|
||||
int MqttIPPublish(const String &ip);
|
||||
void MqttCheckSubscription();
|
||||
void MqttChangeGpioValue(int gpio, int value);
|
||||
bool MqttIsConfigured();
|
||||
|
@ -9,6 +9,7 @@ Adafruit_MQTT_Publish *mqtt_pressure;
|
||||
Adafruit_MQTT_Publish *mqtt_dht_temp;
|
||||
Adafruit_MQTT_Publish *mqtt_dht_humidity;
|
||||
Adafruit_MQTT_Publish *mqtt_dry;
|
||||
Adafruit_MQTT_Publish *mqtt_ip;
|
||||
|
||||
#define NB_ELEMENTS(x) (sizeof(x)/ sizeof(x[0]))
|
||||
#define FEED_MAX_SIZE 96
|
||||
@ -27,6 +28,8 @@ const int gpioWatched[] = CONFIG_MQTT_CONTROLLED_GPIO;
|
||||
#define GPIO_FEED_FORMAT "/feeds/%s/%s/gpio/%d"
|
||||
#define GPIO_SET_FEED_FORMAT "/feeds/%s/%s/gpio/%d/set"
|
||||
|
||||
#define IP_FEED_FORMAT "/feeds/%s/%s/configuration/ip/addr"
|
||||
|
||||
char *mqttId;
|
||||
char GPIO_FEED[MAXSUBSCRIPTIONS][FEED_MAX_SIZE] = {};
|
||||
char GPIO_SET_FEED[MAXSUBSCRIPTIONS][FEED_MAX_SIZE] = {};
|
||||
@ -49,6 +52,7 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname)
|
||||
mqtt_temp = MqttCreatePublisher(TEMPERATURE_FEED_FORMAT, user, mqttId);
|
||||
mqtt_pressure = MqttCreatePublisher(PRESSURE_FEED_FORMAT, user, mqttId);
|
||||
mqtt_dry = MqttCreatePublisher(DRY_FEED_FORMAT, user, mqttId);
|
||||
mqtt_ip = MqttCreatePublisher(IP_FEED_FORMAT, user, mqttId);
|
||||
|
||||
for (uint i = 0 ; i < NB_ELEMENTS(gpioWatched) && i < MAXSUBSCRIPTIONS; i++) {
|
||||
snprintf(GPIO_FEED[i], FEED_MAX_SIZE, GPIO_FEED_FORMAT, user, mqttId, gpioWatched[i]);
|
||||
@ -125,6 +129,14 @@ int MqttDryPublish(int dry) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MqttIPPublish(const String &ip) {
|
||||
if (MqttConnect() == 0) {
|
||||
SKETCH_DEBUG_PRINTLN("publishing IP!");
|
||||
mqtt_ip->publish(ip.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MqttDhtPublish(float temp, float humidity) {
|
||||
if (MqttConnect() == 0) {
|
||||
SKETCH_DEBUG_PRINTLN("publishing DHT!");
|
||||
|
@ -225,6 +225,7 @@ void setup() {
|
||||
WifiSetup(mode, confSsid, confPassword, confHost, ip_mode, ip, gw, mask, dns, dns2);
|
||||
if (mode == BOOTMODE_NORMAL) {
|
||||
MqttSetup(mqttServer, mqttUser, mqttPasswd, mqttPort, confHost);
|
||||
MqttIPPublish(WiFi.localIP().toString());
|
||||
}
|
||||
|
||||
if (mode == BOOTMODE_OTA) {
|
||||
|
Loading…
Reference in New Issue
Block a user