Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. tblUser
  2. userID INT
  3. userEmail VARCHAR(50)
  4. userMINThreholdVal FLOAT(4,2)
  5. userMAXThreholdVal FLOAT(4,2)
  6. tblTempReading
  7. userID INT
  8. thermID CHAR(3)
  9. tempTimeStamp TIMESTAMP
  10. temp FLOAT(4,2)
  11.  
  12. <!DOCTYPE html?
  13. <html>
  14. <?php header("refresh: 300;");?>
  15. <head>
  16. <title>FYP &mdash; Intelligent Temperature Control</title>
  17. <style type ="text/css">
  18. body{
  19. margin:0;
  20. padding:0;
  21. font-family: Sans-Serif;
  22. line-height: 1.5em;
  23. }
  24. main {
  25. padding-bottom: 10010px;
  26. margin-bottom: -10000px;
  27. float: left;
  28. width: 100%;
  29. }
  30. #nav {
  31. float: left;
  32. width: 230px;
  33. margin-left: -100%;
  34. padding-bottom: 10010px;
  35. margin-bottom: -10000px;
  36. background: #eee;
  37. }
  38. #wrapper {
  39. overflow: hidden;
  40. }
  41. #content {
  42. margin-left: 230px; /* Same as 'nav' width */
  43. }
  44. .innertube{
  45. margin: 15px; /* Padding for content */
  46. margin-top: 0;
  47. }
  48. p {
  49. color: #555;
  50. }
  51. nav ul {
  52. list-style-type: none;
  53. margin: 0;
  54. padding: 0;
  55. }
  56. nav ul a {
  57. color: darkgreen;
  58. text-decoration: none;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div id="wrapper">
  64. <main>
  65. <div id = "content">
  66. <div class = "innertube">
  67. <h1>Intelligent Temperature Control</h1>
  68. <h2>User One</h2>
  69. <h3>Temperature Readings</h3>
  70. <?php date_default_timezone_set('Europe/Belfast');?>
  71. <?php echo "<p>Page Last Updated: " . date('d/m/Y h:i:s a',time()) . "</p>";?>
  72. <h3>Thermistor 1</h3>
  73. <?php include('thermReading1.php');?>
  74. <h3>Thermistor 2</h3>
  75. <?php include('thermReading2.php');?>
  76. <h3>Thermistor 3</h3>
  77. <?php include('thermReading3.php');?>
  78. </div>
  79. </div>
  80. </main>
  81. <nav id = "nav">
  82. <div class = "innertube">
  83. <h4>About</h4>
  84. <p> A project tasked with developing an affordable skin temperature logger
  85. that is accurate to 0.1&deg; that is widely available to the public.</p>
  86. <p>This LAMP web server has been set up on a Raspberry Pi that will disaply
  87. the readings that has been sent by the Arduino and ESP8266</p>
  88. </div>
  89. </nav>
  90. </div>
  91. <?php exec('sudo -u www-data python /var/www/userEmailNotification.py');?>
  92. <?php exec('sudo -u www-data python /var/www/userTwitterNotification.py');?>
  93. </body>
  94. </html>
  95.  
  96. <?php
  97. //thermReading1.php
  98. $servername = "localhost";
  99. $username = "myusername";
  100. $password = "mypassword";
  101. $dbname = "dbIntelligentTempControl";
  102. //create connection
  103. $db_handle = mysql_connect($servername,$username,$password);
  104. //**DEBUGGING**
  105. //echo "<p>connection to server opened</p>";
  106. $db_found = mysql_select_db($dbname,$db_handle);
  107. $thermID = "'T00'";
  108. $userID = "'1'";
  109. if($db_found)
  110. {
  111. $sql = "SELECT temp,tempTimeStamp FROM tblTempReading WHERE thermID=" . $thermID . " AND userID=" . $userID . " ORDER BY tempTimeStamp DESC LIMIT 1";
  112. $result = mysql_query($sql);
  113. while($db_field = mysql_fetch_assoc($result))
  114. {
  115. echo "<p>" . $db_field['temp'] . "</p>";
  116. echo "<p>" . $db_field['tempTimeStamp'] . "</p>";
  117. }
  118. }
  119. else
  120. {
  121. echo "<p>Database NOT Found</p>";
  122. }//endif
  123. mysql_close($db_handle);
  124. ?>
  125.  
  126. #!/usr/bin/python
  127. import smtplib
  128.  
  129. SMTP_SERVER = 'smtp.gmail.com'
  130. SMTP_PORT = 587
  131. GMAIL_USERNAME = 'mygmail@gmail.com'
  132. GMAIL_PASSWORD = 'myPW' #CAUTION: This is stored in plain text!
  133.  
  134. recipient = 'recipemail@hotmail.co.uk'
  135. subject = 'Exceeding Threshold Notification'
  136. emailText = 'testing'
  137.  
  138. emailText = "" + emailText + ""
  139.  
  140. headers = ["From: " + GMAIL_USERNAME,
  141. "Subject: " + subject,
  142. "To: " + recipient,
  143. "MIME-Version: 1.0",
  144. "Content-Type: text/html"]
  145. headers = "rn".join(headers)
  146.  
  147. session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
  148.  
  149. session.ehlo()
  150. session.starttls()
  151. session.ehlo
  152.  
  153. session.login(GMAIL_USERNAME, GMAIL_PASSWORD)
  154.  
  155. session.sendmail(GMAIL_USERNAME, recipient, headers + "rnrn" + emailText)
  156. session.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement