diff --git a/server/lib/systant/config.ex b/server/lib/systant/config.ex index eee5afd..a6260a3 100644 --- a/server/lib/systant/config.ex +++ b/server/lib/systant/config.ex @@ -171,9 +171,26 @@ defmodule Systant.Config do end defp find_config_file do - @default_config_paths - |> Enum.map(&Path.expand/1) - |> Enum.find(&File.exists?/1) + expanded_paths = @default_config_paths |> Enum.map(&expand_config_path/1) + + Logger.debug("Searching for config files at: #{inspect(expanded_paths)}") + + case Enum.find(expanded_paths, &File.exists?/1) do + nil -> + Logger.debug("No config file found, checked: #{inspect(expanded_paths)}") + nil + path -> + Logger.debug("Found config file at: #{path}") + path + end + end + + defp expand_config_path("~" <> rest) do + home = System.user_home() + Path.join(home, rest) + end + defp expand_config_path(path) do + Path.expand(path) end defp apply_env_overrides(config) do diff --git a/server/lib/systant/mqtt_client.ex b/server/lib/systant/mqtt_client.ex index 3b09b9b..debd717 100644 --- a/server/lib/systant/mqtt_client.ex +++ b/server/lib/systant/mqtt_client.ex @@ -16,6 +16,7 @@ defmodule Systant.MqttClient do mqtt_config = Systant.Config.mqtt_config(app_config) Logger.info("Starting MQTT client with config: #{inspect(mqtt_config)}") + Logger.info("Attempting to connect to MQTT broker at #{mqtt_config.host}:#{mqtt_config.port}") # Store both configs for later use state_config = %{ diff --git a/server/lib/systant/mqtt_handler.ex b/server/lib/systant/mqtt_handler.ex index d3ffd43..0fed72a 100644 --- a/server/lib/systant/mqtt_handler.ex +++ b/server/lib/systant/mqtt_handler.ex @@ -18,11 +18,15 @@ defmodule Systant.MqttHandler do def connection(status, state) do case status do :up -> - Logger.info("MQTT connection established") + Logger.info("MQTT connection established successfully") :down -> - Logger.warning("MQTT connection lost") + Logger.error("MQTT connection lost - check MQTT broker availability and configuration") :terminating -> Logger.info("MQTT connection terminating") + {:error, reason} -> + Logger.error("MQTT connection failed: #{inspect(reason)}") + other -> + Logger.error("MQTT connection status unknown: #{inspect(other)}") end {:ok, state} end