forked from switchdoclabs/SDL_ESP32_OurWeather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherUtils.h
151 lines (107 loc) · 2.5 KB
/
WeatherUtils.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Weather Utilities
String returnDirectionFromDegrees(int degrees)
{
if (degrees == 0)
return "N";
if (degrees == 22)
return "NNE";
if (degrees == 45)
return "NE";
if (degrees == 67)
return "ENE";
if (degrees == 90)
return "E";
if (degrees == 112)
return "ESE";
if (degrees == 135)
return "SE";
if (degrees == 157)
return "SSE";
if (degrees == 180)
return "S";
if (degrees == 202)
return "SSW";
if (degrees == 225)
return "SW";
if (degrees == 247)
return "WSW";
if (degrees == 270)
return "W";
if (degrees == 292)
return "WNW";
if (degrees == 315)
return "NW";
if (degrees == 337)
return "NNW";
return "XX"; // return previous value if not found
}
void blinkIPAddress()
{
Serial.print("Blinking local Address =");
Serial.println(WiFi.localIP());
IPAddress LIP;
LIP = WiFi.localIP();
int lowOct;
lowOct = LIP[3];
// now do the blink
int check100;
int check10;
int check1;
delay(1000);
check100 = lowOct / 100;
Serial.println(check100);
if (check100 != 0)
{
blinkLED(check100, 250);
}
delay(1000);
check10 = (lowOct - check100 * 100) / 10;
Serial.println(check10);
if (check10 != 0)
{
blinkLED(check10, 500);
}
else
{
blinkLED(10, 100); // blink fast is 0
}
delay(1000);
check1 = ( lowOct - check100 * 100 - check10 * 10);
Serial.println(check1);
if (check1 != 0)
{
blinkLED(check1, 500);
}
else
{
blinkLED(10, 100); // blink fast is 0
}
}
void return2Digits(char returnString[], char *buffer2, int digits)
{
if (digits < 10)
sprintf(returnString, "0%i", digits);
else
sprintf(returnString, "%i", digits);
strcpy(returnString, buffer2);
}
void buildTimeString(char returnString[], char *buffer2, tmElements_t convertTime)
{
char myBuffer[5];
sprintf(myBuffer, "%i-", tmYearToCalendar(convertTime.Year));
strcat(returnString, myBuffer);
return2Digits(myBuffer, myBuffer, convertTime.Month);
strcat(returnString, myBuffer);
strcat(returnString, "-");
return2Digits(myBuffer, myBuffer, convertTime.Day);
strcat(returnString, myBuffer);
strcat(returnString, " ");
return2Digits(myBuffer, myBuffer, convertTime.Hour);
strcat(returnString, myBuffer);
strcat(returnString, ":");
return2Digits(myBuffer, myBuffer, convertTime.Minute);
strcat(returnString, myBuffer);
strcat(returnString, ":");
return2Digits(myBuffer, myBuffer, convertTime.Second);
strcat(returnString, myBuffer);
}