GetData(){ if(wifi =="yes"){ // wake up wifi } // Define where the data will come from (FAA DIGITAL ATIS) ... // This is what the raw JSON data looks like from the datis API ... // [{"airport":"KMSP","type":"arr","code":"J","datis":"MSP ARR INFO J 1253Z. 01009KT 10SM SCT140 BKN180 BKN250 01/M04 A2981 // (TWO NINER EIGHT ONE) RMK AO2 SLP100 T00111044. VISUAL RWY 30L APCH IN USE, VISUAL RWY 30R APCH IN USE. NOTICE TO AIRMEN. // RWYS 4, 22 CLSD. CTN, BIRDS NEAR MSP. READ BACK HS AND ALT. ALL ACFT TAXI WITH TRANSPONDER AND ALTITUDE ENCODING ON. // ...ADVS YOU HAVE INFO J."},{"airport":"KMSP","type":"dep","code":"Y","datis":"MSP DEP INFO Y 1253Z. 01009KT 10SM SCT140 // BKN180 BKN250 01/M04 A2981 (TWO NINER EIGHT ONE) RMK AO2 SLP100 T00111044. DEPARTING RWY 30L, RWY 30R. NOTICE TO AIRMEN. // RWYS 4, 22 CLSD. ALL ACFT CTC GND METERING ON ONE THREE THREE POINT FIVE SEVEN WHEN READY TO PUSHBACK OR TAXI. CTN, // BIRDS NEAR MSP. READ BACK HS AND ALT. ALL ACFT TAXI WITH TRANSPONDER AND ALTITUDE ENCODING ON. ...ADVS YOU HAVE INFO Y."}] String serverPath = "https://datis.clowd.io/api/KMSP"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); if(httpResponseCode>0){ Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); //Serial.println(payload); // Clear buffer space for the Json document ... DynamicJsonDocument doc(2048); // Length (with one extra character for the null terminator) int str_len = payload.length() + 1; // Prepare the character array (the buffer) char json[str_len]; // Copy it over payload.toCharArray(json, str_len); // Deserialize the JSON document DeserializationError error = deserializeJson(doc, json); // Test if parsing succeeds. if(error){ Serial.print(F("deserializeJson() failed: ")); Serial.println(error.f_str()); return; } // The Json array will have two parts, arriving and departing. // Read each part and assign to a text string. // Arrival Runway(s) String arrive = doc[0]["datis"]; Serial.println(arrive); // Departure Runway(s) String depart = doc[1]["datis"]; Serial.println(depart); // Runway definitions for MSP // Zero them out ... they will stay zero unless they are found in the ATIS R4A=0; R4D=0; R22A=0; R22D=0; R12RA=0; R12LA=0; R12RD=0; R12LD=0; R17A=0; R17D=0; R35A=0; R35D=0; R30LA=0; R30RA=0; R30LD=0; R30RD=0; // This is the status LED runstat=4; // The end of each runway has six LEDs lighting either arriving or departing ... // These numbers are the LED (address) numbers on the LED Strip, // The address of the first LED to light on that runway. //R4A=11; //R4D=37; //R22A=42; //R22D=16; //R12RA=125; //R12RD=100; //R12LA=60; //R12LD=79; //R17A=133; //R17D=152; //R35A=158; //R35D=138; //R30LA=95; //R30LD=120; //R30RA=84; //R30RD=65; // When the JSON data is decoded and arrival and departure are separated, the two strings will now look like this ... // // String arrive = doc[0]["datis"]; // ========================================================================================================================================== // MSP ARR INFO J 1253Z. 01009KT 10SM SCT140 BKN180 BKN250 01/M04 A2981 (TWO NINER EIGHT ONE) RMK AO2 SLP100 T00111044. // VISUAL RWY 30L APCH IN USE, VISUAL RWY 30R APCH IN USE. NOTICE TO AIRMEN. RWYS 4, 22 CLSD. CTN, BIRDS NEAR MSP. // READ BACK HS AND ALT. ALL ACFT TAXI WITH TRANSPONDER AND ALTITUDE ENCODING ON. ...ADVS YOU HAVE INFO J. // // String depart = doc[1]["datis"]; // ========================================================================================================================================== // MSP DEP INFO Y 1253Z. 01009KT 10SM SCT140 BKN180 BKN250 01/M04 A2981 (TWO NINER EIGHT ONE) RMK AO2 SLP100 T00111044. // DEPARTING RWY 30L, RWY 30R. NOTICE TO AIRMEN. RWYS 4, 22 CLSD. ALL ACFT CTC GND METERING ON ONE THREE THREE POINT FIVE // SEVEN WHEN READY TO PUSHBACK OR TAXI. CTN, BIRDS NEAR MSP. READ BACK HS AND ALT. ALL ACFT TAXI WITH TRANSPONDER AND ALTITUDE ENCODING ON. // ...ADVS YOU HAVE INFO Y. // ========= DETERMINE DEPARTURE RUNWAYS ======================== // int dstart = depart.indexOf("DEPARTING"); int dstop = depart.indexOf(".", dstart); String drunway = depart.substring(dstart, dstop); // Serial.println(drunway); if(drunway.indexOf("4") > 0){ R4D=37; } if(drunway.indexOf("22") > 0){ R22D=16; } if(drunway.indexOf("12R") > 0){ R12RD=100; } if(drunway.indexOf("12L") > 0){ R12LD=79; } if(drunway.indexOf("17") > 0){ R17D=152; } if(drunway.indexOf("35") > 0){ R35D=138; } if(drunway.indexOf("30R") > 0){ R30RD=65; } if(drunway.indexOf("30L") > 0){ R30LD=120; } // ========= DETERMINE ARRIVAL RUNWAYS ======================== // int astart = 0; int newLine = 0; String arunway = ""; while(arrive.indexOf("APCH", astart) > 0){ newLine = arrive.indexOf("APCH", astart); astart = newLine + 1; arunway = arrive.substring(newLine - 5, newLine - 1); if(arunway.indexOf("4") > 0){ R4A=11; } if(arunway.indexOf("22") > 0){ R22A=42; } if(arunway.indexOf("12R") > 0){ R12RA=125; } if(arunway.indexOf("12L") > 0){ R12LA=60; } if(arunway.indexOf("17") > 0){ R17A=133; } if(arunway.indexOf("35") > 0){ R35A=158; } if(arunway.indexOf("30R") > 0){ R30RA=84; } if(arunway.indexOf("30L") > 0){ R30LA=95; } } // end of the while arrive loop // If all of them are zero, that means it did not read any data. // In the void loop it will make the status LED turn red if checking = 0 checking = R4A + R4D + R22A + R22A + R12RA + R12LA + R12RD + R12LD + R17A + R17D + R35A + R35D + R30LA + R30RA + R30LD + R30RD; // Display definitions for MSP on the serial monitor for testing // Use if you want to see which ones were found in the ATIS data. Serial.print("R4A: "); Serial.println(R4A); Serial.print("R4D: "); Serial.println(R4D); Serial.print("R22A: "); Serial.println(R22A); Serial.print("R22D: "); Serial.println(R22D); Serial.print("R12LA: "); Serial.println(R12LA); Serial.print("R12LD: "); Serial.println(R12LD); Serial.print("R12RA: "); Serial.println(R12RA); Serial.print("R12RD: "); Serial.println(R12RD); Serial.print("R17A: "); Serial.println(R17A); Serial.print("R17D: "); Serial.println(R17D); Serial.print("R35A: "); Serial.println(R35A); Serial.print("R35D: "); Serial.println(R35D); Serial.print("R30RA: "); Serial.println(R30RA); Serial.print("R30RD: "); Serial.println(R30RD); Serial.print("R30LA: "); Serial.println(R30LA); Serial.print("R30LD: "); Serial.println(R30LD); } // End of IF HTTP responded code else{ Serial.print("Error code: "); Serial.println(httpResponseCode); } // Free resources http.end(); } // End of GetData