Skip to content

Commit d43e072

Browse files
committed
Add epmd_disterl esp32 example
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 5d3a5cc commit d43e072

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

examples/erlang/esp32/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ pack_runnable(sx127x sx127x eavmlib estdlib)
3737
pack_runnable(reformat_nvs reformat_nvs eavmlib)
3838
pack_runnable(uartecho uartecho eavmlib estdlib)
3939
pack_runnable(ledc_example ledc_example eavmlib estdlib)
40+
pack_runnable(epmd_disterl epmd_disterl eavmlib estdlib)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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(epmd_disterl).
22+
23+
-export([start/0]).
24+
25+
start() ->
26+
Creds = [
27+
{ssid, "myssid"},
28+
{psk, "mypsk"}
29+
],
30+
case network:wait_for_sta(Creds, 30000) of
31+
{ok, {Address, _Netmask, _Gateway}} ->
32+
distribution_start(Address);
33+
Error ->
34+
io:format("An error occurred starting network: ~p~n", [Error])
35+
end.
36+
37+
distribution_start(Address) ->
38+
{ok, _EPMDPid} = epmd:start_link([]),
39+
{ok, _KernelPid} = kernel:start(normal, []),
40+
{X, Y, Z, T} = Address,
41+
Node = list_to_atom(lists:flatten(io_lib:format("atomvm@~B.~B.~B.~B", [X, Y, Z, T]))),
42+
{ok, _NetKernelPid} = net_kernel:start(Node, #{name_domain => longnames}),
43+
io:format("Distribution was started\n"),
44+
io:format("Node is ~p\n", [node()]),
45+
net_kernel:set_cookie(<<"AtomVM">>),
46+
io:format("Cookie is ~s\n", [net_kernel:get_cookie()]),
47+
register(disterl, self()),
48+
io:format(
49+
"This AtomVM node is waiting for 'quit' message, and this process is registered as 'disterl'\n"
50+
),
51+
io:format("On an OTP node with long names distribution, run:\n"),
52+
io:format("erlang:set_cookie('~s', 'AtomVM').\n", [Node]),
53+
io:format("{disterl, '~s'} ! quit.\n", [Node]),
54+
receive
55+
quit -> ok
56+
end.

0 commit comments

Comments
 (0)