I'm starting with arduino and I've bought a ENC28J60 Ethernet Shield, and search for some sketch examples online. So i found this:
// A simple web server that turn an LED on or off"
#include "etherShield.h"
#include "ETHER_28J60.h"
int outputPin = 6;
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {192, 168, 1, 15}; // IP address for the webserver
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
e.setup(mac, ip, port);
pinMode(outputPin, OUTPUT);
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print("<h1><a href='/?led=off'>Arduino Web Remote</a></h1>");
if (strcmp(params, "?led=on") == 0)
{
digitalWrite(outputPin, HIGH);
e.print("<a href='?led=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED IS ON</button></a>");
}
else if (strcmp(params, "?led=off") == 0)
{
digitalWrite(outputPin, LOW);
e.print("<a href='?led=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED IS OFF</button></a>");
}
e.respond();
}
}
I tried this code and it perfectly worked. Then i tried to do my own, based on this, and it didn't work, 'cause the (params, "?led=on") apparently is not equal 0;
Here's my code:
#include "etherShield.h"
#include "ETHER_28J60.h"
int led = 6;
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};
static uint8_t ip[4] = {192, 168, 1, 15};
static uint16_t port = 80;
static byte gwip[4] = {192, 168, 25, 1};
ETHER_28J60 e;
void setup() {
e.setup(mac, ip, port);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
char* params;
if (params = e.serviceRequest()) {
e.print("<head><style>h1 {text-align:center; font-family:courier} body {background-color:lightgrey} button {background-color:red; border: 2px solid black; font-color:black;} button#off {background-color:white} p {text-align:center}</style></head><body><h1>Arduino Controle Web Teste</h1><p>
<a href=/?led=on><button>Led On</button></a>
<a href=/?led=off><button id=off>Led Off</button></a>
</p></body>");
if (strcmp(params, "?led=on") == 0) {
digitalWrite(led, 1);
e.print("
Les is on
");
} else if (strcmp(params, "?led=off") == 0) {
digitalWrite(led, 0);
e.print("
Led is off
");
}
Serial.println(strcmp(params, "?led=on"));
e.respond();
}
}