A aplicação fecha
]]>Qual erro?
]]>sim consigo!
server is at 192.168.0.177
new client
É isso que ele responde
client disconnected
new client
?led_offclient disconnected
new client
casa client disconnected
new client
teste de conexao client disconnected
new client
?led_onclient disconnected
Detalhe o aplicativo no android funciona apenas uma vez para que o arduino receba um outro comando tenho que fechar o aplicativo e abri-lo novamente.
——————————
Mas eu tenho outro aplicativo que foi feito no AppInventor que está funcionando com esse codigo do arduino e ele responde os seguintes informações.
server is at 192.168.0.177
new client
GET /?led_on HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; LG-D295 Build/KOT49I)
Host: 192.168.0.177
Connection: Keep-Alive
Accept-Encoding: gzip
client disconnected
new client
GET /?led_off HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; LG-D295 Build/KOT49I)
Host: 192.168.0.177
Connection: Keep-Alive
Accept-Encoding: gzip
Você consegue me dizer se no log do Serial aparece a conexão:
Serial.print(“server is at “);
Serial.println(Ethernet.localIP());
??
Segue o código que utilizei no arduino para ser feito um exemplo de conexão
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
*/
#include
#include
// 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
};
IPAddress ip(192, 168, 0, 177);
EthernetServer server(80);
const byte ledPin = A0;// Select pin for Main Light
String readString;
void setup() {
// Open serial communications and wait for port to open:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// 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();
if (readString.length() < 100)
{
readString = readString + c;// Store characters to string
}
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: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("”);
client.println(“”);
client.println(F(“Home Web Control”));
client.println(F(“Teste de Conexão Arduino UNO R3 Ethernet Shield Web Server”));
client.println(F(“WebServer teste de conexão”));
client.print(F(“”));
client.println(F(“”));
//client.println(F(“”));
client.println(F(“”));
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("”);
}
if(readString.indexOf(“/?led_on”) > 0) digitalWrite(ledPin, HIGH);
if(readString.indexOf(“/?led_off”) > 0) digitalWrite(ledPin, LOW);
readString = “”;// Clearing string for next read
client.println(“”);
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”);
}
}
Teria como você me enviar seu código?
]]>então estou trabalhando com o novo Android Studio e fiz estou programa que está aqui no blog para funcionar ele mas o que consegui foi apenas saber que o arduino está conectado ou não.
Eu escrevo um caracter no celular e envio mas não acontece nada no meu arduino pode me dar uma dica.
Pois fiz a mesma idéia do programa utilizando o App Inventor e funcionou mas com este exemplo que tem no site não.
Pode me ajudar?
]]>