@@ -30,7 +30,7 @@ See more at http://blog.squix.ch
3030WundergroundAlerts::WundergroundAlerts () {
3131
3232}
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) {
3434 currentAlert = 0 ;
3535 activeAlertsCnt = 0 ;
3636 isAlerts = true ;
@@ -41,11 +41,11 @@ void WundergroundAlerts::updateAlerts(String apiKey, String language, String cou
4141 isAlertUS = false ;
4242 isAlertEU = true ;
4343 }
44- doUpdate (" /api/" + apiKey + " /alerts/lang:" + language + " /q/" + country + " /" + city + " .json" );
44+ doUpdate (alerts, maxAlerts, " /api/" + apiKey + " /alerts/lang:" + language + " /q/" + country + " /" + city + " .json" );
4545}
4646// end fowlerk add
4747
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) {
4949 currentAlert = 0 ;
5050 activeAlertsCnt = 0 ;
5151 isAlerts = true ;
@@ -56,10 +56,12 @@ void WundergroundAlerts::updateAlertsPWS(String apiKey, String language, String
5656 isAlertUS = false ;
5757 isAlertEU = true ;
5858 }
59- doUpdate (" /api/" + apiKey + " /alerts/lang:" + language + " /q/pws:" + pws + " .json" );
59+ doUpdate (alerts, maxAlerts, " /api/" + apiKey + " /alerts/lang:" + language + " /q/pws:" + pws + " .json" );
6060}
6161
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;
6365 JsonStreamingParser parser;
6466 parser.setListener (this );
6567 WiFiClient client;
@@ -102,6 +104,7 @@ void WundergroundAlerts::doUpdate(String url) {
102104 }
103105 }
104106 }
107+ this ->alerts = nullptr ;
105108}
106109
107110void WundergroundAlerts::whitespace (char c) {
@@ -120,64 +123,74 @@ void WundergroundAlerts::value(String value) {
120123 if (currentKey == " type" && isAlerts) {
121124 activeAlertsCnt++;
122125 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 );
125129 }
126130 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 );
129134 }
130135 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 );
133139 }
134140 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 ;
139146 } else {
140- activeAlertsMessageTrunc [currentAlert-1 ] = false ;
147+ alerts [currentAlert-1 ]. activeAlertsMessageTrunc = false ;
141148 }
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 );
143151 }
144152 if (currentKey == " date" && isAlerts) {
145- activeAlertsStart [currentAlert-1 ] = value;
153+ alerts [currentAlert-1 ]. activeAlertsStart = value;
146154 // 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 ) {
148156 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 ));
150158 }
151159 // 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>" ;
154162 }
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 );
156165 }
157166 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 );
160170 }
161171 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 );
164175 }
165176 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 );
168180 }
169181 // Map meteoalarm level to the field for significance for consistency (used for European alerts)
170182 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 );
173186 }
174187 // For meteoalarms only (European alerts); attribution must be displayed according to the T&C's of use
175188 if (currentKey == " attribution" && isAlerts) {
176- activeAlertsAttribution [currentAlert-1 ] = value;
189+ alerts [currentAlert-1 ]. activeAlertsAttribution = value;
177190 // 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 (" /'>" ," " );
181194 }
182195
183196}
@@ -203,42 +216,6 @@ void WundergroundAlerts::startArray() {
203216
204217}
205218
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-
242219int WundergroundAlerts::getActiveAlertsCnt () {
243220 return activeAlertsCnt;
244221}
0 commit comments