File tree Expand file tree Collapse file tree 3 files changed +111
-0
lines changed
APIs_Drivers/Watchdog_ex_1
APIs_NetworkInterface/Mesh_Ex1
Tutorials_UsingAPIs/TLS_Communication Expand file tree Collapse file tree 3 files changed +111
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 Arm Limited and affiliates.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ #include " mbed.h"
7
+
8
+ const uint32_t TIMEOUT_MS = 5000 ;
9
+ InterruptIn button (BUTTON1);
10
+ volatile int countdown = 9 ;
11
+
12
+ void trigger ()
13
+ {
14
+ Watchdog::get_instance ().kick ();
15
+ countdown = 9 ;
16
+ }
17
+
18
+ int main ()
19
+ {
20
+ printf (" \r\n Target started.\r\n " );
21
+
22
+ Watchdog &watchdog = Watchdog::get_instance ();
23
+ watchdog.start (TIMEOUT_MS);
24
+ button.rise (&trigger);
25
+
26
+ uint32_t watchdog_timeout = watchdog.get_timeout ();
27
+ printf (" Watchdog initialized to %lu ms.\r\n " , watchdog_timeout);
28
+ printf (" Press BUTTON1 at least once every %lu ms to kick the "
29
+ " watchdog and prevent system reset.\r\n " , watchdog_timeout);
30
+
31
+ while (1 ) {
32
+ printf (" \r %3i" , countdown--);
33
+ fflush (stdout);
34
+ ThisThread::sleep_for (TIMEOUT_MS / 10 );
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 Arm Limited and affiliates.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ #include " mbed.h"
7
+
8
+ int main (void )
9
+ {
10
+ MeshInterface *mesh = MeshInterface::get_default_instance ();
11
+
12
+ int status = mesh->connect ();
13
+ if (status) {
14
+ printf (" Connection failed! error %d\n " , status);
15
+ return status;
16
+ }
17
+
18
+ printf (" Connected!\n " );
19
+
20
+ UDPSocket sock;
21
+ status = sock.open (mesh);
22
+ if (status) {
23
+ printf (" Failed to open socket, error %d\n " , status);
24
+ }
25
+
26
+ // Now the interface is connected, and I can communicate with Sockets
27
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 Arm Limited and affiliates.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ #include " mbed.h"
7
+ #include " mbed_trace.h"
8
+
9
+ const char cert[] = /* your certificate, see above */ " " ;
10
+
11
+ int main (void )
12
+ {
13
+
14
+ nsapi_size_or_error_t result;
15
+ NetworkInterface *net = NetworkInterface::get_default_instance ();
16
+
17
+ if (!net) {
18
+ printf (" Error! No network inteface found.\n " );
19
+ return 0 ;
20
+ }
21
+
22
+ printf (" Connecting to network\n " );
23
+ result = net->connect ();
24
+ if (result != 0 ) {
25
+ printf (" Error! net->connect() returned: %d\n " , result);
26
+ return result;
27
+ }
28
+
29
+ TLSSocket *socket = new TLSSocket;
30
+ result = socket->set_root_ca_cert (cert);
31
+ if (result != 0 ) {
32
+ printf (" Error: socket->set_root_ca_cert() returned %d\n " , result);
33
+ return result;
34
+ }
35
+
36
+ result = socket->open (net);
37
+ if (result != 0 ) {
38
+ printf (" Error! socket->open() returned: %d\n " , result);
39
+ return result;
40
+ }
41
+
42
+ printf (" Connecting to os.mbed.com\n " );
43
+ result = socket->connect (SocketAddress (" os.mbed.com" , 443 ));
44
+ if (result != 0 ) {
45
+ printf (" Error! socket->connect() returned: %d\n " , result);
46
+ return result;
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments