Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
- IPAddress ip(192, 168, 1, 177);
- EthernetServer server(80);
- String readString;
- const int statusPin = 8;
- const int tempSensor = A0;
- const int lysSensor = A1;
- const int buzzerPin = 9;
- const int blaaLysPin = 7;
- const int rodLysPin = 6;
- void setup() {
- Serial.begin(9600);
- pinMode(statusPin, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- pinMode(blaaLysPin, OUTPUT);
- pinMode(rodLysPin, OUTPUT);
- Ethernet.begin(mac);
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- }
- int loggeData = 1;
- void loop() {
- int tempSensorVerdi = analogRead(tempSensor);
- float volt = (tempSensorVerdi / 1024.0) * 5.0;
- float temperatur = (volt - .5) * 100;
- float lysSensorVerdi = analogRead(lysSensor);
- EthernetClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- Serial.print(c);
- if (readString.length() < 100) {
- readString += c;
- }
- if (c == '\n') {
- Serial.println(readString);
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close");
- client.println("Refresh: 5"); // refresh the page automatically every 5 sec
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<head>");
- client.println("<title>Lab-7</title>");
- client.println("<meta charset=\"utf-8\"/>");
- client.println("</head>");
- client.println("<body>");
- if (loggeData == 1) {
- client.println("Temperatur: ");
- client.println(temperatur);
- client.println(" C");
- client.println("<br />");
- client.println("Lys: ");
- client.print(lysSensorVerdi);
- client.println("<br /><br />");
- digitalWrite(statusPin, HIGH);
- }
- else {
- digitalWrite(statusPin, LOW);
- }
- client.println("<a href=\"/?monitoron\"\"><button>Skru på målinger</button></a>");
- client.println("<a href=\"/?monitoroff\"\"><button>Skru på målinger</button></a>");
- client.println("<br />");
- client.println("<button id=\"btnBlaa\">Blå LED</button>");
- client.println("</body>");
- client.println("</html>");
- delay(1);
- client.stop();
- if (readString.indexOf("?monitoron") > 0) {
- loggeData = 1;
- }
- if (readString.indexOf("?monitoroff") > 0) {
- loggeData = 0;
- }
- readString = "";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement