ESP8266 wdt reset on connection https
Posted: Wed Nov 23, 2022 11:07 pm
ESP8266 throws a wdt reset every time it attempts to connect to a specific public transit API:
I can connect with a browser: https://bustime.mta.info/api/siri/stop- ... .json?key=<MYKEY>&OperatorRef=MTA&MonitoringRef=MTA_401761&LineRef=MTA%20NYCT_M15%2B
Other ports (8080, 80) don't connect but don't trigger wdt either. Identical sketch connecting to a different API works fine. What am I missing?
Full code here, but never gets past connection attempt:
Code: Select all
if (!client.connect("bustime.mta.info", 443))
Code: Select all
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v000719f0
~ld
I can connect with a browser: https://bustime.mta.info/api/siri/stop- ... .json?key=<MYKEY>&OperatorRef=MTA&MonitoringRef=MTA_401761&LineRef=MTA%20NYCT_M15%2B
Other ports (8080, 80) don't connect but don't trigger wdt either. Identical sketch connecting to a different API works fine. What am I missing?
Full code here, but never gets past connection attempt:
Code: Select all
// get bus API key here: http://bt.mta.info/wiki/Developers/Index
// info SIRI API http://bt.mta.info/wiki/Developers/SIRIIntro
// Working URL: https://bustime.mta.info/api/siri/stop-monitoring.json?key=<MYKEY>&OperatorRef=MTA&MonitoringRef=MTA_401761&LineRef=MTA%20NYCT_M15%2B
const int vers = 101;
#include <WiFiManager.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
// ************* settings
const String busStopID = "401761"; const String busStop = "2 AVE/E 68 ST";
//const String busStopID = "903093"; constString busStop = "1 AVE/E 1 ST";
// busLine = "LineRef=MTA%20NYCT_M15%2B"; //M15-SBS for both stops
const String busMTAkey = <MY_KEY>;
// ************* declares
WiFiClientSecure client; // For HTTPS requests
void setup() {
Serial.begin(115200); yield(); delay(900);
Serial.print("\n\nStarting MTA bus arrivals vers "); Serial.println(vers);
//****************** WiFi
WiFiManager wifiManager;
wifiManager.setTimeout(180);
Serial.println(F("Connecting to WiFi"));
if (!wifiManager.autoConnect("MTA bus arrivals")) {
Serial.println(F("Failed to connect to WiFi, config as AP at 192.168.4.1"));
}
Serial.println(F("connected...yeey :)"));
} // end setup()
//****************** loop()
void loop() {
getBusSchedule();
for (int i = 0; i < 600; ++i) {
yield();
delay(100);
}
}
//****************** get bus schedule https
void getBusSchedule() {
Serial.println(F("Updating bus schedule"));
client.setInsecure(); // needed for https
yield(); delay(200);
Serial.print(F("Connecting to bus host... "));
client.setTimeout(10000); // 1000 or 10,000 still ng, wdt ,
if (!client.connect("bustime.mta.info", 443)) { // wdt reset port 443; 8080 and 80 fail
Serial.println(F("Connection failed"));
return;
}
Serial.println(F("Connected!\n"));
// Send HTTP request. w id for a particular stop
client.print(F("/api/siri/stop-monitoring.json?key="));
client.print(busMTAkey);
client.print(F("&OperatorRef=MTA&MonitoringRef="));
client.print(busStopID); // bus stop, determines direction, etc
client.println(F("&LineRef=MTA%20NYCT_M15%2B")); // line M15-SBS
client.println(F(" HTTP/1.0"));
client.println(F("Host: bustime.mta.info"));
client.println(F("Connection: close"));
if (client.println() == 0) {
Serial.println(F("Failed to send request"));
client.stop();
return;
}
char status[32] = {0}; // Check HTTP status
client.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status, "HTTP/1.1 200 OK") != 0) {
Serial.print(F("Unexpected response: "));
Serial.println(status);
client.stop();
return;
}
char endOfHeaders[] = "\r\n\r\n"; // Skip HTTP headers
if (!client.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
client.stop();
return;
}
//****************** JSON filter and deserialize
// Stream& client;
StaticJsonDocument<200> filter;
filter["Siri"]["ServiceDelivery"]["StopMonitoringDelivery"][0]["MonitoredStopVisit"][0]["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedArrivalTime"] = true;
StaticJsonDocument<2048> doc;
DeserializationError error = deserializeJson(doc, client, DeserializationOption::Filter(filter), DeserializationOption::NestingLimit(12));
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
for (JsonObject Siri_ServiceDelivery_StopMonitoringDelivery_0_MonitoredStopVisit_item : doc["Siri"]["ServiceDelivery"]["StopMonitoringDelivery"][0]["MonitoredStopVisit"].as<JsonArray>()) {
const char* busArrivalTime = Siri_ServiceDelivery_StopMonitoringDelivery_0_MonitoredStopVisit_item["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedArrivalTime"];
printf("%s M15-SBS at %s ", busStop, busArrivalTime);
}
} // end getBusSchedule()