aboutsummaryrefslogtreecommitdiff
path: root/examples/std/README.md
diff options
context:
space:
mode:
author1-rafael-1 <[email protected]>2025-09-15 20:07:18 +0200
committer1-rafael-1 <[email protected]>2025-09-15 20:07:18 +0200
commit6bb3d2c0720fa082f27d3cdb70f516058497ec87 (patch)
tree5a1e255cff999b00800f203b91a759c720c973e5 /examples/std/README.md
parenteb685574601d98c44faed9a3534d056199b46e20 (diff)
parent92a6fd2946f2cbb15359290f68aa360953da2ff7 (diff)
Merge branch 'main' into rp2040-rtc-alarm
Diffstat (limited to 'examples/std/README.md')
-rw-r--r--examples/std/README.md119
1 files changed, 114 insertions, 5 deletions
diff --git a/examples/std/README.md b/examples/std/README.md
index dcc152fc2..ac2c2a1a6 100644
--- a/examples/std/README.md
+++ b/examples/std/README.md
@@ -1,19 +1,128 @@
1 1
2## Running the `embassy-net` examples 2## Running the `embassy-net` examples
3 3
4First, create the tap99 interface. (The number was chosen to 4To run `net`, `tcp_accept`, `net_udp` and `net_dns` examples you will need a tap interface. Before running these examples, create the tap99 interface. (The number was chosen to
5hopefully not collide with anything.) You only need to do 5hopefully not collide with anything.) You only need to do this once every time you reboot your computer.
6this once.
7 6
8```sh 7```sh
8cd $EMBASSY_ROOT/examples/std/
9sudo sh tap.sh 9sudo sh tap.sh
10``` 10```
11 11
12Second, have something listening there. For example `nc -lp 8000` 12The example `net_ppp` requires different steps that are detailed in its section.
13
14### `net` example
15
16For this example, you need to have something listening in the correct port. For example `nc -lp 8000`.
13 17
14Then run the example located in the `examples` folder: 18Then run the example located in the `examples` folder:
15 19
16```sh 20```sh
17cd $EMBASSY_ROOT/examples/std/ 21cd $EMBASSY_ROOT/examples/std/
18sudo cargo run --bin net -- --tap tap99 --static-ip 22cargo run --bin net -- --tap tap99 --static-ip
23```
24### `tcp_accept` example
25
26This example listen for a tcp connection.
27
28First run the example located in the `examples` folder:
29
30```sh
31cd $EMBASSY_ROOT/examples/std/
32cargo run --bin tcp_accept -- --tap tap99 --static-ip
33```
34
35Then open a connection to the port. For example `nc 192.168.69.2 9999`.
36
37### `net_udp` example
38
39This example listen for a udp connection.
40
41First run the example located in the `examples` folder:
42
43```sh
44cd $EMBASSY_ROOT/examples/std/
45cargo run --bin net_udp -- --tap tap99 --static-ip
46```
47
48Then open a connection to the port. For example `nc -u 192.168.69.2 9400`.
49
50### `net_dns` example
51
52This example queries a `DNS` for the IP address of `www.example.com`.
53
54In order to achieve this, the `tap99` interface requires configuring tap99 as a gateway device temporarily.
55
56For example, in Ubuntu you can do this by:
57
581. Identifying your default route device. In the next example `eth0`
59
60```sh
61ip r | grep "default"
62default via 192.168.2.1 dev eth0 proto kernel metric 35
63```
64
652. Enabling temporarily IP Forwarding:
66
67```sh
68sudo sysctl -w net.ipv4.ip_forward=1
69```
70
713. Configuring NAT to mascarade traffic from `tap99` to `eth0`
72
73```sh
74sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
75sudo iptables -A FORWARD -i tap99 -j ACCEPT
76sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
77```
78
794. Then you can run the example located in the `examples` folder:
80
81```sh
82cd $EMBASSY_ROOT/examples/std/
83cargo run --bin net_dns -- --tap tap99 --static-ip
84```
85
86### `net_ppp` example
87
88This example establish a Point-to-Point Protocol (PPP) connection that can be used, for example, for connecting to internet through a 4G modem via a serial channel.
89
90The example creates a PPP bridge over a virtual serial channel between `pty1` and `pty2` for the example code and a PPP server running on the same computer.
91
92To run this example you will need:
93- ppp (pppd server)
94- socat (socket CAT)
95
96To run the examples you may follow the next steps:
97
981. Save the PPP server configuration:
99```sh
100sudo sh -c 'echo "myuser $(hostname) mypass 192.168.7.10" >> /etc/ppp/pap-secrets'
101```
102
1032. Create a files `pty1` and `pty2` and link them
104```sh
105cd $EMBASSY_ROOT/examples/std/
106socat -v -x PTY,link=pty1,rawer PTY,link=pty2,rawer
107```
108
1093. open a second terminal and start the PPP server:
110```sh
111cd $EMBASSY_ROOT/examples/std/
112sudo pppd $PWD/pty1 115200 192.168.7.1: ms-dns 8.8.4.4 ms-dns 8.8.8.8 nodetach debug local persist silent
113```
114
1154. Open a third terminal and run the example
116```sh
117cd $EMBASSY_ROOT/examples/std/
118RUST_LOG=trace cargo run --bin net_ppp -- --device pty2
119```
1205. Observe the output in the second and third terminal
1216. Open one last terminal to interact with `net_ppp` example through the PPP connection
122```sh
123# ping the net_ppp client
124ping 192.168.7.10
125# open an tcp connection
126nc 192.168.7.10 1234
127# Type anything and observe the output in the different terminals
19``` 128```