Hello, I'm trying to read JSON data from "api.weaher.gov" and display it on my e-paper module. I managed to connect to api.weather.gov and read JSON data using my Wemos d1 mini. However, when I printout on the JSON data on the serial monitor, random parts of the data are missing. When read data, it seems to read all the characters of the JSON data but when I print out completed string, there are missing parts. I tried google it but I couldn't find anything about it... can you help me to find the problem? Thank you!!
Attached is the Serial output and below is the code.
On the Serial output, there should be more lines for number 7 but they are lost.
/*
HTTP over TLS (HTTPS) example sketch
This example demonstrates how to use
WiFiClientSecure class to access HTTPS API.
We fetch and display the status of
esp8266/Arduino project continuous integration
build.
Limitations:
only RSA certificates
no support of Perfect Forward Secrecy (PFS)
TLSv1.2 is supported since version 2.4.0-rc1
Created by Ivan Grokhotkov, 2015.
This example is in public domain.
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
StaticJsonDocument<10000> doc;
#ifndef STASSID
#define STASSID "Sorry"
#define STAPSK "Secret"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
//const char* host = "api.github.com";
const char* host = "api.weather.gov";
const int httpsPort = 443;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char fingerprint[] PROGMEM = "1ce610e06d392674ee443a469b449977aca3d472";
void setup() {
Serial.flush();
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
Serial.printf("Using fingerprint '%s'\n", fingerprint);
client.flush();
client.setFingerprint(fingerprint);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
String url = "/gridpoints/OKX/35,29/forecast";
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
long int time = millis(); // current time
long int wait = 1000 * 100; // wait 10 seconds before terminating the read process
char c = 0;
bool flag = false;
String line = "";
while ((time + wait) > millis())
{
while (client.available())
{
c = client.read();
if (c < 0x20) {
Serial.write('\\');
Serial.write(c+ 0x20);
Serial.write('\\');
Serial.println();
} else
Serial.write(c);
line += c;
if (c == '\0') continue;
}
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
DeserializationError error = deserializeJson(doc, line);
line = "";
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
JsonVariant properties = doc["properties"];
JsonArray periods = properties["periods"];
JsonObject num1 = periods[0];
String periodName = num1["name"];
Serial.println(periodName);
}
void loop() {
}

