简体   繁体   中英

Passing an Arduino Variable to JS

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.

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>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM