I've recently been delving into Arduino programming to host an HTML/CSS/JavaScript webpage on an Adafruit HUZZAH ESP8266 breakout board. Please pardon any unconventional methods I may be using.
My approach involves utilizing Ajax to update pressure gauge values on a page, and while it initially works, I eventually encounter the ERR_CONNECTION_TIMED_OUT
error.
This issue arises frequently, especially during server startup. Resetting the WiFi card multiple times sometimes resolves the problem temporarily, but it remains unstable and problematic.
Furthermore, I've observed that the ESP8266 seems to support only one user at a time. When attempting to connect from another device, the server crashes, necessitating a reset to establish connection with the new host.
I'm seeking assistance in determining whether my use of Ajax is inefficient or if these challenges stem from limitations within the ESP8266 environment?
(Old Code removed to fit new code)
EDIT: I've made enhancements to my code in two key areas:
I consolidated numerous client.println() statements by storing HTML/CSS/JS content in separate char arrays, thereby reducing them to just four client.println() lines.
I minimized the number of Ajax calls from five down to one by sending all variables together in a comma-delimited string, which is then parsed to extract individual variable content.
Despite these improvements, I continue to face intermittent ERR_CONNECTION_TIMED_OUT errors. The randomness of these occurrences perplexes me; for instance, the server ran smoothly with consecutive successful Ajax calls for nearly two hours before generating errors, followed by immediate recurrence upon restarting the server within 30 seconds.
At this juncture, I am uncertain whether the inefficiency lies in my Ajax implementation or is inherent to the ESP8266's limitations?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Wire.h;
WiFiServer server(80);
WiFiClient client;
String HTTP_req;
String req;
double test = 42;
String LEDstatus = "off";
(Some variable initializations omitted for brevity)
char webpagePartOne[2500];
char webpagePartTwo[2500];
char webpagePartThree[2500];
char webpagePartFour[2500];
// Further code and functions follow...