Teste
Posted on April 7, 2011 by admin| 52 Comments Updated! Arduino Ethernet code
Since last Arduino Ethernet code there we several Arduino IDE releases with changes that affected the code listed in this post. Due high interest, we updated it with minor changes that makes it work as expected. The biggest occurred because Wstring.h library isn’t no longer in use, because String.h library is included in core that brings some difference in several functions used in code.
In code we need to write readString += c; instead readString.append(c); if(readString.indexOf(“L=1″) >0) instead if(readString.contains(“L=1″))
Also we need to re-import Ethernet.h library in order to bring along all necessary libraries like Client.h, Server.h, SPI.h, Udp.h.
The other problem occurred when program run was that LED actually never lights up when checkbox is selected. I used Serial.print(c); to track down the problem. And it seems that method GET sends two strings:
Our code was catching and analyzing both strings. We only need to take string where parameter is sent: “GET /?L=1 HTTP/1.1” and skip “GET /favicon.ico HTTP/1.1”. As our example is very simple we can see ,that second string lacks “?” symbol. So we check the string if there is a ‘?’ symbol, of not, skip whole analyze.
And last fix is applied to LED checkbox. Now it stays checked if LED is ON. Hope you find these changes useful.
Here is a code listing: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | #include <SPI.h>#include <Client.h>#include <Ethernet.h>#include <Server.h>#include <Udp.h>byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac addressbyte ip[] = { 192, 168, 0, 110 }; // ip in lanbyte gateway[] = { 192, 168, 0, 1 };