Skip to content

Commit d456008

Browse files
committed
Merge pull request #1667 from pguyot/w20/add-disterl-example-for-rp2
Add disterl example for rp2 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents e6e574b + 693022b commit d456008

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

examples/erlang/rp2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ pack_uf2(picow_wifi_sta picow_wifi_sta)
3030
pack_uf2(picow_wifi_ap picow_wifi_ap)
3131
pack_uf2(picow_udp_beacon picow_udp_beacon)
3232
pack_uf2(picow_tcp_server picow_tcp_server)
33+
pack_uf2(picow_wifi_epmd_disterl picow_wifi_epmd_disterl)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
-module(picow_wifi_epmd_disterl).
22+
23+
-export([start/0]).
24+
25+
start() ->
26+
Parent = self(),
27+
Config = [
28+
{sta, [
29+
{ssid, <<"myssid">>},
30+
{psk, <<"mypsk">>},
31+
{got_ip, fun(Arg) -> got_ip(Parent, Arg) end}
32+
]},
33+
{sntp, [
34+
{host, "pool.ntp.org"}
35+
]}
36+
],
37+
case network:start(Config) of
38+
{ok, _Pid} ->
39+
receive
40+
{got_ip, IPv4} ->
41+
distribution_start(IPv4)
42+
end;
43+
Error ->
44+
erlang:display(Error)
45+
end.
46+
47+
got_ip(Parent, {IPv4, _Netmask, _Gateway}) ->
48+
Parent ! {got_ip, IPv4}.
49+
50+
distribution_start(Address) ->
51+
{ok, _EPMDPid} = epmd:start_link([]),
52+
{ok, _KernelPid} = kernel:start(normal, []),
53+
{X, Y, Z, T} = Address,
54+
Node = list_to_atom(lists:flatten(io_lib:format("atomvm@~B.~B.~B.~B", [X, Y, Z, T]))),
55+
{ok, _NetKernelPid} = net_kernel:start(Node, #{name_domain => longnames}),
56+
io:format("Distribution was started\n"),
57+
io:format("Node is ~p\n", [node()]),
58+
net_kernel:set_cookie(<<"AtomVM">>),
59+
io:format("Cookie is ~s\n", [net_kernel:get_cookie()]),
60+
register(disterl, self()),
61+
io:format(
62+
"This AtomVM node is waiting for 'quit' message, and this process is registered as 'disterl'\n"
63+
),
64+
io:format("On an OTP node with long names distribution, run:\n"),
65+
io:format("erlang:set_cookie('~s', 'AtomVM').\n", [Node]),
66+
io:format("{disterl, '~s'} ! quit.\n", [Node]),
67+
receive
68+
quit -> ok
69+
end.

0 commit comments

Comments
 (0)