1

This may be a very simple question for someone out there.

Say I have an int Arduino vairble:

int sensorData = analogRead(sensorPin);

How would I be able to pass that as a JS variable?

client.println("<script> var dat = sensorData </script>"); // this is what I have tried

For more context, I am trying to pass the variable to update a webpage heading; which does work if I pass in a JS variable, but not an Arduino one:

client.println("<h1 id=\"sensorData\"> %SENSORDATA% </h1>");
client.println("document.getElementById(\"sensorData\").innerHTML = dat");

Any help would be greatly appreciated.

1 Answer 1

1

The client class has the print and printLn functions.

so you should be able to split it up and do something like:

client.print("<h1 id=\"sensorData\"> ");
client.print(sensorData);
client.println(" </h1>");
Sign up to request clarification or add additional context in comments.

2 Comments

client.print("<script> var dat = ") ; client.print (sensorData); ... should work as well, if you really want/need it. (see the difference?)
Worked a treat. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.