Skip to content

Instantly share code, notes, and snippets.

@bettio
Created March 7, 2020 22:30
Show Gist options
  • Save bettio/c273a0647540f30a664fc12d3d620dd3 to your computer and use it in GitHub Desktop.
Save bettio/c273a0647540f30a664fc12d3d620dd3 to your computer and use it in GitHub Desktop.
Elixir morse encode example - step 2
def start() do
connect()
end
def connect() do
this_process = self()
config = [
{:sta,
[
{:ssid, "MyWiFiAPSSIDHere"},
{:psk, "MyWiFiPassHere"},
{:connected, fn -> send(this_process, :connected) end},
{:got_ip, fn ip_info -> send(this_process, {:ok, ip_info}) end},
{:disconnected, fn -> send(this_process, :disconnected) end}
]}
]
case :network_fsm.start(config) do
:ok ->
network_events_loop()
error ->
:erlang.display(error)
end
end
def network_events_loop() do
router = [
{'*', __MODULE__, []}
]
receive do
{:ok, ip_info} ->
:erlang.display(ip_info)
:http_server.start_server(8080, router)
any_event ->
:erlang.display(:connected)
end
network_events_loop()
end
def handle_req(method, path, conn) do
:erlang.display(Conn)
:erlang.display({Method, Path})
body = "<html><body><h1>Not Found</h1></body></html>"
:http_server.reply(404, body, conn)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment