I have an LED matrix setup as a weather ticker, it grabs the forecast data for my area (as set in the url for weather.gov) I'd like to be able to open a webserver and change the lat / long for the url.
Is this doable?
here is the code Im currently using:
#include <ArduinoJson.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES 16
#define CLK_PIN D5
#define DATA_PIN D7
#define CS_PIN D8
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
uint8_t scrollSpeed = 25; // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 0; // in milliseconds
// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 1000
char curMessage[BUF_SIZE] = { "Getting WX Data. . ." };
char newMessage[BUF_SIZE] = { "" };
bool newMessageAvailable = false;
long currentMillis = 0;
// Current fingerprint for https://api.weather.gov
const uint8_t fingerprint[20] = {0x1C, 0xE6, 0x10, 0xE0, 0x6D, 0x39, 0x26, 0x74, 0xEE, 0x44, 0x3A, 0x46, 0x9B, 0x44, 0x99, 0x77, 0xAC, 0xA3, 0xD4, 0x72};
//ESP8266WiFiMulti WiFiMulti;
void setup()
{
Serial.begin(115200);
P.begin();
P.setIntensity(2);
//Serial.println("[WiFi] Set Mode -> Station");
//WiFi.mode(WIFI_STA);
//delay(2000);
//Serial.println("[WiFi] Mode = Station");
//delay(2000);
//delay(10);
WiFi.begin("#####", "########");
Serial.print("[WiFi] Connecting to My Net ...");
//Serial.print(ssid); Serial.print(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: \t");
Serial.println(WiFi.localIP());
getforecast();
P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
//getforecast();
}
void loop()
{
const uint32_t updatePeriod = (60L*10L*1000L); // milliseconds in an hour
static uint32_t lastUpdate = 0;
if (millis() - lastUpdate >= updatePeriod) {
lastUpdate = millis();
getforecast();
}
if (P.displayAnimate())
{
if (newMessageAvailable)
{
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
}
void getforecast()
{
Serial.print("\n\nShow New Message Available Flag...");
Serial.println(newMessageAvailable);
currentMillis = 0;
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setFingerprint(fingerprint);
HTTPClient https;
Serial.print("[HTTPS] begin...\n");
if (https.begin(*client, "https://forecast.weather.gov/MapClick.php?lat=29.584&lon=-98.553&FcstType=json"))
{
Serial.print("[HTTPS] GET...\n");
int httpCode = https.GET();
if (httpCode > 0)
{
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY)
{
//pass GET results to doc
String payload = https.getString();
//Serial.println(https.getString()); //show whole JSON feed
const size_t capacity = 2*JSON_ARRAY_SIZE(1) + 8*JSON_ARRAY_SIZE(15) + JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(7) + JSON_OBJECT_SIZE(11) + JSON_OBJECT_SIZE(12) + JSON_OBJECT_SIZE(20);
DynamicJsonDocument doc(capacity + 4500); //add in extra bytes for string duplication
//Serial.print(" Doc Buffer Size: ");
//Serial.println(capacity + 4500);
deserializeJson(doc, payload);
//DeserializationError error = deserializeJson(doc, payload); //not using error catch for now
//if (error)
//{
//Serial.print(F("deserializeJson() failed: "));
//Serial.println(error.c_str());
//return;
//}
//Serial.print("\n\nShow New Message Available Flag...");
//Serial.println(newMessageAvailable);
Serial.println("\n\nResult of buffer print");
char CurrentPeriodBuffer[1000]; //used in ealier test
strcpy(CurrentPeriodBuffer, doc["time"]["startPeriodName"][0].as<char*>());
strcat(CurrentPeriodBuffer, ", ");
strcpy(CurrentPeriodBuffer + strlen(CurrentPeriodBuffer), doc["data"]["text"][0].as<char*>());
strcat(CurrentPeriodBuffer, " ");
strcpy(CurrentPeriodBuffer + strlen(CurrentPeriodBuffer), doc["time"]["startPeriodName"][1].as<char*>());
strcat(CurrentPeriodBuffer, ", ");
strcpy(CurrentPeriodBuffer + strlen(CurrentPeriodBuffer), doc["data"]["text"][1].as<char*>());
strcat(CurrentPeriodBuffer, "As of: ");
strcpy(CurrentPeriodBuffer + strlen(CurrentPeriodBuffer), doc["creationDateLocal"].as<char*>());
Serial.println(CurrentPeriodBuffer);
strcpy(newMessage, CurrentPeriodBuffer);
//Serial.println(newMessage);
//Serial.print("newMessage length: ");
//Serial.println(strlen(newMessage));
newMessageAvailable = true;
//Serial.print("\n\nShow New Message Available Flag...");
//Serial.println(newMessageAvailable);
}
}
else
{
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
}
}
you can see the url "https://forecast.weather.gov/MapClick.php?lat=29.584&lon=-98.553&FcstType=json" has the lat / lon I'd like to change it to something like...
"https://forecast.weather.gov/MapClick.php?lat=$lat_var$&lon=$lon_var$&FcstType=json"
any help would be appreciated.
-J