Good evening everyone.
I’m trying to read the status of a led on a web page. It is programmed to turn on and off every 4 seconds. In particle console I get the values "1" and “0” respectively. But I can’t collect this data on a web page.
int ledPin = D7;
int statusPin;
void setup() {
pinMode(ledPin,OUTPUT);
Spark.variable("statusPin", &statusPin, INT);
}
void loop() {
digitalWrite(ledPin,LOW);
statusPin = digitalRead(ledPin);
Particle.publish("Status", String(statusPin) , PRIVATE);
delay(4000);
digitalWrite(ledPin,HIGH);
statusPin = digitalRead(ledPin);
Particle.publish("Status", String(statusPin) , PRIVATE);
delay(4000);
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="raphael.2.1.0.min.js"></script>
<script src="justgage.1.0.1.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
var accessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
var deviceID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var url = "https://api.spark.io/v1/devices/" + deviceID + "/statusPin";
function callback(status){
if(status == "sucess"){
if(statusPin == '0')
alert("on");
else{
alert("off");
}
g.refresh(statusPin);
setTimeout(getReading,1000);
}
}
function getReading(){
$.get(url, {access_token: accessToken}, callback);
}
</script>
</head>
<body>
</body>
</html>