Talking to the network with an Arduino

Aus DL8RDS Wiki
(Weitergeleitet von Talking to the network)
Wechseln zu: Navigation, Suche

Well, even this is most certainly no longer related to my SWR meter project, I just find that it's sooooo cool, so I will simply present some code here.

1 Hardware

2 Related

3 The Sketch

#include <Server.h>
#include <Ethernet.h>
#include <Client.h>

#include <Wire.h>

#define address 0x48

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = {192, 168, 178, 190};
byte gateway[] ={192,168,178,1};
byte subnet[] = {255,255,255,0};
Server server = Server(80);

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
}

void loop()
{
  Client client = server.available();
  if (client) {
    Wire.beginTransmission(address);
    Wire.send(0x00);
    Wire.requestFrom(address, 1);
    int temperature;
    if (Wire.available()) {
      temperature = Wire.receive();
    }
    Wire.endTransmission();

    server.print("HTTP/1.0 200 OK\r\nServer: arduino\r\n");
    server.print("Content Type: text/html\r\n\r\n");
    server.print("Zimmertemperatur</head>\r\n");
     server.print("<body>Zimmertemperatur:<p>\r\n");
     server.print(temperature-4);
     server.print("<p>Uptime:");
     server.print(millis());
     server.print("ms.");
    delay(10);
    client.stop();
    Serial.println("-----------");
    Serial.println(temperature);
  }
}

It will show the room temperature of my lab. I used the above mentioned LM75 sensor from Horter and the Ethernet shield with the WIZnet Ethernet module that you can purchase from Watterott. Also have a look there:

http://www.mats-vanselow.de/arduino-ins-netz-bringen

Given that my controller grabs the temperature from the source via I2C, it would be no problem to connect several sensors over this bus. It would be possible to read out a huge number of data sources...