@@ -30,7 +30,7 @@ See more at http://blog.squix.ch
30
30
WundergroundAlerts::WundergroundAlerts () {
31
31
32
32
}
33
- void WundergroundAlerts::updateAlerts (String apiKey, String language, String country, String city) {
33
+ void WundergroundAlerts::updateAlerts (WGAlert *alerts, uint8_t maxAlerts, String apiKey, String language, String country, String city) {
34
34
currentAlert = 0 ;
35
35
activeAlertsCnt = 0 ;
36
36
isAlerts = true ;
@@ -41,11 +41,11 @@ void WundergroundAlerts::updateAlerts(String apiKey, String language, String cou
41
41
isAlertUS = false ;
42
42
isAlertEU = true ;
43
43
}
44
- doUpdate (" /api/" + apiKey + " /alerts/lang:" + language + " /q/" + country + " /" + city + " .json" );
44
+ doUpdate (alerts, maxAlerts, " /api/" + apiKey + " /alerts/lang:" + language + " /q/" + country + " /" + city + " .json" );
45
45
}
46
46
// end fowlerk add
47
47
48
- void WundergroundAlerts::updateAlertsPWS (String apiKey, String language, String country, String pws) {
48
+ void WundergroundAlerts::updateAlertsPWS (WGAlert *alert, uint8_t maxAlerts, String apiKey, String language, String country, String pws) {
49
49
currentAlert = 0 ;
50
50
activeAlertsCnt = 0 ;
51
51
isAlerts = true ;
@@ -56,10 +56,12 @@ void WundergroundAlerts::updateAlertsPWS(String apiKey, String language, String
56
56
isAlertUS = false ;
57
57
isAlertEU = true ;
58
58
}
59
- doUpdate (" /api/" + apiKey + " /alerts/lang:" + language + " /q/pws:" + pws + " .json" );
59
+ doUpdate (alerts, maxAlerts, " /api/" + apiKey + " /alerts/lang:" + language + " /q/pws:" + pws + " .json" );
60
60
}
61
61
62
- void WundergroundAlerts::doUpdate (String url) {
62
+ void WundergroundAlerts::doUpdate (WGAlert *alerts, uint8_t maxAlerts, String url) {
63
+ this ->alerts = alerts;
64
+ this ->maxAlerts = maxAlerts;
63
65
JsonStreamingParser parser;
64
66
parser.setListener (this );
65
67
WiFiClient client;
@@ -102,6 +104,7 @@ void WundergroundAlerts::doUpdate(String url) {
102
104
}
103
105
}
104
106
}
107
+ this ->alerts = nullptr ;
105
108
}
106
109
107
110
void WundergroundAlerts::whitespace (char c) {
@@ -120,64 +123,74 @@ void WundergroundAlerts::value(String value) {
120
123
if (currentKey == " type" && isAlerts) {
121
124
activeAlertsCnt++;
122
125
currentAlert++;
123
- activeAlerts[currentAlert-1 ] = value;
124
- Serial.print (" Alert type processed, value: " ); Serial.println (activeAlerts[currentAlert-1 ]);
126
+ alerts[currentAlert-1 ].activeAlerts = value;
127
+ Serial.print (" Alert type processed, value: " );
128
+ Serial.println (alerts[currentAlert-1 ].activeAlerts );
125
129
}
126
130
if (currentKey == " description" && isAlerts && isAlertUS) {
127
- activeAlertsText[currentAlert-1 ] = value;
128
- Serial.print (" Alert description processed, value: " ); Serial.println (activeAlertsText[currentAlert-1 ]);
131
+ alerts[currentAlert-1 ].activeAlertsText = value;
132
+ Serial.print (" Alert description processed, value: " );
133
+ Serial.println (alerts[currentAlert-1 ].activeAlertsText );
129
134
}
130
135
if (currentKey == " wtype_meteoalarm_name" && isAlerts && isAlertEU) {
131
- activeAlertsText[currentAlert-1 ] = value;
132
- Serial.print (" Alert description processed, value: " ); Serial.println (activeAlertsText[currentAlert-1 ]);
136
+ alerts[currentAlert-1 ].activeAlertsText = value;
137
+ Serial.print (" Alert description processed, value: " );
138
+ Serial.println (alerts[currentAlert-1 ].activeAlertsText );
133
139
}
134
140
if (currentKey == " message" && isAlerts) {
135
- activeAlertsMessage[currentAlert-1 ] = value;
136
- Serial.print (" Alert msg length: " ); Serial.println (activeAlertsMessage[currentAlert-1 ].length ());
137
- if (activeAlertsMessage[currentAlert-1 ].length () >= 511 ) {
138
- activeAlertsMessageTrunc[currentAlert-1 ] = true ;
141
+ alerts[currentAlert-1 ].activeAlertsMessage = value;
142
+ Serial.print (" Alert msg length: " );
143
+ Serial.println (alerts[currentAlert-1 ].activeAlertsMessage .length ());
144
+ if (alerts[currentAlert-1 ].activeAlertsMessage .length () >= 511 ) {
145
+ alerts[currentAlert-1 ].activeAlertsMessageTrunc = true ;
139
146
} else {
140
- activeAlertsMessageTrunc [currentAlert-1 ] = false ;
147
+ alerts [currentAlert-1 ]. activeAlertsMessageTrunc = false ;
141
148
}
142
- Serial.print (" Alert message processed, value: " ); Serial.println (activeAlertsMessage[currentAlert-1 ]);
149
+ Serial.print (" Alert message processed, value: " );
150
+ Serial.println (alerts[currentAlert-1 ].activeAlertsMessage );
143
151
}
144
152
if (currentKey == " date" && isAlerts) {
145
- activeAlertsStart [currentAlert-1 ] = value;
153
+ alerts [currentAlert-1 ]. activeAlertsStart = value;
146
154
// Check last char for a "/"; the returned value sometimes includes this; if so, strip it (47 is a "/" char)
147
- if (activeAlertsStart [currentAlert-1 ].charAt (activeAlertsStart [currentAlert-1 ].length ()-1 ) == 47 ) {
155
+ if (alerts [currentAlert-1 ].activeAlertsStart . charAt (alerts [currentAlert-1 ]. activeAlertsStart .length ()-1 ) == 47 ) {
148
156
Serial.println (" ...last char is a slash..." );
149
- activeAlertsStart [currentAlert-1 ] = activeAlertsStart [currentAlert-1 ].substring (0 ,(activeAlertsStart [currentAlert-1 ].length ()-1 ));
157
+ alerts [currentAlert-1 ]. activeAlertsStart = alerts [currentAlert-1 ].activeAlertsStart . substring (0 ,(alerts [currentAlert-1 ]. activeAlertsStart .length ()-1 ));
150
158
}
151
159
// For meteoalarms, the start field is returned with the UTC=0 by default (not used?)
152
- if (isAlertEU && activeAlertsStart [currentAlert-1 ] == " 1970-01-01 00:00:00 GMT" ) {
153
- activeAlertsStart [currentAlert-1 ] = " <Not specified>" ;
160
+ if (isAlertEU && alerts [currentAlert-1 ]. activeAlertsStart == " 1970-01-01 00:00:00 GMT" ) {
161
+ alerts [currentAlert-1 ]. activeAlertsStart = " <Not specified>" ;
154
162
}
155
- Serial.print (" Alert start processed, value: " ); Serial.println (activeAlertsStart[currentAlert-1 ]);
163
+ Serial.print (" Alert start processed, value: " );
164
+ Serial.println (alerts[currentAlert-1 ].activeAlertsStart );
156
165
}
157
166
if (currentKey == " expires" && isAlerts) {
158
- activeAlertsEnd[currentAlert-1 ] = value;
159
- Serial.print (" Alert expiration processed, value: " ); Serial.println (activeAlertsEnd[currentAlert-1 ]);
167
+ alerts[currentAlert-1 ].activeAlertsEnd = value;
168
+ Serial.print (" Alert expiration processed, value: " );
169
+ Serial.println (alerts[currentAlert-1 ].activeAlertsEnd );
160
170
}
161
171
if (currentKey == " phenomena" && isAlerts) {
162
- activeAlertsPhenomena[currentAlert-1 ] = value;
163
- Serial.print (" Alert phenomena processed, value: " ); Serial.println (activeAlertsPhenomena[currentAlert-1 ]);
172
+ alerts[currentAlert-1 ].activeAlertsPhenomena = value;
173
+ Serial.print (" Alert phenomena processed, value: " );
174
+ Serial.println (alerts[currentAlert-1 ].activeAlertsPhenomena );
164
175
}
165
176
if (currentKey == " significance" && isAlerts && isAlertUS) {
166
- activeAlertsSignificance[currentAlert-1 ] = value;
167
- Serial.print (" Alert significance processed, value: " ); Serial.println (activeAlertsSignificance[currentAlert-1 ]);
177
+ alerts[currentAlert-1 ].activeAlertsSignificance = value;
178
+ Serial.print (" Alert significance processed, value: " );
179
+ Serial.println (alerts[currentAlert-1 ].activeAlertsSignificance );
168
180
}
169
181
// Map meteoalarm level to the field for significance for consistency (used for European alerts)
170
182
if (currentKey == " level_meteoalarm" && isAlerts && isAlertEU) {
171
- activeAlertsSignificance[currentAlert-1 ] = value;
172
- Serial.print (" Meteo alert significance processed, value: " ); Serial.println (activeAlertsSignificance[currentAlert-1 ]);
183
+ alerts[currentAlert-1 ].activeAlertsSignificance = value;
184
+ Serial.print (" Meteo alert significance processed, value: " );
185
+ Serial.println (alerts[currentAlert-1 ].activeAlertsSignificance );
173
186
}
174
187
// For meteoalarms only (European alerts); attribution must be displayed according to the T&C's of use
175
188
if (currentKey == " attribution" && isAlerts) {
176
- activeAlertsAttribution [currentAlert-1 ] = value;
189
+ alerts [currentAlert-1 ]. activeAlertsAttribution = value;
177
190
// Remove some of the markup in the attribution
178
- activeAlertsAttribution [currentAlert-1 ].replace (" <a href='" ," " );
179
- activeAlertsAttribution [currentAlert-1 ].replace (" </a>" ," " );
180
- activeAlertsAttribution [currentAlert-1 ].replace (" /'>" ," " );
191
+ alerts [currentAlert-1 ]. activeAlertsAttribution .replace (" <a href='" ," " );
192
+ alerts [currentAlert-1 ]. activeAlertsAttribution .replace (" </a>" ," " );
193
+ alerts [currentAlert-1 ]. activeAlertsAttribution .replace (" /'>" ," " );
181
194
}
182
195
183
196
}
@@ -203,42 +216,6 @@ void WundergroundAlerts::startArray() {
203
216
204
217
}
205
218
206
- String WundergroundAlerts::getActiveAlerts (int alertIndex) {
207
- return activeAlerts[alertIndex];
208
- }
209
-
210
- String WundergroundAlerts::getActiveAlertsText (int alertIndex) {
211
- return activeAlertsText[alertIndex];
212
- }
213
-
214
- String WundergroundAlerts::getActiveAlertsMessage (int alertIndex) {
215
- return activeAlertsMessage[alertIndex];
216
- }
217
-
218
- bool WundergroundAlerts::getActiveAlertsMessageTrunc (int alertIndex) {
219
- return activeAlertsMessageTrunc[alertIndex];
220
- }
221
-
222
- String WundergroundAlerts::getActiveAlertsStart (int alertIndex) {
223
- return activeAlertsStart[alertIndex];
224
- }
225
-
226
- String WundergroundAlerts::getActiveAlertsEnd (int alertIndex) {
227
- return activeAlertsEnd[alertIndex];
228
- }
229
-
230
- String WundergroundAlerts::getActiveAlertsPhenomena (int alertIndex) {
231
- return activeAlertsPhenomena[alertIndex];
232
- }
233
-
234
- String WundergroundAlerts::getActiveAlertsSignificance (int alertIndex) {
235
- return activeAlertsSignificance[alertIndex];
236
- }
237
-
238
- String WundergroundAlerts::getActiveAlertsAttribution (int alertIndex) {
239
- return activeAlertsAttribution[alertIndex];
240
- }
241
-
242
219
int WundergroundAlerts::getActiveAlertsCnt () {
243
220
return activeAlertsCnt;
244
221
}
0 commit comments