Advertisement
PDP11

MonitorSwitch_1B_HTML

Apr 6th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. <!--
  2. This code sends $.get request to MonitorSwitch.ino on the core
  3.  
  4. -->
  5.  
  6. <!DOCTYPE html>
  7. <html>
  8.  
  9. <head>
  10. <title>Monitor Switch on SparkCore</title>
  11. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
  12. </script>
  13. </head>
  14.  
  15. <body>
  16.  
  17. <script>
  18. var sw1State;
  19.  
  20. //The setInterval() method will wait a specified number of milliseconds, and then execute a specified function,
  21. //and it will continue to execute the function, once at every given time-interval.
  22. window.setInterval(function(){MonitorSW1()},2000);
  23.  
  24. function MonitorSW1()
  25. {
  26. $.get("https://api.spark.io/v1/devices/123456789123456789ABCD/sw1?access_token=123456789123456789ABCD",function(data,status)
  27. {
  28. sw1State = data;
  29. for (var prop in sw1State) {
  30. console.log(prop+" "+sw1State[prop]);
  31. // alert(prop +" "+ sw1State[prop]);
  32. }
  33.  
  34. document.KettleState.text1.value = sw1State['result'];
  35. if(sw1State['result'])
  36. document.KettleOnOff.OnOff.value = "ON";
  37. else
  38. document.KettleOnOff.OnOff.value = "OFF";
  39.  
  40.  
  41. }).complete(function(){
  42. // alert("Data: " + sw1State['result']);
  43. return sw1State;
  44. });
  45. }
  46.  
  47. function toggle(button) {
  48. if (document.KettleOnOff.OnOff.value == "OFF") {
  49. document.KettleOnOff.OnOff.value = "ON";
  50. $.post("https://api.spark.io/v1/devices/123456789123456789ABCD/led?access_token=123456789123456789ABCD",
  51. {
  52. args:"l1,HIGH"
  53.  
  54. });
  55.  
  56. $.post("https://api.spark.io/v1/devices/123456789123456789ABCD/state?access_token=123456789123456789ABCD",
  57. {
  58. args:"sw1,HIGH"
  59.  
  60. });
  61.  
  62.  
  63. }
  64. else
  65. {
  66. document.KettleOnOff.OnOff.value = "OFF";
  67. $.post("https://api.spark.io/v1/devices/123456789123456789ABCD/led?access_token=123456789123456789ABCD",
  68. {
  69. args:"l1,LOW"
  70.  
  71. });
  72.  
  73. $.post("https://api.spark.io/v1/devices/123456789123456789ABCD/state?access_token=123456789123456789ABCD",
  74. {
  75. args:"sw1,LOW"
  76.  
  77. });
  78.  
  79. }
  80. }
  81.  
  82. </script>
  83.  
  84. <form name="KettleState" id="Kettle">
  85. <label for = "kettle">Kettle State</label>
  86. <!--<name="KettleState" id="Kettle">-->
  87. <INPUT type="text" id="text1" name="text1">
  88. </form>
  89.  
  90. <form name="KettleLevel" id="KettleL">
  91. <label for = "kettleL">Kettle Level</label>
  92. <INPUT type="text" id="text1" name="text1">
  93. </form>
  94.  
  95. <form name="KettleTemp" id="KettleT">
  96. <label for = "kettleT">Kettle Temp</label>
  97. <INPUT type="text" id="text1" name="text1">
  98. </form>
  99.  
  100. <!--
  101. <form name="KettleState" id="Kettle">
  102. <INPUT type="text" id="text1" name="text1">
  103. </form>
  104.  
  105.  
  106. <form name="KettleLevel" id="KettleL">
  107. <INPUT type="text" id="text1" name="text1">
  108. </form>
  109.  
  110. <form name="KettleTemp" id="Kettle">
  111. <INPUT type="text" id="text1" name="text1">
  112. </form>
  113. -->
  114. <form name="KettleOnOff" id="KettButt">
  115. <input type="button" id="OnOff" value="OFF" style="color:blue"
  116. onclick="toggle(this);">
  117. </form>
  118.  
  119.  
  120. </body>
  121.  
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement