I have found several codes that explain how to have data updated to a webserver via AJAX, but I can't seem to figure out how to have an external switch that is an input_pullup update the server with its current state:
For example: I press a button. The button goes goes Low. The esp device detects that it is low and performs some action including updating the webserver of its status via AJAX.
If i put in the loop
if (digitalRead button == LOW){
What goes here? to send the status to the webserver?
}
Here is a sample code that uses: AJAX to update the status after a button click, but how do i modify it to update the status of an external button?
AJAX is happening on your client, not your webserver. It is the client that sends requests and gets updated information. Pressing a button on the webserver may alter some state of the webserver but if the client doesn't ask, the webserver does not PUSH new information to the client. Your example of a timer is not the web server updating. The client sees the timer expire and issues another GET to the webserver to update.
Thanks for explaining. That does make more sense. So is there no way to have the webserver PUSH information to a client if say an external switch is triggered? Maybe this makes sense?
I think you have some misunderstanding about AJAX.
This is what I would do. Use php to update a database.
I don't have time to write the the whole code for it but you might be able to find a project like this online. I'll give you the basic steps for you to get an idea.
Setup a web server (Use something like XAMPP).
Create a MySQL database.
Create a .php file that updates the MySQL database by receiving data via a GET request.
Use your ESP8266 to send the GET request containing your data.
So when your ESP8266 sends data via a GET request, your .php file takes them and puts them in the database. Then you can show the data in the database on a webpage. You can also create an API and use AJAX to show it on a web page and update the data without refreshing the page.
If you have no idea about what I'm talking about, search YouTube with "Send Data From ESP8266 to MySQL Database" you will find so many projects and tutorials.
Thanks! It is a bit over my head, so I will be doing the google search you suggested!
I did come up with a a way to have the variables updated to a webserver with a time interval (AJAX). So I think now, I can create a String that is updated when my physical button is pressed which will in turn be updated on the webserver at the time interval in the code.....I do understand better now that it isn't pushing the information, but I am able to request it at a set time interval and then GET it with this: