I have a rpi that updates my db with its current time every 5 seconds this is saved in the variable cseen and changes every 5 minutes IF the board updates the db successfully. The point of this is if after 5 seconds the values are the same the board must have lost connection.
my code to check if the variable has changed is the problem here and is as follows:
<script>
var lastSeen = "";
var cseen = "";
setInterval(function(){
$.getJSON('temp.php',function(data){
tot = data.length;
for(var i = 0; tot > i; i++){
//console.log(data[i][0]);
cseen = data[i][1];
$("#temp" + i).html(data[i][0]);
if(cseen != lastSeen){
console.log("board " + i + "cseen:" + cseen +" lastSeen:"+ lastSeen);
console.log("board " + i + " Online");
}else{
console.log("board " + i + "cseen:" + cseen +" lastSeen:"+ lastSeen);
console.log("board " + i + " Offline");
}
lastSeen = cseen;
}
//console.log(data.length);
//$(".temp").html(data.value);
})
},5000)
</script>
the output i receive from console is
(index):50 board 0cseen:1 lastSeen:1
(index):51 board 0 Offline
(index):50 board 1cseen:1 lastSeen:1
(index):51 board 1 Offline
(index):50 board 2cseen:1 lastSeen:1
(index):51 board 2 Offline
(index):50 board 3cseen:1 lastSeen:1
(index):51 board 3 Offline
(index):47 board 4cseen:Wed Feb 7 12:54:21 2018 lastSeen:1
(index):48 board 4 Online
(index):47 board 5cseen:1 lastSeen:Wed Feb 7 12:54:21 2018
(index):48 board 5 Online
(index):50 board 6cseen:1 lastSeen:1
(index):51 board 6 Offline
EDIT: Here is the json data logged to console:
(7) [Array(2), Array(2), Array(2), Array(2), Array(2), Array(2), Array(2)]
(2) ["400'C", "1"]
(2) ["20", "1"]
(2) ["30", "1"]
(2) ["60", "1"]
(2) ["46.2'C↵", "Wed Feb 7 13:00:44 2018"]
(2) ["70", "1"]
(2) [null, "1"]
The only board that is actually online and updating is board 5, please tell me what I am doing wrong, this is a pure logic problem