Hello,
I'm working on a simple project, but I don't know nothing about GET POST methods, my code is mostly copy/paste...
Idea is at the moment I get connected to my home wifi, Arduino will do something (like turn on the outside lamp, but you know, possibilities are infinite).
at Android side, I'm thinking in run it from Trigger. So Trigger will run the address, or open an app wich will send the command to Arduino.
Trigger: https://play.google.com/store/apps/details?id=com.jwsoft.nfcactionlauncher
Arduino is currently running the following code:
IPAddress ip(192,168,0,126);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(81);
EthernetClient client;
void setup() {
pinMode(pinLamp, OUTPUT);
pinMode(pinGND, OUTPUT);
digitalWrite(pinGND, LOW);
// Open serial communications and wait for port to open:
Serial.begin(9600);
// 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
client = server.available();
if (client) {
writePage();
}
}
void writePage()
{
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
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') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("<font size=\"24\" face=\"arial\">Automacao residencial
");
client.print("Lampada externa: <a href=\"/H1\">ON</a> | <a href=\"/L1\">OFF</a>
");
client.print("Lampada escada: <a href=\"/H2\">ON</a> | <a href=\"/L2\">OFF</a>
</font>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
}
else { // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H1")) {
digitalWrite(pinLamp1, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L1")) {
digitalWrite(pinLamp1, LOW); // GET /L turns the LED off
}
if (currentLine.endsWith("GET /H2")) {
digitalWrite(pinLamp2, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L2")) {
digitalWrite(pinLamp2, LOW); // GET /L turns the LED off
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
when I put Arduino IP on my my web browser, it shows a page with 4 links, each one will execute the action for /L1, /H1, /L2, /H2.
Question is, how can I send it from Android without request an action from user?
If I make a script to send /L1 directly to Arduino, how it will looks like?
192.168.0.126/H1 or 192.168.0.126?H1, or neither, or both... some light?