-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
59 lines (50 loc) · 1.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "EthernetInterface.h"
#include "mbed.h"
#include "nsapi_types.h"
// Network interface
EthernetInterface eth;
Mutex print_mutex;
void safe_print(const char *msg)
{
print_mutex.lock();
printf(msg);
print_mutex.unlock();
}
void status_callback(nsapi_event_t status, intptr_t param)
{
safe_print("Connection status changed!\r\n");
switch (param) {
case NSAPI_STATUS_LOCAL_UP:
safe_print("Local IP address set!\r\n");
break;
case NSAPI_STATUS_GLOBAL_UP:
safe_print("Global IP address set!\r\n");
break;
case NSAPI_STATUS_DISCONNECTED:
safe_print("No connection to network!\r\n");
break;
case NSAPI_STATUS_CONNECTING:
safe_print("Connecting to network!\r\n");
break;
default:
safe_print("Not supported\r\n");
break;
}
}
int main()
{
safe_print("Status callback example!\r\n");
eth.attach(&status_callback);
eth.set_blocking(false);
safe_print("Connecting...\r\n");
eth.connect();
safe_print("Connecting started...\r\n");
ThisThread::sleep_for(10000);
safe_print("Disconnect\r\n");
eth.disconnect();
safe_print("Done\r\n");
}