|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
I only get the 'favicon.i' if the serial monitor is open when the board first connects. Other than that just "HTTP" out of the serial monitor.
It did not appear on my DMM that either pin 7 or 8 was toggling with the webpage button presses (not sure if it's one or zero oriented). Will look into it more later. What I suspect is wrong here is that: 1. If you look there is only one call to serial to output from this code. 2. What you should see is what is in the buffer. 3. When you alter the form it fires a POST event. 4. That should cause the page to reload (with the same content). 5. During that post event parameters follow. 6. We both only see "HTTP". 7. However this is a POST so look at this link: http://www.jmarshall.com/easy/http/#postmethod (Link altered to something more related and friendly) 8. Therefore when the code reloads and tries to parse these parameters...it can not find what is not in the buffer. 9. Therefore the page simply reloads but does not change the pins (it thinks it's the first time you loaded it). 10. This *might* have worked for someone at some point but this is likely time sensitive. 11. The browser is doing all the work to display the HTML form. 12. When the browser toggles something it's just a silly drawing to the browser. 13. Even if this was a slider (it's a button) it would likely slide as you might expect. 14. Even if the browser does not successfully communicate the change it will tend to draw the changes. 15. HTTP is stateless so unless you put something more intelligent like Javascript in there you can't ask the browser after the fact what happened without another HTML form submission. 16. If your HTML forms never send valid data you are trapped in a vicious loop where things *appear* to be happening. This is a typical problem for web applications of any sort. Often form submissions recall the same code and that code needs to get parameters (either GET or POST). If that code does not get parameters HTTP is stateless so it thinks you were *never there before*. So since I am not the student here ![]() Put a serial print statement *inside* the conditional that toggles the pin. See if it ever prints. You sort of did this already above just put *only* the print statement not any additional conditionals. Then we can go from there. BTW when was this book you have written? Look at the copyright date. It's this book right: http://shop.oreilly.com/product/9780596802486.do Whistles innocently: https://bugzilla.mozilla.org/show_bug.cgi?id=260500 Last edited by techhelpbb : 08-02-2013 at 12:54 AM. |
|
#2
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Quote:
|
|
#3
|
||||
|
||||
|
Re: Arduino + Ethernet Shield Help
Try my suggestion above.
In the conditional already in the example code just try to print anything out the serial port. Things change and when someone writes a *tiny* webserver they sometimes forget that they control the part they write. They do not control the browser part that is written by someone to whom they have no immediate contact. So let's think about this: What happens when the browser part does something different then it did before? How does the example written in a hard copy book evolve when the authors and editors of the book can't predict the future? It doesn't. This code is obsolete (for people with current browsers) but it's actually not terribly hard to fix it. So let's do this step by step. Start with my request above. Tell us if you ever see that line print. Last edited by techhelpbb : 08-01-2013 at 06:01 PM. |
|
#4
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
So in the code line...
Code:
while(client.findUntil("PinD", "\n\r"))
{
int val = client.parseInt();
pinMode(8, OUTPUT);
digitalWrite(8, val);
}
Code:
while(client.findUntil("PinD", "\n\r"))
{
int val = client.parseInt();
pinMode(8, OUTPUT);
digitalWrite(8, val);
if(val == 1)
{
Serial.print("The LED is on")
}
else
{
Serial.print("The LED is off")
}
}
|
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||||
|
|||||
|
Re: Arduino + Ethernet Shield Help
Quote:
Will do, and will post results. |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||||
|
|||||
|
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¨ |
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||||
|
|||||
|
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) |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
|||||
|
|||||
|
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")? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|