Skip to content

Commit

Permalink
Add mDNS to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmclean committed Sep 8, 2024
1 parent ffa91b5 commit 348a66a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 32 deletions.
4 changes: 0 additions & 4 deletions garden-app/controller/generate_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ const (
#define QUEUE_SIZE 10
#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "{{ .MQTTConfig.Broker }}"
#define MQTT_PORT {{ .MQTTConfig.Port }}
#endif
#define NUM_ZONES {{ len .Zones }}
#define VALVES { {{ range $index, $z := .Zones }}{{if $index}}, {{end}}{{ $z.ValvePin }}{{ end }} }
#define PUMPS { {{ range $index, $z := .Zones }}{{if $index}}, {{end}}{{ $z.PumpPin }}{{ end }} }
Expand Down
16 changes: 0 additions & 16 deletions garden-app/controller/generate_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ func TestGenerateMainConfig(t *testing.T) {
#define QUEUE_SIZE 10
#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "localhost"
#define MQTT_PORT 1883
#endif
#define NUM_ZONES 1
#define VALVES { GPIO_NUM_16 }
#define PUMPS { GPIO_NUM_18 }
Expand Down Expand Up @@ -95,13 +91,9 @@ func TestGenerateMainConfig(t *testing.T) {
#define QUEUE_SIZE 10
#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "localhost"
#define MQTT_PORT 1883
#endif
#define NUM_ZONES 1
#define VALVES { GPIO_NUM_16 }
#define PUMPS { GPIO_NUM_18 }
Expand Down Expand Up @@ -139,13 +131,9 @@ func TestGenerateMainConfig(t *testing.T) {
#define QUEUE_SIZE 10
#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "localhost"
#define MQTT_PORT 1883
#endif
#define NUM_ZONES 1
#define VALVES { GPIO_NUM_16 }
#define PUMPS { GPIO_NUM_18 }
Expand Down Expand Up @@ -195,13 +183,9 @@ func TestGenerateMainConfig(t *testing.T) {
#define QUEUE_SIZE 10
#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "localhost"
#define MQTT_PORT 1883
#endif
#define NUM_ZONES 4
#define VALVES { GPIO_NUM_16, GPIO_NUM_16, GPIO_NUM_16, GPIO_NUM_16 }
#define PUMPS { GPIO_NUM_18, GPIO_NUM_18, GPIO_NUM_18, GPIO_NUM_18 }
Expand Down
9 changes: 0 additions & 9 deletions garden-app/controller/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ func mqttPrompts(config *Config) error {
},
Validate: survey.Required,
},
{
Name: "publish_health",
Prompt: &survey.Input{
Message: "Enable health publishing?",
Default: fmt.Sprintf("%t", config.PublishHealth),
Help: "control whether or not healh publishing is enabled. Enable it unless you have a good reason not to",
},
Validate: survey.Required,
},
}
err := survey.Ask(qs, config)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions garden-controller/include/wifi_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <LittleFS.h>
#include <ESPmDNS.h>

#define FORMAT_LITTLEFS_IF_FAILED true

Expand Down
13 changes: 10 additions & 3 deletions garden-controller/src/wifi_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ void connectWifiDirect() {

printf("Wifi connected...\n");

strcpy(mqtt_server, MQTT_ADDRESS);
strcpy(mqtt_topic_prefix, TOPIC_PREFIX);
mqtt_port = MQTT_PORT;

wifiManager.setEnableConfigPortal(false);
wifiManager.setConfigPortalBlocking(false);
wifiManager.autoConnect();
Expand All @@ -129,9 +133,7 @@ void setupWifiManager() {
wifiManager.addParameter(&custom_mqtt_topic_prefix);
wifiManager.addParameter(&custom_mqtt_port);

char hostname[50];
snprintf(hostname, sizeof(hostname), "%s-controller", mqtt_topic_prefix);
wifiManager.setHostname(hostname);
wifiManager.setHostname(mqtt_topic_prefix);

// wifiManager.resetSettings();

Expand All @@ -151,6 +153,11 @@ void setupWifiManager() {

xTaskCreate(wifiManagerLoopTask, "WifiManagerLoopTask", 4096, NULL, 1, &wifiManagerLoopTaskHandle);

if (!MDNS.begin(mqtt_topic_prefix)) {
printf("error starting mDNS\n");
return;
}

// Create event handler tp reconnect to WiFi
WiFi.onEvent(wifiDisconnectHandler, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
}

0 comments on commit 348a66a

Please sign in to comment.