/*
Web Server
A simple web server that shows the value of a0,a1,a2 as three phase power in amps and oil temp using a Dallas 18b20.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A2 and digital pin2 for the dallas temp sensor
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
Modified again by Bill Allardyce
16 april 2015
*/
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor phase1; // Create an instance
EnergyMonitor phase2; // Create an instance
EnergyMonitor phase3; // Create an instance
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xDE};
IPAddress ip(10,113,130,202);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Start up the library
sensors.begin();
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
phase1.current(0,30); // Current: input pin, calibration.
phase2.current(1,30); // Current: input pin, calibration.
phase3.current(2,30); // Current: input pin, calibration.
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// 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("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 100"); // refresh the page automatically every 1 sec
client.println();
client.println("<!DOCTYPE HTML>");
sensors.requestTemperatures(); // Send the command to get temperatures
double Irms1 = phase1.calcIrms(1480);
double Irms2 = phase2.calcIrms(1480);
double Irms3 = phase3.calcIrms(1480); // Calculate Irms only
client.println("MFG SD Test Vacuum Pump");
client.println("<br />");
client.print("Ph1");client.println("<t/>");client.println("<t/>");client.println();client.println("<t/>");client.print("-Ph2");client.print("\t");client.println("<t/>");client.print("-Ph3");client.println("--C");client.println("--F");
client.print("<br />");
client.println(" ");client.println("<t\>");client.println(Irms1);client.println( );client.print(Irms2);client.println( ); client.print(Irms3); client.println( );client.println( );client.print(sensors.getTempCByIndex(0));
client.println( );client.print(sensors.getTempFByIndex(0));
//client.println(" ");
//client.println(" ");
//client.println("<br />");
//client.println(" ");
//client.println(" ");
//client.println("<br />");
//client.println(" ");
//client.println("<br />");
//client.println(sensors.getTempCByIndex(0));
//client.println("<br />");
//client.println(sensors.getTempFByIndex(0));
{
}
//client.println("</html>");
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();
Serial.println("client disconnected");
}
}
Comments