WebServer Implementation

Hey everyone,

So I am working on a project that involves gathering force data that is transmitted wirelessly (using the virtual wire library) to a receiving Arduino Uno, which is then supposed to be uploaded to the webserver hosted on an ethernet shield. The problem is that data isn't constantly being sent, so I am experiencing timeouts with the body upload line in my HTML file. I was wondering if there was a way I could respond to AJAX XML requests with HTML in my Arduino sketch, or if there was some alternative to body upload I could write in my HTML file so that the page still loads in my browser?

Thanks,

Chris

I found this tutorial helpful for Ajax...http://blog.startingelectronics.com/arduino-web-server-tutorial/

That's the tutorial I've been using up to this point, which I have found very helpful. However it seems the AJAX tutorial needs a constant stream of data, while I will only be sending data to the client whenever a certain force threshold is breached. It appears to be causing a timeout, and I can't view the page on a browser. I tried sending the same data over and over until new data is obtained to try and circumvent this, but I'm still getting a timeout.

I've narrowed it down some more. I put in a Serial.println() within each loop and found that for whatever reason the client isn't available, so I can't even look into the HTTP requests. So i tried the Ethernet example sketch, which works perfectly. Any ideas as to why the client isn't available when I'm running my AJAX sketch?

Any ideas as to why the client isn’t available when I’m running my AJAX sketch?

My crystal ball says that have run out of memory. You seem, for instance, to have forgotten to post your code.

Hey Paul, here’s my code. I wasn’t sure if it was a browser issue or not so I wasn’t sure if I needed to post my code at first. This has the HTML file I’m loading from the SD card as well. The SD card has no problem initializing and the file can be found when going through setup()

AJAXWebServer.ino (9.04 KB)

mainPage.txt (1.87 KB)

For projects such as this you should NOT ce using an UNO to act as server (if that is what it real is) use a Yun (or of there IOT processor). All those blogs etc that use a uno are out of date! Forget them.

But remember your sever/client code goes on the linux side not on the avr.

Mark

                        webFile = SD.open("mainPage.htm");        // open web page file
                        if (webFile) {
                            while(webFile.available()) {
                                client.write(webFile.read()); // send web page to client
                            }
                            webFile.close();
                        }

Sending 512 byte packets containing 1 byte of payload is horribly inefficient.

However it seems the AJAX tutorial needs a constant stream of data, while I will only be sending data to the client whenever a certain force threshold is breached.

I don't see that. I see a response being returned every time that there is a request for data (as it should be).

Show us what the serial data looks like, and where you think the timeout is happening.

I have this chunk of code that I'm using to see whether or not a client is ever available

    EthernetClient client = server.available();  // try to get client
    Serial.println(client);

It prints a constant stream of zeros. When I try this block with the EthernetWebServer example sketch, I'll get an occasional 1, indicating a client is available to write to. I've seen different buffer implementations of the SD card file read which I plan on using once I can get the client to connect.

EthernetClient client = server.available();  // try to get client

That creates an object of type EthernetClient.

Serial.println(client);

What, exactly, do you expect that to print?

I’ve ran Serial.println(client) on other webserver examples, and it prints 1 whenever there is a client and data to be read from said client.

I would think that the print statement should write a 1 in my serial port monitor whenever I enter 192.168.1.177 in my web browser, as it does when I run other webserver examples. I’ve used the same IP address for all other example webservers I’ve tried, so I know my network isn’t the issue.

I would think that the print statement should write a 1 in my serial port monitor whenever I enter 192.168.1.177 in my web browser

What would you expect Serial.print(server); to print? Printing OBJECTS does not make sense.