Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 5.98 KB | None | 0 0
  1.  
  2. <!doctype html>
  3. <html>
  4. <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.     <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
  7.         <link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
  8.         <link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
  9.         <script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
  10.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  11.        
  12.         <title></title>
  13.         <style type="text/css">
  14.                 p {font-size: x-large}
  15.                 button {
  16.                         display: block;margin: 5px 5px 5px 5px;width: 160px;height: 45px;
  17.                         font-size: 22pt;font-weight: bold;color: yellow;}
  18.                 body {
  19.                     max-width:720px;
  20.                     margin: auto;
  21.                 }
  22.                
  23.                
  24.                 table td, table th{
  25.                     border: 1px solid black;
  26.                     padding: 5px;
  27.                 }
  28.                
  29.                 .ct-chart {
  30.                     margin-bottom: 20px;
  31.                 }
  32.         </style>
  33. </head>
  34.  
  35. <body>
  36.         <header>
  37.                 <p STYLE="color: green;"><b>Control led from web with PubNub !</b></p>
  38.         </header>
  39.         <form method="GET">
  40.                 <input class="btn btn-success" id="switchOn" value="start reading" type="button">
  41.                 <input class="btn btn-danger" id="switchOff" value="stop reading" type="button">
  42.         </form>
  43.         <?php
  44.        
  45.                         $servername = "localhost";
  46.                        $username = "root";
  47.                        $password = "suskeenwiske2";
  48.                        // Create connection
  49.                        $conn = new mysqli($servername, $username,$password);
  50.                        // Check connection
  51.                        if ($conn->connect_error) {
  52.                                 die("Connection failed: " .
  53.                                                         $conn->connect_error);
  54.                         }
  55.                         echo "Connected successfully";
  56.                         $sql = "SELECT tijdstip, temperatuur, licht from data.voorbereidingExamen";
  57.                         $result = $conn->query($sql);
  58.                         if($result->num_rows > 0) {
  59.                                 echo "<table style='margin-bottom:50px;'>";
  60.                                 $graden = array();
  61.                                 $tijdstippen = array();
  62.                                 $lichtpercentages = array();
  63.                                 $i = 0;
  64.                                 echo "<tr>
  65.                                         <th>index</th>
  66.                                         <th>tijdstip</th>
  67.                                         <th>temperatuur</th>
  68.                                         <th>lichtpercentage</th>
  69.                                     </tr>";
  70.                                 while($row = $result->fetch_assoc()) {
  71.                                         echo "<tr><td>" . $i . "</td>";
  72.                                         array_push($graden, $row["temperatuur"]);
  73.                                         array_push($tijdstippen,$row['tijdstip']);
  74.                                         array_push($lichtpercentages, $row['licht']);
  75.                                         echo "<td>" . $row["tijdstip"] . "</td>";
  76.                                         echo "<td>" . $row["temperatuur"] . "°C</td>";
  77.                                         echo "<td>" . $row["licht"] . "%</td></tr>";
  78.                                         $i++;
  79.                                 }
  80.                                 echo "</table>";
  81.                         } else {
  82.                                 echo "0 results";
  83.                         }
  84.                         $conn->close();
  85.  
  86.                 ?>
  87.        
  88.        
  89.        
  90.         <!-- script voor grafiek te maken met chartist -->
  91.          <h3>Temperatuur</h3>
  92.          <div class="ct-chart  ct-perfect-fourth" id="temperatuur" ></div>
  93.          <h3>Lichtpercentage</h3>
  94.          <div class="ct-chart  ct-perfect-fourth" id="licht" ></div>
  95.                         <script>
  96.                                 var gradendata = $.map(<?php echo json_encode($graden); ?>, function(el) { return el});
  97.                                 var tijdstippenData = $.map(<?php echo json_encode($tijdstippen); ?>, function(el) { return el});
  98.                                 var lichtpercentageData = $.map(<?php echo json_encode($lichtpercentages); ?>, function(el) { return el});
  99.                                
  100.                                 for (i = 0; i < tijdstippenData.length; i++) {
  101.                                    newDate = new Date(tijdstippenData[i]);
  102.                                     tijdstippenData[i] = newDate.toUTCString();
  103.                                }
  104.  
  105.                                var data = ({
  106.                                        labels: tijdstippenData,
  107.                                        series: [gradendata]
  108.  
  109.                                });
  110.                                
  111.                                 var data2 = ({
  112.                                     labels: tijdstippenData,
  113.                                     series: [lichtpercentageData]
  114.                                 });
  115.                                
  116.                                new Chartist.Line('#temperatuur', data);
  117.                                 new Chartist.Line('#licht', data2);
  118.                        </script>
  119.    
  120.         <!-- including the latest PubNub JavaScript SDK -->
  121.         <script src="http://cdn.pubnub.com/pubnub-3.7.1.min.js"></script>
  122.         <script>
  123.         (function() {
  124.                 var channel = 'examen';
  125.                
  126.                 var p = PUBNUB.init({
  127.                         subscribe_key: 'sub-c-4fb85268-c12f-11e6-963b-0619f8945a4f',
  128.                         publish_key:   'pub-c-351f3ff6-ab9c-4c73-9104-09d018ad3bc1'
  129.                 });
  130.                 // Sending data
  131.                 $('#switchOn').on('mousedown', function start(){p.publish({
  132.                                 channel : channel,
  133.                                 message : {read: 1}
  134.                         });})
  135.                 $('#switchOff').on('mousedown', function stop(){p.publish({
  136.                                 channel : channel,
  137.                                 message : {read: 0}
  138.                         });})
  139.                 })();
  140.  
  141.         </script>
  142.  
  143. </body>
  144. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement