Avoiding Ajax overload/server collapse in an Arduino/ESP8266 setting

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...

Answer №1

It has come to my attention that the ESP8266 is only able to handle one user at a time.

I recommend avoiding the use of the Keep-Alive header as it could potentially lead to issues.

client.println("Connection: keep-alive");

By setting the Keep-Alive, you are essentially keeping the connection open indefinitely, which may result in errors.

If your server has a session timeout set, using Keep-Alive will keep the session active continuously.

Furthermore, there is a timeout and maximum request limit for keep alive connections.

Given that you encounter this error intermittently, it seems likely that it relates to the server's timeout and maximum requests allowed via Keep-Alive.

Suggest removing the header and testing the system without it.

Answer №2

Give it a shot by utilizing a packet sniffer like Wireshark and capture the output in a screenshot.

Answer №3

Source: Link to tutorial

Remember to terminate the connection once your response is sent:

Terminating Connection: CIPCLOSE

Things are functioning properly! The key is closing the connection after data transmission. The CIPCLOSE command can be utilized for this purpose:

Utilize the command AT+CIPCLOSE= to close a specific channel. Therefore, the connection can be terminated using:

AT+CIPCLOSE=0

Answer №4

After extensive testing, I discovered that the ESP8266 is not equipped to handle continuous ajax updates. As a solution, I turned to websockets which proved to be much more reliable and stable for my project.

I found inspiration from this example: https://gist.github.com/bbx10/667e3d4f5f2c0831d00b

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating to a different page in the app following a document update: a step-by-step guide

I am facing an issue with a page where I am trying to print a specific DIV using the script below... function printReceiptDiv() { var divElements; if (vm.isDLR) { divElements = document.getElementById("DLRreportCont ...

From where was this color of the navigation bar derived?

As I delve into a site previously worked on by someone else, my task is to recreate the navigation they implemented. However, I am unable to locate in the source code what was used for the navigation background. The challenge lies in the fact that after m ...

"Exploring the concepts of inheritance in Typescript

I'm seeking answers regarding inheritance in TypeScript/JavaScript. Below is my base class (express controller router): abstract class BaseCtrl { abstract model; // Get all getAll = (req, res) => { this.model.find({}, (err, docs) => ...

Using table.column as a function in jQuery datatabbe is not supported

When using jquery datatable, I encountered an error stating "table.column is not a function." <script> $(document).ready(function() { var table = $('#lsotable').dataTable(); $("#lsotable thead th").each( function ( i ) { ...

Encountering a React.js issue when attempting to update data

When attempting to update fields with a given drugid, an error occurs. For example, selecting drugid as 1 and clicking the update button results in an error message stating 'localhost:8081/drug/1' not found. In the MongoDB database, there is also ...

Preventing JSON data from being altered in AngularJS by creating a duplicate copy

It seems like there might be an issue with my implementation of AngularJS. I am trying to create a copy of a JSON object on page load, generate a form using the original data, and then compare the two JSON objects when the submit button is pressed to deter ...

Delete outdated information using Google Apps Scripts when the date is less than the current date plus a specified number of days

I have a Google Sheet where I need to filter out entries based on the number of days since the last check. Specifically, I want to keep only those entries where the number of days since the last check is greater than 10. You can find the Sheet here. fu ...

The process of generating a querystring from a form using jQuery is not functioning as expected

I am attempting to send an AJAX request, but I am facing an issue where the query string I am trying to construct turns out to be empty. <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>This project dem ...

What is the best way to send a parameter from JavaScript to a UserControl?

Within my ASP.Net application, I have a UserControl named EmployeesUserControl that is displayed within a JQuery modal dialog. Prior to displaying the Employees, I need to provide a filter criteria indicating which entity the employee belongs to. My query ...

Crafting visually stunning interfaces with Material UI

I'm a beginner in Material Design and I could use some assistance with the following structure. Can anyone guide me on how to create this? https://i.stack.imgur.com/NpiVz.png I've managed to add a text box, but now I'd like to place a label ...

Typescript HashMap implementation with Lists as values

Currently delving into TypeScript, I am attempting to generate a collection in a manner akin to the following Java example: HashMap<String, List<String>> hashMap = new HashMap<String,List<String>>(); Struggling to locate any releva ...

How to host two Node.js socket.io projects on one URL

My Nodejs server is hosted on Amazon Lightsail. I have successfully connected to it and configured Apache for Nodejs. I am working with 2 Nodejs socket.io projects and I want to access both of them using a single URL. Below are the links in Nextjs: const ...

Observing a global object's attribute in Angular JS

Imagine you have an object in the global scope (yes, I know it's not ideal but just for demonstration purposes) and you wish to monitor a property of that object using Angular JS. var person = { name: 'John Doe' }; var app = angular.mod ...

Jquery and AJAX are struggling to load dynamic content when accessed locally

I have a keen interest in utilizing Ajax to dynamically load content into a div. While I have been using jQuery for a few months, my experience with Ajax is still limited. Recently, I came across a downloadable tutorial online that seemed promising here. H ...

Strange sequence of results coming from Vue.js

methods: { ShowWindow: function(QueryID) { this.$data.ID = QueryID; if(this.GetData()) { console.log("asdasd") } document.querySelector("#EditWindow").style.visibility = "visi ...

Tips for halting a MySQL database transaction within a NodeJS environment using expressJS

Recently, I encountered a coding challenge that involved managing a long database transaction initiated by a user. The scenario was such that the user inadvertently updated 20 million entries instead of the intended 2 million, causing a significant impact ...

determining the sorting behavior of columns in Datatables

While working on my table, I referred to a Datatbles tutorial that covers sorting the third column as a percentage value. // Setting up column search - adding a text input to each footer cell $('#p_table-id tfoot th').each(function ...

Submitting a Django form using AJAX technology

Here is my implementation of the new_registration view : def handle_registration_request(request): context = {} if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): language = Language.objects.get(key="EN ...

How to continuously submit a single form field with Jquery using setInterval?

After reviewing this jquery timer on jsfiddle, I must say it works quite effectively. However, my specific requirement is to submit a single form field at regular intervals. Consider the following HTML form structure: <form id="form"> <input ...

Vue components: Using `object[key]` as a prop does not trigger reactivity

I'm attempting to bind a value from an Object into the prop of a Component, but unfortunately it is not reacting as expected. Despite using $this.set, the reactivity issue persists. Below is my template: <div class="grid"> <emoji-card v-fo ...