-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
67 lines (60 loc) · 1.69 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
60
61
62
63
64
65
66
67
#include "mbed.h"
#include "blinkThread.h"
#include "temperatureThread.h"
#include "GUI.h"
#include "displayThread.h"
#include "capsenseThread.h"
#include "ntpThread.h"
#include "awsThread.h"
Thread blinkThreadHandle;
Thread temperatureThreadHandle;
Thread displayThreadHandle;
Thread capsenseThreadHandle;
Thread ntpThreadHandle;
Thread awsThreadHandle;
Semaphore WiFiSemaphore;
WiFiInterface *wifi;
// wifiStatusCallback
// Changes the display when the wifi status is changed
void wifiStatusCallback(nsapi_event_t status, intptr_t param)
{
switch(param) {
case NSAPI_STATUS_LOCAL_UP:
break;
case NSAPI_STATUS_GLOBAL_UP:
break;
case NSAPI_STATUS_DISCONNECTED:
WiFiSemaphore.release();
break;
case NSAPI_STATUS_CONNECTING:
break;
default:
break;
}
}
int main()
{
printf("Started System\n");
int ret;
wifi = WiFiInterface::get_default_instance();
wifi->attach(&wifiStatusCallback);
while(1)
{
do {
ret = wifi->connect("CYFI_IOT_EXT", "cypresswicedwifi101", NSAPI_SECURITY_WPA_WPA2);
if (ret != 0) {
ThisThread::sleep_for(2000); // If for some reason it doesnt work wait 2s and try again
}
} while(ret !=0);
if(blinkThreadHandle.get_state() == Thread::Deleted)
{
awsThreadHandle.start(awsThread);
ntpThreadHandle.start(ntpThread);
blinkThreadHandle.start(blinkThread);
displayThreadHandle.start(displayThread);
temperatureThreadHandle.start(temperatureThread);
capsenseThreadHandle.start(capsenseThread);
}
WiFiSemaphore.acquire();
}
}