|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Somewhere you've lost a line...I highlighted it red.
The line you want to add is shown in green. Code:
if(strcmp(buffer,"POST ") == 0)
{
client.find("\n\r");
while(client.findUntil("PinD", "\n\r"))
{
int pin = client.parseInt();
int val = client.parseInt();
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
Serial.println("I saw the POST and toggled the pin!")
}
}
Just add the one green line to the original code. Be back in 2 or so hours....gotta go to a MORT thing..... Last edited by techhelpbb : 08-01-2013 at 06:50 PM. |
|
#2
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Quote:
Will do, and will post results. |
|
#3
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Make sure to put the semicolon at the end of the line I suggested you add.
Guess I nicked it off when I edited the color tags on my phone. Something to think about as you work this out: Code:
Press OFF button: FireFox 19.02 Internet browser sends: POST / HTTP/1.1 Host: 192.168.1.130 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://192.168.1.130/ Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 7 pinD8=0 Arduino Replies: HTTP/1.1 200 OK Content-Type: text/html HTML of web page follows. Press ON button: FireFox 19.02 Internet browser sends: POST / HTTP/1.1 Host: 192.168.1.130 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://192.168.1.130/ Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 7 pinD8=1 Arduino Replies: HTTP/1.1 200 OK Content-Type: text/html HTML of webpage follows. No sense in posting what the HTML looks like here. It's in the code and major browsers will let you view that as source. Take a good look at the code as supplied and picture what will happen when it reads that. As of last night around midnight I had this code fixed and working as it was intended. I just don't want to deprive anyone of the learning experience ![]() If time is pressing let me know and I'll just send the fixed code to look at. I wanted to address another statement previously made: 15 LEDs at 20mA each DC current limit. Driven at 50% duty cycle PWM so you can 'dim' them. Consume something like an average of 10mA. If the PWM is sychronized to all 15 LEDs on actual outputs (so this assumes your Arduino has enough digital I/O for this). Then that's 150mA. If the PWM signals are 'out of phase' with each other then it's possible this could be as low as 75mA. Let us assume the likely chance that it's 15 LEDs on 15 digial I/O at 75% duty cycle. That would, at least to your eye, look like they are almost fully powered on. So 15 LEDs are probably drawing close to 200mA out of the maximum typical drive of an Atmel AVR of 200mA. Since R/C hobby servos are usually connected to another circuit or shield. Since R/C hobby servos are often 6VDC for the motor which is a good reason for the additional circuit. It's likely the R/C hobby servo control presents a simple 5V CMOS input to the Arduino. Such an input draws a tiny current. Usually around 0.1mA or even less. So that means that you were hovering somewhere between 150mA and 201mA of total drive from the Atmel AVR with that setup. So previously when it was suggested that an Arduino was able to power 15 LEDs and servos off the same board from a USB port that wasn't entirely a fair assesment of the actual total drive power being demanded of the Atmel AVR on the Arduino itself. It seems unlikely that the servo power came from the USB port since they typically limit to 1A or even 500mA. So again be very careful with this. I can stack CMOS input shift registers on Arduino digital outputs. Heck I can stack I2C/SPI port expanders and other Arduinos on the digital ouputs of a single Arduino. So it is possible to have an enormous number of things controlled by a single Arduino. *However* always consider just how much current as a whole that will demand of the Atmel AVR on the Arduino. Device count alone can fool you easily. It is the context that actually matters. Also seeing as you've driven LEDs with PWM and know how to do that. Did you know you can drive the opto-isolator LED with PWM? The relay coil is really slow to respond. So you can save digital I/O current by driving the LED in the opto-isolators with PWM. Depends on how you do that. You could drive half of the relays low. Then the other half. So you could reduce 160mA to drive that 8 relay board you have to something like 80mA. Last edited by techhelpbb : 08-02-2013 at 12:10 PM. |
|
#4
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Sorry it took so long, I've been too busy to toy with this issue.
I added the Serial.print function where you indicated Code:
(if(strcmp(buffer,"POST ") == 0)
{
client.find("\n\r");
while(client.findUntil("PinD", "\n\r"))
{
int pin = client.parseInt();
int val = client.parseInt();
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
Serial.println("I saw the POST and toggled the pin!")
}
}
Except it added one character; Code:
HTTP favicon.i¨ |
|
#5
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Quote:
You did not get the message because you never get to that part of the loop. Look up at my last post. It shows what my FireFox browser sends to the board. Then look at the code you have. Specifically look at the inner conditionals that mention POST. Look before and look after that. There are several things wrong there. |
|
#6
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Quote:
Code:
if(client.find("/"))
Or how I added a space after POST in Code:
if(strcmp(buffer,"POST ") == 0) |
|
#7
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Nope it's not a single versus double quotation issue.
The first thing a browser will send you after you click the button is the following text: POST / HTTP/1.1 So remember the original code is trying to read what the browser sends and then act on that information. Plus the original code is obsolete. So if you look for "/" first what will you find? Now look at what it looks for next... Remember each time the Atmel AVR MCU takes a character from the ethernet chip's buffer that character is no longer available in the ethernet chip to read again. So if you look for the "/" first. Will you ever find "POST"? Last edited by techhelpbb : 08-06-2013 at 03:12 PM. |
|
#8
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Wait, I think I'm understanding now. Are you saying change the order of the if statements? Take this one
Code:
if(client.find("/"))
Code:
if(strcmp(buffer,"POST ") == 0) That way it looks for POST instead of the "/"? Or add a new if statement for if(client.find"POST")? |
|
#9
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Do you really need to look for: /
Does your *non existent* file system have any subfolders or other pages? Considering you know this is not going to be a full standards compliant webserver I submit to you that you do not need to look for anything other than POST. The first time you load the page the browser will use GET anyway. Now if you plan on actually parsing browser requests for several pages and returning error messages then yes at that point you should mind the: / For now how about you just look for the "POST". It's handy the code example already shows you how. Just get rid of the first conditional looking for the: / Use the client.find as demonstrated in the example to look for: POST Keep in mind that you'll loose that original serial debug when you do this because you should delete that as well. So be prepared to not see the "HTTP" or the "favicon.i" in the serial monitor. If you have not already: leave the serial debug line I offered above in your code. Let us save 'strcmp' for discussions on buffer security issues. You do not need that for this purpose at all. Also look at every occurance of 'PinD' you need them all to match when it comes to the case of the text. Last edited by techhelpbb : 08-06-2013 at 04:58 PM. |
|
#10
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
I no longer see HTTP or favicon.i.
I commented out the line saying if(client.find"/"). Whenever I click a button on the webpage the LED still does not work. However, the serial monitor displays "POST" when I click either button, and then about a second later is displays "GET". The "I saw the post and toggled the pin" still does not display though. EDIT: I saw you said make sure the case of PinD matches everywhere and looked and saw it didn't everywhere. Now the debug line prints on the serial monitor (I saw the POST and toggled the pin!) However, no LED. ANOTHER EDIT: I forgot that I changed one of the lines to say; Code:
client.println(" value='LOW'><input type='submit' value='On'/></form>");
client.println(" value='HIGH'><input type='submit' value='On'/></form>");
Last edited by jwallace15 : 08-06-2013 at 05:56 PM. |
|
#11
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Fantastic
Post up your Arudino code because if you Google around you'll discover that this book and that example has had quite a few people scratching their heads. Just remember: this is no Microsoft Internet Information Server or Apache web server. It is more like the old SitePlayer (only SitePlayer was a lot more polished): http://www.netmedia.com/siteplayer/webserver/sp1.html It has no SSL. It has no authentication as you are using it. If the browsers change dramatically you will need to alter that code. Make sure you test that with all the browsers you need to use it with. |
|
#12
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Here is the final working code;
Code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,130 };
const int MAX_PAGENAME_LEN = 8;
char buffer[MAX_PAGENAME_LEN+1];
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
delay(2000);
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
int type = 0;
while (client.connected())
{
if (client.available())
{
memset(buffer,0, sizeof(buffer));
//if(client.find("/"))
if(client.readBytesUntil('/', buffer,sizeof(buffer)))
{
Serial.println(buffer);
if(strcmp(buffer,"POST ") == 0)
{
client.find("\n\r");
while(client.findUntil("PinD", "\n\r"))
{
int pin = client.parseInt();
int val = client.parseInt();
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
}
}
sendHeader(client,"Post example");
client.println("<h2>Click buttons to turn pin 8 on or off</h2>");
client.print(
"<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
client.println(" value='0'><input type='submit' value='Off'/></form>");
client.print(
"<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
client.println(" value='1'><input type='submit' value='On'/></form>");
client.println("</body></html>");
client.stop();
}
break;
}
}
delay(1);
client.stop();
}
}
void sendHeader(EthernetClient client, char *title)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>");
client.print(title);
client.println("</title><body>");
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|