Wildan S. Nahar
Published © MIT

Arduino + Ethernet Shield to Monitor Temperature

This project makes a thermometer using a thermistor.

IntermediateProtip3 hours28,807
Arduino + Ethernet Shield to Monitor Temperature

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
#include 'Ethernet.h'
#include 'SPI.h'

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 3000; // READING INTERVAL
float p = 0.00;
String data;

void setup() { 
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); 
  }
  delay(10000); // GIVE THE SENSOR SOME TIME TO START
}

void loop(){
  currentMillis = millis();
  if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
    previousMillis = currentMillis;
    p = (float) analogRead(A0) * (5.0 / 1023.0); // CONVERT TO ARDUINO READABLE VALUE;
    p = (float) -7.58 * p + 27.309; // CALIBRATION RESULT
  }
  data = "potentio=";
  data = data + p;

  if (client.connect("167.205.43.205",3500)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.println("POST /results HTTP/1.1"); // HTTP POST TO /results
    client.println("Host: 167.205.43.205:3500"); // SERVER ADDRESS HERE TOO
    client.println("Content-Type: application/x-www-form-urlencoded"); // DATA TYPE
    client.print("Content-Length: ");  
    client.println(data.length()); 
    client.println(); 
    client.print(data); 
  } 
  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  delay(5000); // 5 SECONDS DELAY
}

Code snippet #2

Plain text
#include 'Ethernet.h'
#include 'SPI.h'

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 3000; // READING INTERVAL
float p = 0.00;
String data;

void setup() { 
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); 
  }
  delay(10000); // GIVE THE SENSOR SOME TIME TO START
}

void loop(){
  currentMillis = millis();
  if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
    previousMillis = currentMillis;
    p = (float) analogRead(A0) * (5.0 / 1023.0); // CONVERT TO ARDUINO READABLE VALUE;
    p = (float) -7.58 * p + 27.309; // CALIBRATION RESULT
  }
  data = "potentio=";
  data = data + p;

  if (client.connect("167.205.43.205",3500)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.println("POST /results HTTP/1.1"); // HTTP POST TO /results
    client.println("Host: 167.205.43.205:3500"); // SERVER ADDRESS HERE TOO
    client.println("Content-Type: application/x-www-form-urlencoded"); // DATA TYPE
    client.print("Content-Length: ");  
    client.println(data.length()); 
    client.println(); 
    client.print(data); 
  } 
  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  delay(5000); // 5 SECONDS DELAY
}

Code snippet #3

Plain text
app.post('/results', function(req, res){
    var post = {}
    post.date = new Date(),
    post.temp = req.body.temp

    sql.query('INSERT INTO analog_read SET ?', post, function(err, results, fields){
        if(err) throw err;
        console.log('sent success with value : ', post.temp)
        res.json({'status':'success!'})
    })
})

Code snippet #4

Plain text
app.post('/results', function(req, res){
    var post = {}
    post.date = new Date(),
    post.temp = req.body.temp

    sql.query('INSERT INTO analog_read SET ?', post, function(err, results, fields){
        if(err) throw err;
        console.log('sent success with value : ', post.temp)
        res.json({'status':'success!'})
    })
})

Github

http://github.com/wildan3105/arduino-ethernet

Credits

Wildan S. Nahar

Wildan S. Nahar

0 projects • 9 followers
Instrumentation Physicst; Embedded system hobbyist

Comments