Hi.
I am building a project with a arduino Due that is to be a multiroom thermostat.
To control it, I want to use a web page with the Ethernet shield.
to extract data from arduino to web page, I want to use JSON and Jquery.
Note that I am a real newbe on both c+, HTML or jQuery.
So I follow step by step this video tutorial and tried adapt it to my needs :
It spit in 2 file the index.htm and main.js.
all the step by step was going good until it can to extrac data from the json data. the json var return ‘undefined’ like this:
here the code:
the index:
<DOCTYPE html>
<html>
<head>
<title>Home thermostat</title>
</head>
<body>
<h1>jquery get temperature</h1>
<h2>local temperature</h2>
<ul id="roomId">
</ul>
<script src="javascript/jquery.min.js"></script>
<script src="javascript/main.js"></script>
</body>
</html>
main.js
$(function(){
var $data = $('#roomId');
$.ajax({
type: 'GET',
url: 'http://192.168.0.110/ajax_inputs',
success: function(data) {
$.each(data, function(i, item){
$data.append('<li>Room: '+ item.name +' : ' + item.temperature +'</li>');
});
}
});
});
my json string have check ok with postman so I suppose it could have more with the buffer of ‘$data’ of something like that. but I post my json data anyway.
{"channels" : [{"name":"NAME 0","status":1,"canal":0,"temperature":22.70,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 1","status":0,"canal":1,"temperature":23.02,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 2","status":0,"canal":2,"temperature":22.74,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 3","status":0,"canal":3,"temperature":22.48,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 4","status":0,"canal":4,"temperature":22.55,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 5","status":0,"canal":5,"temperature":22.63,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 6","status":0,"canal":6,"temperature":22.68,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 7","status":0,"canal":7,"temperature":22.68,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 8","status":0,"canal":8,"temperature":0.00,"setPoint":5.00,"permission":0,"percentOut":0},{"name":"NAME 9","status":0,"canal":9,"temperature":-50.00,"setPoint":5.00,"permission":0,"percentOut":0}]}
Thanks.