Go Down

Topic: Reading a variable data from html-javascript to Arduino via ethernet shield (Read 296 times) previous topic - next topic



Need your assistance here, i am searching over the net for the past several weeks to learn and understand how to use the ethernet shield with the sd card to read an html file. The postings from https://startingelectronics.org/tutorials/arduino/arduino-MEGA-24-output-web-server/ was quite useful as my project is based on arduino mega; nevertheless as a learn startup point i am using UNO for the time being. Over the past several days; i came to understand that XML parsing seems to be more consuming of memory for UNO and better to use JSON.

I got stuck as i am not able to move further neither with JSON as the examples are not being given as a simple examble using ethernet shield. Most of them are using ESP8266.

I need your assistance in giving me a small code for me to parse the two variables "x" and "y" from the javascript (HTML) to arduino integer variables so that i can print the answer in serial monitor.

i have attached HTML file for your reference which has the variable shown "x" and "y" which i need to parse to arduino uno.

<!DOCTYPE html>
<html lang="en">

<input id="x">
<input id="y">
<button id="GO">ADD</button>

<div id="result"></div>

function add() {
var x = Number(document.getElementById('x').value);
var y = Number(document.getElementById('y').value);

document.getElementById('result').innerHTML = x+y;
return false;

document.getElementById('GO').addEventListener('click', add);



Please assist me



Are you trying to scrape a website with an Arduino or are you trying to interface an Arduino with an HTTP website in which you are writing the API?
Throw a little karma my way. What goes around comes around.


My objective is to find a simple method to pass the variable input from html to arduino .

I am using Ethernet shield and my html file is in the SD card. There are 2 variables x and y in the html JavaScript and I want to transfer the variable to arduino.


If you bind your HTML input elements to a form element you can have the browser make an HTTP GET request to your Arduino running the HTTP server after they have successfully submitted the form.

You would then have the values on your Arduino after handling the GET request.

If you did not want to use the form element, you could make the GET request asynchronously with AJAX.
Throw a little karma my way. What goes around comes around.


Thanks for your response, can you write me a code for me with the above example.

I will play with it and can develop further.

Sorry for the trouble, but it will be a great help if you can


Post your Arduino server code you have running on your UNO. To serve an HTML page you are already running an HTTP server on your Arduino and probably already have the code to do what I have described up and running. You may have to write another handler or add some code to it, but in general, you've got the basic thing working if you can see an HTML page being served from your Arduino.

You have stated in your original post that you are using an UNO and the ESP8266 tutorials are not helpful. I would only be able to verify that my code works on an ESP8266 or ESP32 as these are the only microcontrollers I have.

The general concept is the same and I would be able to walk you through it seeing the HTTP server code that you have running on your Arduino UNO.
Throw a little karma my way. What goes around comes around.

Go Up