App Inventor Automação com Android e Arduino EthernetShield

Olá Pessoal.

Já vi aqui no forum projectos de Automacao com arduino blueetooth e Android.

Porem ainda não encontrei nenhum projecto que invés de usar Bluetooth funcione com etherneshield.

Pesquisando um pouco na net encontrei este projecto:

---------------------------------CÓDIGO ARDUINO-------------------------------------

/*
Web Server

A simple web server that switches LED's on and off, based on input from an
Android App Inventor application

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* LED outputs attached to pins 5 and 6

created 13 Oct 2010
by Rogier van den Berg / rogiervandenberg.nl

*/

#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 };
byte ip[] = { 192,168,0, 201 };

//Settings for the two LED's
int ledPin = 5;
int ledState = LOW;
int powerLedPin = 6;
int powerLedState = LOW;

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);

void setup()
{
//Set the LED pins as output
pinMode(ledPin, OUTPUT);
pinMode(powerLedPin, 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!
digitalWrite(powerLedPin, HIGH);
}

void loop()
{
//Make sure requests are taken care of
handleIncomingInstruction();

//Make sure the power led stays on, when nothing happens.
if(powerLedState == LOW)
switchPowerLed();
}

void handleIncomingInstruction()
{
// listen for incoming clients
Client 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(c);
switchPowerLed();

// 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();
}
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 == "TestOpdracht")
switchLed();
}
}

void switchLed()
{
// 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);
Serial.println("We switchen de LED!");
}

void switchPowerLed()
{
// if the LED is off turn it on and vice-versa:
if (powerLedState == LOW)
powerLedState = HIGH;
else
powerLedState = LOW;

// set the LED with the ledState of the variable:
digitalWrite(powerLedPin, powerLedState);
}

------------------------------------------------ FIM ------------------------------------------

Código para app inventor para o abrir basta no app inventor fazer:

My projectos-->More Actions-->Upload Source

DOWNLOAD CODIGO APP INVENTOR

---------------------- VIDEO DE DEMONSTRAÇÃO----------------------------------

https://www.youtube.com/watch?v=r7y0IpGhk_w

Ora bem o que este projecto faz é basicamente atraves de um Android com um programa apenas com um botao faz ligar e desligar o led.

Agora eu gostaria da vossa ajuda para o seguinte:

Eu pretendo que ao ligar o Led esse botão fique com a cor VERDE e ao desligar o led fique com a cor Vermelha.

E pretendia também o seguinte: se o led tiver acesso e o botão verde, eu gostaria que ao desligar o equipamento android e voltar a ligar o programa, que ele veja o estado do led.. se ele tiver acesso aparece então a cor verde se tiver desligado, aparece vermelho.

Alguem me pode enviar o projecto já modificado com essa funcoes?

Ficaria muito grato.

Exibições: 19772

Responder esta

Respostas a este tópico

é possivel nesse codigo da mesma forma que quando a açao é realizada o botao muda de cor , ser enviado um sms para outro celular ?

é possível sim, resolvemos isso com um comando que envia o estado do pino, tipo um "checar" que é acionado a cada ação....

Olá,Renan,baseado neste código olha só o que eu fiz(http://labdegaragem.com/video/ligar-l-mpada-pelo-celular),qualquer dúvida manda aí,valew.

Olá cara,pode me se eupreciso entrar no site tiny web DB,para armazenar valores para colocar o ip do arduino como servidor?obrigado.sou iniciante ainda em app.

Rafael, o AI não envia/recebe como uma página da web. Portanto, qualquer alteração sem alguns cuidados no código pode não funcionar.

Olá,bruno,vc pode me dizer de que forma posso me comunicar com arduino e w5110 fora da intra net,pelo meu celular,construi esse braço e(http://labdegaragem.com/video/bra-o-rob-controle-remoto) e gostaria de controlar ele online.Obrigado.

Legal o projeto, podemos sim tentar fazer ele para controlar usando o AI + Arduíno via Internet até mesmo por comando de voz. Vamos ver o pessoal que estiver interessado em desenvolver algo parecido e vamos marcar um dia para reunir. Como falei com Lucas B., tenho já o programa pronto no AI e Arduino para fazer essa comunicação, mas gosto de ter um brainstorm com as pessoas para aprendizado. VLW

Blz,cara,marca aí,vamos compartilhar algumas idéias,VALEW...

Pessoal, seguinte: Estou criando um app no app inventor para controlar um clp Logo da siemens. O programa do clp ta blz pq ja fiz com outros aplicativos. Agora sobre app inventor sou marinheiro de primeira viagem. Consegui fuçando fazer a parte estrutural dos botões e paginas. O que ta pegando é a parte da comunicação. Alguem pode me ajudar? Não tenho idéia de como posso fazer

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço