Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DHT.h>
- #include <Ethernet.h>
- #include <SPI.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // RESERVED MAC ADDRESS
- EthernetClient client;
- IPAddress server(192,168,0,102); // IP Adres (or name) of server to dump data to
- #define DHTPIN 2 // SENSOR PIN
- #define DHTTYPE DHT11 // SENSOR TYPE - THE ADAFRUIT LIBRARY OFFERS SUPPORT FOR MORE MODELS
- DHT dht(DHTPIN, DHTTYPE);
- long previousMillis = 0;
- unsigned long currentMillis = 0;
- long interval = 250000; // READING INTERVAL
- float temperature = 0; // TEMPERATURE VAR
- float humidity = 0; // HUMIDITY VAR
- String data;
- void setup() {
- Serial.begin(115200);
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP");
- }
- dht.begin();
- delay(10000); // GIVE THE SENSOR SOME TIME TO START
- temperature = (float) dht.readTemperature();
- humidity = (float) dht.readHumidity();
- }
- void loop(){
- currentMillis = millis();
- if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
- previousMillis = currentMillis;
- temperature = (float) dht.readTemperature();
- humidity = (float) dht.readHumidity();
- }
- if (client.connect(server, 3306)) {
- Serial.print("temperature=" );
- Serial.println( temperature );
- Serial.print("humidity=" );
- Serial.println( humidity );
- Serial.println("-> Connected");
- if(client.connected()){
- // Make a HTTP request:
- client.print( "GET /add_data.php?");
- client.print("temperature=");
- client.print( temperature);
- client.print("humidity=");
- client.print( humidity);
- client.println( " HTTP/1.1");
- client.println( "Host: 192.168.0.102" );
- //client.println(server);
- client.println( "Connection: close" );
- client.println();
- client.println();
- client.stop();
- }
- }
- if (client.connected()) {
- client.stop(); // DISCONNECT FROM THE SERVER
- }
- delay(30000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
- }
- <?php
- // Connect to MySQL
- include("dbconnect.php");
- // Prepare the SQL statement
- $SQL = "INSERT INTO test.test.temperature (temperature ,humidity) VALUES ('".$_GET["temperature"]."', '".$_GET["humidity="]."')";
- // Execute SQL statement
- mysql_query($SQL);
- // Go to the review_data.php (optional)
- header("Location: review_data.php");
- ?>
- <?php
- $MyUsername = "root"; // enter your username for mysql
- $MyPassword = "fifa2005"; // enter your password for mysql
- $MyHostname = "localhost"; // this is usually "localhost" unless your database resides on a different server
- $dbh = mysql_pconnect($MyHostname , $MyUsername, $MyPassword);
- $selected = mysql_select_db("test",$dbh);
- ?>
- <html>
- <head>
- <title>Arduino Temperature Log</title>
- <style type="text/css">
- .table_titles, .table_cells_odd, .table_cells_even {
- padding-right: 20px;
- padding-left: 20px;
- color: #000;
- }
- .table_titles {
- color: #FFF;
- background-color: #666;
- }
- .table_cells_odd {
- background-color: #CCC;
- }
- .table_cells_even {
- background-color: #FAFAFA;
- }
- table {
- border: 2px solid #333;
- }
- body { font-family: "Trebuchet MS", Arial; }
- </style>
- </head>
- <body>
- <h1>Arduino Temperature Log</h1>
- <table border="0" cellspacing="0" cellpadding="4">
- <tr>
- <td class="table_titles">ID</td>
- <td class="table_titles">Date and Time</td>
- <td class="table_titles">Temperature</td>
- <td class="table_titles">Humidity</td>
- </tr>
- <?php
- // Retrieve all records and display them
- $result = mysql_query("SELECT * FROM temperature ORDER BY id ASC");
- // Used for row color toggle
- $oddrow = true;
- // process every record
- while( $row = mysql_fetch_array($result) )
- {
- if ($oddrow)
- {
- $css_class=' class="table_cells_odd"';
- }
- else
- {
- $css_class=' class="table_cells_even"';
- }
- $oddrow = !$oddrow;
- echo '<tr>';
- echo ' <td'.$css_class.'>'.$row["id"].'</td>';
- echo ' <td'.$css_class.'>'.$row["timestamp"].'</td>';
- echo ' <td'.$css_class.'>'.$row["temperature"].'</td>';
- echo ' <td'.$css_class.'>'.$row["humidity"].'</td>';
- echo '</tr>';
- }
- ?>
- </table>
- </body>
- </html>
- // Make a HTTP request:
- client.print( "GET /add_data.php?");
- client.print("temperature=");
- client.print( temperature);
- client.print("humidity=");
- client.print( humidity);
- // Make a HTTP request:
- client.print( "GET /add_data.php?");
- client.print("temperature=");
- client.print( temperature);
- client.print("&humidity=");
- client.print( humidity);
- #include <dht.h>
- #include <SPI.h>
- #include <Ethernet.h>
- EthernetClient client;
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- char server[] = "192.168.0.101";
- dht DHT;
- int interval = 5000; // Wait between dumps
- #define DHT11_PIN 2
- void setup()
- {
- Ethernet.begin(mac);
- Serial.begin(115200);
- //Serial.println("Humidity (%),tTemperature (C)");
- }
- void loop()
- {
- Serial.print("Temperature2 = ");
- Serial.print(DHT.temperature);
- Serial.println(" *C");
- Serial.print("Humidity = ");
- Serial.print(DHT.humidity);
- Serial.println(" ");
- // READ DATA
- //Serial.print("DHT11, t");
- int chk = DHT.read11(DHT11_PIN);
- if (client.connect(server, 80)) {
- client.print( "GET /diplomna/Arduino/add_data.php?");
- client.print("temperature=");;
- client.print( DHT.temperature );
- client.print("&&");
- client.print("humidity=");
- client.println( DHT.humidity );
- client.println( "HTTP/1.1");
- client.println( "Connection: close" );
- client.stop();
- Serial.println("CONNECTED");
- }
- else {
- // you didn’t get a connection to the server:
- Serial.println("–> connection failed/n");
- }
- delay(interval);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement