gausby / tortoise

A MQTT Client written in Elixir
Apache License 2.0
312 stars 54 forks source link

EXIT no process on nerves #105

Closed ychaudhari7 closed 5 years ago

ychaudhari7 commented 5 years ago

I am using {tortoise: "~> 0.9"} on a nerves project when I boot the device in shell and try simple connection over tcp by

defmodule MMod.Mqtt do
  require Logger
  use GenServer

  def start_link(opts \\ []) do
    GenServer.start_link(__MODULE__, :ok,opts)
  end

  def init(:ok) do
    IO.puts("starting mqtt")
    {:ok,pid}=Tortoise.Supervisor.start_child(
        client_id: Application.get_env(:hello_network,:client_id),
        handler: {Tortoise.Handler.Logger, []},
        server: {Tortoise.Transport.Tcp, host: Application.get_env(:hello_network,:mqtt_host), port: String.to_integer(Application.get_env(:hello_network,:port))}
    )
    {:ok,pid}
  end

  def handle_call({:simple_call}, from, state) do
        {:reply,from,state}
  end

  def handle_cast({:simple_cast}, from, state) do
        {:noreply,[]}
  end

  def handle_info(msg, state) do
        case msg do
            _ ->  Tortoise.publish(Application.get_env(:hello_network,:client_id),Application.get_env(:hello_network,:topic),":mymsg", qos: 2)
        {:noreply,state}
               end
  end

end

My values for getting fetched as

client_id : "my_client" mqtt_host: "iot.eclipse.org" port: 1883

I am getting this

{:error, {:noproc, {GenServer, :call, [ Tortoise.Supervisor, {:start_child, {{ Tortoise.Connection, :start_link, [ [ client_id: "my_first_client", handler: {Tortoise.Handler.Logger,[]}, server: {Tortoise.Transport.Tcp,[ host: "iot.eclipse.org", port:1883]} ] ]}, transient, 5000, :worker,[Tortoise.Connection] }}, :infinity ]}}} ** (EXIT from #PID<0.964.0> shell process exited with reason: exited in: GenServer.call(Tortoise.Supervisor,{:start_child, {Tortoise.Connection, :start_link, [[client_id: "my_client_id", handler: {Tortoise.Handler.Logger, []},server: {Tortoise.Transport.Tcp, [host: "iot.eclipse.org", port: 1883]}]]}, :transient, 5000, :worker, [Tortoise.Connection]}}, :infinity)

** (EXIT) no process the process is not alive or there is no process currently associated with given name possibly because its application isn't started (elixir) lib/gen_server.ex 979 GenServer.call/3

I am able to connect to server with same in normal mix project on host machine. I am using

Erlang OTP/ 21 and Elixir (1.8.1)