forked from bimanpaulsamsung/st-device-sdk-c-ref
-
Notifications
You must be signed in to change notification settings - Fork 1
/
WifiSTATest.cpp
67 lines (54 loc) · 1.79 KB
/
WifiSTATest.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
60
61
62
63
64
65
66
#include "cmsis_os2.h"
#include <stdio.h>
#include "mbed.h"
#include "WhdSoftAPInterface.h"
// Blinking rate in milliseconds
#define BLINKING_RATE_MS 500
osThreadId_t tid_phaseA;// Thread id of thread “phaseA”
void phaseA(void) {//Some application thread...some processing
printf("IN phaseA()\n");
DigitalOut led(LED1);
while (true) {
led = !led;
thread_sleep_for(BLINKING_RATE_MS);
// printf(".\n");
}
}
void app_main(void) {
Thread thread;
thread.start(phaseA);
printf("IN app_main()\n");
osDelay(osWaitForever);
//app_mainnever ready again
while (1);
}
static int connect_to_ap(char *wifi_ssid, char *wifi_password,
nsapi_security_t security = NSAPI_SECURITY_WPA_WPA2)
{
WiFiInterface *wifi;
wifi = WiFiInterface::get_default_instance();
if (!wifi) {
printf("ERROR: No WiFiInterface found.\n");
return -1;
}
printf("\nConnecting to %s...\n", wifi_ssid);
int ret = wifi->connect(wifi_ssid, wifi_password, security);
if (ret != 0) {
printf("\nConnection error: %d\n", ret);
return -1;
}
printf("Success\n\n");
printf("MAC: %s\n", wifi->get_mac_address());
printf("IP: %s\n", wifi->get_ip_address());
printf("Netmask: %s\n", wifi->get_netmask());
printf("Gateway: %s\n", wifi->get_gateway());
printf("RSSI: %d\n\n", wifi->get_rssi());
return 0;
}
int main(void) {
connect_to_ap("Psense", "psense019");
Thread thread;
thread.start(app_main);
printf("IN main()\n");
while(1);//will not execute unless above fails
}