twitter
Search

Entries in ethernet (2)

Wednesday
Feb012012

Twitter-posting Kitty Dishes

For Adafruit/Instructables "Make it Tweet" challenge, I assembled a way for an Arduino microcontroller to monitor and post updates to Twitter when the cats eat, need food, and need water. Here's an overview video:

The complete project is posted on instructables, complete with source code and schematics.

Wednesday
Feb012012

Ethernet enabled server room thermometer

After my first "blinky" thermometer was taken down for looking "too unprofessional," I moved on to craft a more subtle (and functional) way to get the job done. This time,  with an Arduino Uno, an Ethernet Shield, and a DHT11 temperature sensor. The code is a combination of Ladyada's DHT code and the Arduino example Ethernet code with only tiny modifications. The enclosure was purchased at Jameco.

The result is monitored in Nagios and Cacti. If anyone builds one and needs help with Nagios/Cacti implementation, let me know.

The HTML output is intentionally boring so as to be easily readable by monitoring software:

TemperatureC: 28.00
TemperatureF: 82.40
Humidity: 53.00

Code:

/*
  Web  Server Thermometer

A simple web server that shows the value of a DHT11
using an Arduino Wiznet Ethernet shield. 

Circuit:
* DHT11 attached to pin 2
* Ethernet shield attached to pins 10, 11, 12, 13

Web server code: 
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe

DHT code written by ladyada
Public Domain

Combining the two by thoughtfix
July, 2011

*/

#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"

#define DHTTYPE DHT11   // DHT 11 
#define DHTPIN 2     // DHT pin

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x4B, 0x21 };
byte ip[] = { 192,168,1, 223 };

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Server server(80);
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  // start the Ethernet connection and the server:

  Ethernet.begin(mac, ip);
  server.begin();
  dht.begin();
}


void loop()
{
  // listen for incoming clients
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = t*1.8+32; 
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output the value of each analog input pin
          client.print("TemperatureC: "); 
          client.println(t);
          client.println("<br />");
          client.print("TemperatureF: "); 
          client.println(f);
          client.println("<br />");
          client.print("Humidity: "); 
          client.print(h);
          client.println("<br />");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}