O meu codigo do arduino é:
#include <SPI.h>
#include <Ethernet.h>
// 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, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 75 }; // ip in lan
byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(6969);
//Settings for the two LED's
int ledPin = 5;
int ledState = LOW;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
void setup()
{
//Set the LED pins as output
pinMode(ledPin, OUTPUT);
//For debugging, set the Serial Output
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
//Turn one of the LED's on, to know it is ready to go!
}
void loop()
{
//Make sure requests are taken care of
handleIncomingInstruction();
//Make sure the power led stays on, when nothing happens.
}
void handleIncomingInstruction()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean newLine = true;
String line = "";
while (client.connected() && client.available()) {
char c = client.read();
//Serial.print©;
// 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' && newLine) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<body>");
client.println("<hr />");
client.print("<font size='5'>LED status: ");
if (ledState == LOW)
{
client.println("<font color='green' size='5'>0");
}
else
{
client.println("<font color='green' size='5'>1");
}
// auto reload webpage every 5 second
client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");
client.println("</body>");
}
if (c == '\n') {
// you're starting a new line
newLine = true;
evaluateLine(line);
line = "";
}
else if (c != '\r') {
// you've gotten a character on the current line
newLine = false;
line += c;
}
}
evaluateLine(line);
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void evaluateLine(String line)
{
if (line.startsWith("tag", 0)) {
String instruction = line.substring(4, line.length());
Serial.println(instruction);
if (instruction == "ligar")
ligar();
if (instruction == "desligar")
desligar();
}
}
void ligar()
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
void desligar()
{
// if the LED is off turn it on and vice-versa:
if (ledState == HIGH)
ledState = LOW;
else
ledState = HIGH;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
No entanto não tou a conseguir que o app inventor leia os seguintes valores:
if (ledState == LOW)
{
client.println("<font color='green' size='5'>0");
}
else
{
client.println("<font color='green' size='5'>1");
a minha estrutura esta assim:
ou seja o meu botao STATUS LED nao fica verde quando esta 1 nem vermelho quando esta zero.
no entanto quando eu acesso ao meu http://192.168.1.75:6969 aparece lá o estado 0 e 1
alguempode ajudar?
eu tou a ler o 0 e o 1 destas linhas
if (ledState == LOW)
{
client.println("<font color='green' size='5'>0");
}
else
{
client.println("<font color='green' size='5'>1");