So I am currently trying to display an analog pin value to a webpage. All the circuit is is a variable resistor being fed 5V, connected to an analog pin so that the value can be varied. Here is my photon code:
#define pot_input A0
int analog_value = 0;
void setup(){
Particle.function("getval", getValue);
Particle.variable("analog_value", analog_value);
pinMode(pot_input, INPUT);
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);
}
void loop(){
}
int getValue(String cmd){
analog_value = analogRead(pot_input);
return 0;
}
Here is my html:
<!DOCTYPE html>
<html>
<head>
<script charset="utf-8" src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type=
"text/javascript">
</script>
<title></title>
</head>
<body>
<h1>Current Value at Pin A0:</h1><br>
<h3 id="val"><strong>NO VALUE YET</strong></h3>
<script type="text/javascript">
var deviceID = "MY_ID";
var accessToken = "MY_ACCESS_TOKEN";
var getFunc = "getval";
window.setInterval(function() {
requestURL = "https://api.spark.io/v1/devices/" + deviceID + "/" + getFunc + "/?access_token=" + accessToken;
$.getJSON(requestURL, function(json){
document.getElementById("val") = json.result + "units";
});
}, 1000);
</script>
</body>
</html>
The error that I’m getting from the particle API is the following:
{
"ok": false,
"error": "Variable not found"
}
Does anyone known why my function cannot be accessed? When I run particle list in the command line It appears as a function. I have checked my device id and access token about a million times, they are correct (initially I had an error saying they were wrong so I made sure to check). Any help is greatly appreciated, thanks!