Hello friends,
This is my first post, i'm working with Arduino for a while, and created a project to check the oil level of a energy generator (sorry if its wrong, but i don't know exactly how to translate this from my native language).
The point is, i'm trying to make a rev. 2. The first one showed just the result of 1 sensor (on and off).. Now i have to show on that page the results of 3 sensors.
I'm using this kind o sensor (http://ecx.images-amazon.com/images/I/41aijfptgnL._SY300_.jpg), and a Arduino Uno.
My actual code is:
#include <EtherCard.h>
#define STATIC 1 //Desativa DHCP
#if STATIC
static byte myip[] = { 192, 168, 10, 98 };
static byte gwip[] = { 192, 168, 10, 101 };
#endif
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
BufferFiller bfill;
int sensor = 3;
int vrd = 6;
int vrm = 7;
void setup() {
Serial.begin(57600);
Serial.println("\n[Iniciando...]");
pinMode(sensor, INPUT);
pinMode(vrd, OUTPUT);
pinMode(vrm, OUTPUT);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop() {
int estado = digitalRead(sensor);
Serial.print("");
Serial.println(estado);
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) // check if valid tcp data is received
if (estado == 0) {
ether.httpServerReply(pageoff()); // send web page data
}
else {
ether.httpServerReply(pageon()); // send web page data
}
if (estado == 0) {
digitalWrite(vrm, HIGH);
digitalWrite(vrd, LOW);
}
else {
digitalWrite(vrm, LOW);
digitalWrite(vrd, HIGH);
}
}
static word pageon() {
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<html>"
"<head><title>"
"LIGADO"
"</title></head>"
"<body>"
"<center>"
"<h3>LIGADO</h3>"
"</center>"
"</body>"
"</html>"));
return bfill.position();
}
static word pageoff() {
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<html>"
"<head><title>"
"DESLIGADO"
"</title></head>"
"<body>"
"<center>"
"<h3> DESLIGADO </h3>"
"</center>"
"</body>"
"</html>"));
return bfill.position();
}
I saw some projects that creates pages showing results, but i couldn't find a way to implement this.
The webpage must contain a result for each sensor, showing a text label like "sensor1up" or "sensor1down".