Skip to content

Instantly share code, notes, and snippets.

@bettio
Created November 30, 2018 00:59
Show Gist options
  • Save bettio/0695f61d4e3f0208527ffe63e33cddb0 to your computer and use it in GitHub Desktop.
Save bettio/0695f61d4e3f0208527ffe63e33cddb0 to your computer and use it in GitHub Desktop.
UDP hello world on https://github.com/bettio/atomvm (works on d6c6d54d607e5d8ca5af7447fa53f3d4e1647db4)
defmodule UDPHelloWorld do
@remote_ip {192, 168, 0, 2}
@port 8981
# @ssid 'YourSSID'
# @psk 'YourPassword'
def start() do
# You should connect to a network and sleep some seconds
# network = :network.open()
# :network.setup(network, [{:ssid, @ssid}, {:psk, @psk}])
# :timer.sleep(1000)
udp = :erlang.open_port({:spawn, "udp"}, [])
send_udp(udp, @remote_ip, @port, 'UDP hello world\n')
end
def send_udp(udp, ip_addr, dest_port, buffer) when is_list(buffer) do
send udp, {self(), make_ref(), :send, ip_addr, dest_port, buffer}
receive do
ret -> ret
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment