anchor.diff:  handle_info({uplink, _Node, _Vars0}, #state{publish_uplinks=PatPub}=State)
           when PatPub == undefined; PatPub == ?EMPTY_PATTERN ->
       {noreply, State};
  -handle_info({uplink, _Node, Vars0}, #state{conn=Connector, pid=undefined}=State) ->
  -    case connect(Connector) of
  -        {ok, ConnPid} ->
  -            {noreply, handle_uplink(Vars0, State#state{pid=ConnPid})};
  -        {error, _} ->
  -            % will try to reconnect upon next uplink
  -            {noreply, State#state{pid=undefined}}
  -    end;
  -handle_info({uplink, _Node, Vars0}, #state{pid=ConnPid}=State) when is_pid(ConnPid) ->
  -    {noreply, handle_uplink(Vars0, State)};
  +handle_info({uplink, _Node, Vars0}, #state{conn=Conn}=State) ->
  +    case ensure_connected(State) of
  +        {ok, State2} ->
  +            {noreply, handle_uplink(Vars0, State2)};
  +        {error, State2} ->
  +            lager:warning("Connector ~p not connected, uplink lost", [Conn#connector.connid]),
  +            {noreply, State2}
  +    end;
   
   handle_info({event, _Node, _Vars0}, #state{publish_events=PatPub}=State)
           when PatPub == undefined; PatPub == ?EMPTY_PATTERN ->
       {noreply, State};
  -handle_info({event, _Node, Vars0}, #state{conn=Connector, pid=undefined}=State) ->
  -    case connect(Connector) of
  -        {ok, ConnPid} ->
  -            {noreply, handle_event(Vars0, State#state{pid=ConnPid})};
  -        {error, _} ->
  -            {noreply, State#state{pid=undefined}}
  -    end;
  -handle_info({event, _Node, Vars0}, #state{pid=ConnPid}=State) when is_pid(ConnPid) ->
  -    {noreply, handle_event(Vars0, State)};
  -
  -handle_info({gun_up, C, http}, State=#state{pid=C}) ->
  -    {noreply, State};
  +handle_info({event, _Node, Vars0}, #state{conn=Conn}=State) ->
  +    case ensure_connected(State) of
  +        {ok, State2} ->
  +            {noreply, handle_event(Vars0, State2)};
  +        {error, State2} ->
  +            lager:warning("Connector ~p not connected, event lost", [Conn#connector.connid]),
  +            {noreply, State2}
  +    end;
  +
  +handle_info({gun_up, C, http}, State=#state{pid={C,_}}) ->
  +    {noreply, #state{ready=true}=State};
   handle_info({gun_down, C, _Proto, _Reason, Killed, Unprocessed},
  -        State=#state{pid=C, streams=Streams}) ->
  -    {noreply, State#state{streams=remove_list(remove_list(Streams, Killed), Unprocessed)}};
  +        State=#state{pid={C,_}, streams=Streams}) ->
  +    {noreply, State#state{ready=false, streams=remove_list(remove_list(Streams, Killed), Unprocessed)}};
   handle_info({gun_response, C, StreamRef, Fin, 401, Headers},
  -        State=#state{pid=C, streams=Streams}) ->
  +        State=#state{pid={C,_}, streams=Streams}) ->
       State3 =
           case proplists:get_value(<<"www-authenticate">>, Headers) of
               undefined ->
  
positive.code:             {stop, shutdown}
      end.
  
  handle_call(_Request, _From, State) ->
      {reply, {error, unknownmsg}, State}.
  
  handle_cast(_Msg, State) ->
      {noreply, State}.
  
  handle_info(connect, #state{conn=Connector}=State) ->
      case connect(Connector) of
          {ok, ConnPid} ->
              {noreply, State#state{pid=ConnPid}};
          {error, _} ->
              % will try to reconnect upon uplink
              {noreply, State#state{pid=undefined}}
      end;
  handle_info(nodes_changed, State) ->
      % nothing to do here
      {noreply, State};
  
negative.code: 
  -include("lorawan_db.hrl").
  
  -record(state, {conn, pid, ready, streams, publish_uplinks, publish_events, auth, nc}).
  
  start_connector(#connector{connid=Id, received=Received}=Connector) ->
      case lorawan_connector:pattern_for_cowboy(Received) of
  