alkopop79

Untitled

Nov 5th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <script type="application/javascript">
  2. function loadJSON()
  3. {
  4. var data_file = "https://agent.electricimp.com/xxxxxxxx-xxxxx"; //Insert link to your Agent here
  5. var http_request = new XMLHttpRequest();
  6. try
  7. {
  8. // Opera 8.0+, Firefox, Chrome, Safari
  9. http_request = new XMLHttpRequest();
  10. }
  11. catch (e)
  12. {
  13. // Internet Explorer Browsers
  14. try
  15. {
  16. http_request = new ActiveXObject("Msxml2.XMLHTTP");
  17. }
  18. catch (e)
  19. {
  20. try
  21. {
  22. http_request = new ActiveXObject("Microsoft.XMLHTTP");
  23. }
  24. catch (e)
  25. {
  26. alert("Something went wrong. :/");
  27. return false;
  28. }
  29. }
  30. }
  31.  
  32. http_request.onreadystatechange = function()
  33. {
  34. if (http_request.readyState == 4)
  35. {
  36. if (http_request.status == 200)
  37. {
  38. var jsonObj = JSON.parse(http_request.responseText);
  39.  
  40. if(jsonObj.coreInfo.connected)
  41. {
  42. document.getElementById("device").innerHTML = jsonObj.coreInfo.deviceID;
  43. document.getElementById("function").innerHTML = jsonObj.name;
  44. document.getElementById("result").innerHTML = Math.round((jsonObj.result/65535) * 100) + "%";
  45. }
  46. else
  47. {
  48. document.getElementById("device").innerHTML = "offline";
  49. document.getElementById("function").innerHTML = "&nbsp;";
  50. document.getElementById("result").innerHTML = "&nbsp;";
  51. }
  52. }
  53.  
  54. setTimeout("loadJSON()", 1000);
  55. }
  56. }
  57.  
  58. http_request.open("GET", data_file, true);
  59. http_request.send();
  60. }
  61.  
  62. window.onload=function()
  63. {
  64. loadJSON();
  65. };
  66. </script>
Advertisement
Add Comment
Please, Sign In to add comment