Go Down

Topic: Introducing the Webduino web server library (Read 22 times) previous topic - next topic

Glyphi

I've hacked your library to write to the serial port, the two headers are:

POST /buzz HTTP/1.1
Host: 192.168.111.64
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://192.168.111.64/buzz
Content-Type: application/x-www-form-urlencoded
Content-Length: 55

password=1&Puter=Tungsten&Action=Blip&PickleIt=PickleIt

POST /buzz HTTP/1.1
User-Agent: HTC_Touch_Diamond2_T5353 Opera/9.50 (Windows NT 5.1; U; en)
Host: 86.54.51.245
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: en-GB,en;q=0.9
Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Referer: http://86.54.51.245/buzz
Connection: Keep-Alive, TE
TE: deflate, gzip, chunked, identity, trailers
Content-Length: 55
Content-Type: application/x-www-form-urlencoded

password=1&Puter=Tungsten&Action=Blip&PickleIt=PickleIt

The first works, the second returns no parameters.

I'm going to check for line terminators now.

Yes, I'm on the 017 build, but have not yet started using ethernet2.

Glyn

Glyphi

No, no no....

Ignore me...

It has just started working, and I don't know why.

I hate that. It usually means that there is something lurking, just waiting to bite me on the bum at some mission critical time.

Thanks, for all your help - I've certainly learned loads in the process!

Glyn

Glyphi

Hmmm,

This code works...

int WebServer::read()
{
 if (m_pushbackDepth == 0)
 {
     int inn = m_client->read();
     Serial.print ((char) inn);
     return inn;
//    return m_client->read();
     }
 else
   return m_pushback[--m_pushbackDepth];
}

If I // the Serial.print it stops working again!


Are there any artefacts in Serial.print, possibly relating to CR or LF that you know of?

Glyn

(I tried putting in:
//      switch (inn)
//      {
//            case  '\n':
//                  Serial.print ("newline ");
//            case  '\r':
//                  Serial.print ("return ");
//            default:
//                  Serial.print ((char) inn);
//              }
but all looked identical and worked - thought each line endind in 'return newline return'

Ho humm.
)

Ben Combee

I don't think you want ethernet2 if you're on Arduinio 17... I think they incorporated a lot of those changes (can't verify right now).

The line terminator could be an issue.  The webduino code is looking for two CRLF pairs in a row to know that headers have ended.  You might want to modify the serial output to show a CR as "<CR>" and a LF as "<LF>\n" to see those.

Serial shouldn't change the character handling, but it might change the timing enough.  Maybe the read() routine needs a retry. with it checking server.connected() if it gets a -1.

Ben Combee

Try replacing the read routine with this:

Code: [Select]
int WebServer::read()
{
 if (m_pushbackDepth == 0)
 {
   while (m_client->connected())
   {
     int ch = m_client->read();

     // if we get a character, return it, otherwise continue in while
     // loop, checking connection status
     if (ch != -1)
       return ch;
   }

   // connection lost, return EOF
   return -1;
 }
 else
   return m_pushback[--m_pushbackDepth];
}


This may still need a timeout mechanism, but I bet it will be more reliable.  I've not tested this code yet, though.

Glyphi

Thanks, I can see what you are trying to do, but when I implement it the GET works, but when I press the button it just times out. It's too late at night here, I'll have a more informed play tomorow. Many thanks!

In the spirit I'm thinking of adding more debugging code - but C is really not my language of choice (or 30 years). And the gpaid work presses.

BTW the reason for doing this is to allow me to control the power switch on some remote machines and cycle the power on the UPS which occasionally causes trouble.

Y'all have fun

Glyn

Ben Combee

I spent a bunch of time on this tonight, and have updated the Webduino library to version 1.3.  You can get the new download from http://code.google.com/p/webduino/.

There were two problems:

1) if the client didn't send data quickly enough to the Arduino, it could drop the connection before getting all of the request.

2) after fixing that, I found that some clients would keep the connection open after sending all of a POST's content.  To fix this, I had to process the Content-Length header from POSTs and use that to terminate the connection from the server side.

I also added a define to get serial debug output for connections so you can see what gets requested from the Arduino and fixed a few other small issues with the code.

Glyphi

I gave it a try and it appears to be a step backwards. Sorry...

I'm going to drop back a version to get this device installed. I will only use to reboot machines when I'm away from home so firefox only is not a problem. With luck I'll get a spare set of boards next week and continue the debugging.

BTW, what do you use for debugging? or is just a case of serial.print?

Thanks for all your efforts, I hope to return to the fray soon.

Glyn

Ben Combee

Can you say how it's a step backwards?

For debugging, all I really can use is the serial output.  I was able to run the AjaxBuzzer code last night with the changes.

I was mainly testing with Firefox 3.5.2.

Ben Combee

Just reran tests with FF 3.6a1, Safari, Google Chrome, and IE 8 -- all worked with the 1.3 version.  I went ahead and marked 1.3 as beta on the site and put 1.2.1 back in the listing until I get a chance to try through my wireless router.

Glyphi

A quicky, since you appear to contemparaneously active. Apologies for the lack of info - laptop has been playing up all day.

Would switch to email, but my server is dead at the moment (hence the urgent reason for the board!).

So I'll try the 3 browsers I have ASAP and get info back.

y'all have fugn,

Glyn

Glyphi

This is a cut down version of my code
---------------------------

/* Web_Buzzer.pde - example sketch for Webduino library */

//#include "Ethernet.h"
#include <Ethernet.h>
#include <WebServer.h>


#define PWD "1"

static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

static uint8_t ip[] = { 192, 168, 111, 64 };
char msg[1000] = "Hello";

#define PREFIX "/minimal"
WebServer webserver(PREFIX, 80);

void buzzCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
 if (type == WebServer::POST)
 {
   bool repeat;
   char name[16], value[16];
   msg[0] = 0;
   
   do
   {
     repeat = server.readPOSTparam(name, 16, value, 16);
     strcat(msg, "<p>"); strcat(msg, name); strcat(msg, " - "); strcat(msg, value); strcat(msg, ".</p>");
     

   } while (repeat);
   server.httpSeeOther(PREFIX);
   return;
 }

 server.httpSuccess();

 if (type == WebServer::GET)
 {
   P(header) =
     "<html><head><title>Beetroot</title>"
     "<body>"
     "<div align='center'> "
     "<h1>Pickle the Beet!</h1>";
   P(message) =
     "<form action='/buzz' method='POST'>"
     "<p>"
     "<font +2"
     "<label for='password'>Password:</label>"
     "<input name='password' value='' type='text'  maxlength='20' />"
     "</p>"
      "<br>"
     "<label for='Puter'>Computer:</label>"
     "<select style=' width: 100px' size='1' name='Puter'>"
       "<option value='-'>-------------</option>"
       "<option value='Tungsten'>Tungsten</option>"
       "<option value='Hydra'>Hydra</option>"
       "<option value='UPS'>UPS</option>"
     "</select>"
     "<br>"
     "<br>"
      "<label for='Action'>Action:</label>"
    "<select style=' width: 100px' size='1' name='Action'>"
       "<option value='-'>-------------</option>"
       "<option value='Blip'>Blip</option>"
       "<option value='Bang'>Bang</option>"
     "</select>"
      "<br>"
    "<p><button type='submit' style='height: 100px; width: 100px' name='PickleIt' value='PickleIt'>PickleIt</button></p>"
      "</form></div>";
   P(foot) =
     "</body></html>";
     

   server.printP(header);
   server.printP(message);
   server.print(msg);
   server.printP(foot);
 }
}

void setup()
{

 Ethernet.begin(mac, ip);

 webserver.setDefaultCommand(&buzzCmd);

 webserver.begin();
}

void loop()
{
 // process incoming connections one at a time forever

 webserver.processConnection();
 
}
-------------------------------------
When I press the button in firefox it goes to reload and never ends. When you press the browser reload button you get:
Other
Location: /minimal

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8

<html><head><title>Beetroot</title> plus the rest of the html.

You get the if, after pressing the button yougo to the address bad and press return.

In IE when you press the button the screen clears, all appears to end but nothing is displayed. going to the address bar and hitting return gets you the page again.

In opera mobile you appeat to get the page redisplayed, but with no parameter info added. This is similar to previous behavior.

Would you like the ip address?

Glyn

Glyphi

Erm, what?

You get the if, after pressing the button yougo to the address bad and press return.

should read:

You get the same if, after pressing the button, you go to the address bar and press return.

Ben Combee

I just uploaded a 1.3.1 version that fixes this hang.

When I tested 1.3, I was using AJAX POST requests which had more headers then normal POSTs through HTML forms.  There was a bug when the last header sent was Content-Length where the server would hang.  I fixed this code and it worked for both the Web_Buzzer and Web_AjaxBuzzer examples.

Glyphi

Looks good after a simple test.

Many many thanks for all you efforts.

Glyn

Go Up