Ethernet shield with SD web server simple question

I’m trying to use arduino with ethernet shield and SD card as web server, following the examples of Arduino Ethernet Shield Web Server Tutorial.

I’ve managed to create a web page and send various values from arduino to the server using the following:


data_t_out = this.responseXML.getElementsByTagName(‘analog’)[0].childNodes[0].nodeValue;
data_t_in = this.responseXML.getElementsByTagName(‘analog’)[1].childNodes[0].nodeValue;
data_hum = this.responseXML.getElementsByTagName(‘analog’)[2].childNodes[0].nodeValue;
data_barom = this.responseXML.getElementsByTagName(‘analog’)[3].childNodes[0].nodeValue;

arduino side







However, when I’m adding 4 strings:

in index.html and before the final cl.print("");

short_term = this.responseXML.getElementsByTagName(‘meteo’)[0].childNodes[0].nodeValue;
short_term_extra = this.responseXML.getElementsByTagName(‘meteo’)[1].childNodes[0].nodeValue;
long_term = this.responseXML.getElementsByTagName(‘meteo’)[2].childNodes[0].nodeValue;
long_term_extra = this.responseXML.getElementsByTagName(‘meteo’)[3].childNodes[0].nodeValue;

and in arduino





the web page doesn’t get the strings.

I am really green regarding Java, AJAX, ecc, so please forgive my question.

I recommend you to use JSON format.
and set the Content-length header

Thanks for your recommendation, but my question was why, while it passes values for ‘analog’, it ignores the strings in ‘meteo’.

What does the complete responseXML XML instance look like? Does the browser show any errors?

No errors from the browser side. I managed to show the text strings with:

Previsione breve 1: ...

Previsione breve 2: ...

Previsione lunga 1: ...

Previsione lunga 2: ...

but I don’t know how to get the values and use them for other computations. I’ve tried with:

and no show on browser.

My ignorant question is how to assign a damn name to all those variables that I manage to send and use then elsewhere in the html or javascript code.

Your text strings contain markup, so they become an integral part of the DOM of the XML document you retrieve.

this.responseXML.getElementsByTagName(‘meteo’)[0].childNodes[0].nodeValue now tries to get the nodeValue of a

, not the nodeValue of a text node, so you either need a different query, or send text without HTML markup.

The quickest solution if you insist on using XML and want to keep the HTML markup is probably sending your text strings as CDATA sections, so something like:

cl.print("]] >");

I haven’t tested that for you, though.

Another option is to use this.responseText instead of this.responseXML, and get the response as plain text instead of XML.

normal is to use JSON

I really thank you for your replies. The code I used was published on the startingelectronics site (Arduino Analog Value Displayed on Gauge on Web Page), it worked for the gauges, I repeated the code for more gauges and it still worked, so I used it. The web server is in the SD card, it makes requests to arduino, arduino sends the data, the web page shows all dials correctly (about 10 of them) and everybody is happy. BUT ....(and this is a new but) I cannot find a way to use the variables arduino has sent. All of them, not just the string variables.
I know my Fortran, Pascal, C and Python but nothing about html and javascript. So I can leave the part that uses the variables for the gauges and try something else for the rest of the variables. Searching the internet was useless, that's why I asked the question here. I'm not a dummy but I can't invest time studying something I will not use again (and due to my age, I will forget in a few months) so I ask for help. The SD server must request various data (int, float, bool and strings) from arduino, arduino must send the data and lastly, the server must get the data in a way a html-java ignorant like me can use them again (as variables or arrays) without difficulties. A simple example SD server-side and arduino-side would be sufficient.
Again I thank you very very much.

In my project I have a web server and web page, but I don't know if it can help you. It has what you need but does it a little more complicated as the tutorial. Mainly on the server side the additional thing is that I use my StreamLib for buffering and chunked transfer encoding. On the browser side the complication is that I generate most of the page with Java Script.

the server Regulator/WebServer.ino at master · jandrassy/Regulator · GitHub

web file Regulator/Regulator/data at master · jandrassy/Regulator · GitHub