App_Simple_Webserver 1v3

Non-technical related questions should go here.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

App_Simple_Webserver 1v3

Postby Folknology » Wed Sep 08, 2010 4:32 pm

I would be interested to see if anyone else is having an issue running app_simple_webserver.1v3. Having setup the static ip information in Main.xc, building and running I get the following:

Code: Select all

INFO: Ethernet Rx Server init..
INFO: Ethernet Rx Server started..
Using static ip
dhcp_init
But I cannot get any response on the address to http requests.

When I build and run the app_xc2_firmware.1v3 it works perfectly.

Can anyone confirm the issue or is it particular to me or my setup?

I am also unsure why I see 'dhcp_init' when using static IP setup, I'm probably missing something obvious help!!

(I'm using 10.4 tools with an XC2)
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Postby Folknology » Wed Sep 08, 2010 4:42 pm

Just noticed something else weird about the App_Simple_Webserver 1v3, when I run it the XC2 LEDs are all partially turned on
russ
Junior Member
Posts: 7
Joined: Fri Dec 11, 2009 11:53 am

Postby russ » Thu Sep 09, 2010 2:36 pm

That output is all that I'd expect.

As the xc2_firmware is working I would suspect a configuration issue.

Can you try the IP address picked up by the xc2_firmware as the static IP in the simple_webserver?

Russ
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Postby Folknology » Thu Sep 09, 2010 2:45 pm

Yup I tried that static and dynamic configs.

I'm very close to solving this more shortly...
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Postby Folknology » Thu Sep 09, 2010 3:01 pm

Ok Think I got it now, or at least a couple of the issues :

1. the compiler settings in the Makefile are incorrect I added optimisation my setting are :

Code: Select all

XCC_FLAGS += -O3 -save-temps -g 
2. When I added a printstr("In http main loop") inside the main xhttp while loop it started working (the quantum observation fix!)...
I also found adding a delay in the loop fixed it like this :

Code: Select all

tmr when timerafter(t + 1000000) :> t;
On deeper examination I discovered there were obviously errant xtcp events occurring which the delay obscurred so I tried adding port filtering on the events, restricting connections to port 80 and this seems to do the trick.

here is the old broken version of xhttpd :

Code: Select all

void xhttpd(chanend tcp_svr) 
{
 xtcp_connection_t conn;

  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);
  httpd_init();
  xtcp_ask_for_event(tcp_svr);
  while(1) {
    select 
      {
      case xtcp_event(tcp_svr, conn):
        httpd_handle_event(tcp_svr, conn);printintln(conn.local_port);
        xtcp_ask_for_event(tcp_svr);
        break;    
      }	  

  }
}
here is the new fixed vs:

Code: Select all

void xhttpd(chanend tcp_svr) 
{
  xtcp_connection_t conn;

  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);
  httpd_init();
  xtcp_ask_for_event(tcp_svr);
  while(1) {
    select 
      {
      case xtcp_event(tcp_svr, conn):
        switch(conn.local_port)
          {
            case 80:
            httpd_handle_event(tcp_svr, conn);
            break;
           default:
            printintln(conn.local_port);
            break;
           }
        xtcp_ask_for_event(tcp_svr);
        break;    
      }

  }
}
Not sure what the errant events are they could be netbios or MSN/MDNS events on the network etc.. adding the port filtering is of course a good idea anyhow.

*Update actually the printint is just adding a delay which is solving or obscuring the issue and making it work. I will investigate further..
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Postby davelacey » Thu Sep 09, 2010 4:35 pm

Folknology wrote:Ok Think I got it now, or at least a couple of the issues :

1. the compiler settings in the Makefile are incorrect I added optimisation my setting are :

Code: Select all

XCC_FLAGS += -O3 -save-temps -g 
I'm surprised this makes a difference tbh. It may be useful to have optimizations on for the main http app but shouldn't change it from working to not working.

2. When I added a printstr("In http main loop") inside the main xhttp while loop it started working (the quantum observation fix!)...
I also found adding a delay in the loop fixed it like this :

Code: Select all

tmr when timerafter(t + 1000000) :> t;
On deeper examination I discovered there were obviously errant xtcp events occurring which the delay obscurred so I tried adding port filtering on the events, restricting connections to port 80 and this seems to do the trick.

here is the old broken version of xhttpd :

Code: Select all

void xhttpd(chanend tcp_svr) 
{
 xtcp_connection_t conn;

  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);
  httpd_init();
  xtcp_ask_for_event(tcp_svr);
  while(1) {
    select 
      {
      case xtcp_event(tcp_svr, conn):
        httpd_handle_event(tcp_svr, conn);printintln(conn.local_port);
        xtcp_ask_for_event(tcp_svr);
        break;    
      }	  

  }
}
here is the new fixed vs:

Code: Select all

void xhttpd(chanend tcp_svr) 
{
  xtcp_connection_t conn;

  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);
  httpd_init();
  xtcp_ask_for_event(tcp_svr);
  while(1) {
    select 
      {
      case xtcp_event(tcp_svr, conn):
        switch(conn.local_port)
          {
            case 80:
            httpd_handle_event(tcp_svr, conn);
            break;
           default:
            printintln(conn.local_port);
            break;
           }
        xtcp_ask_for_event(tcp_svr);
        break;    
      }

  }
}
The httpd code already filters on port (see httpd.c) and it shouldn't matter anyway, no other traffic should get to that thread. There is something strange going on here...
*Update actually the printint is just adding a delay which is solving or obscuring the issue and making it work. I will investigate further..
Oops. Missed that bit. This makes some sense. The port filtering is irrelevant but I have to say I'm a bit confused about why the delay is making a difference.

What OS are you using to connect to the webserver?

Regards,
Dave
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Postby Folknology » Thu Sep 09, 2010 4:53 pm

Hi Dave

I'm using linux (ubuntu)

Where in httpd.c does it filter the port?

And there is definitely MDNS config IFUP and IFDOWN requests on the network if I switch to xtcp_conn_or_config_event

Also when I add a printstr() before the http_handle_event() that makes it work and prints out 11 events.

Here is the expanded code using xtcp_conn_or_config_event for more info:

Code: Select all

void xhttpd(chanend tcp_svr) 
{
  xtcp_connection_t conn;

  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);
  httpd_init();
  //xtcp_ask_for_event(tcp_svr);
  xtcp_ask_for_conn_or_config_event(tcp_svr);
  while(1) {
    xtcp_conn_or_config_t event_type;
    xtcp_ipconfig_t ipconfig;
    xtcp_config_event_t config_event;
    select 
      {
      case xtcp_conn_or_config_event(tcp_svr,
                                     event_type,
                                     config_event, ipconfig,
                                     conn):
	//case xtcp_event(tcp_svr, conn):
	switch(event_type)
	  {
	  case XTCP_CONN_EVENT:
	      switch(conn.local_port)
		{
		case 80:
		  printstr("Conn event on port 80\n");
		  httpd_handle_event(tcp_svr, conn);
		  break;
		case MDNS_SERVER_PORT:
		  printstr("MDNS port\n");
		  break;
		case NETBIOS_PORT:
		  printstr("Netbios port\n");
		  break;
		default:
		  //printintln(conn.local_port);
		  printstr("Unknown port conn\n");
		  break;
		}
	      break;
	  case XTCP_CONFIG_EVENT:
            if (config_event == XTCP_IFUP) 
	      printstr("Config Event XTCP_IFUP\n");
	    else if (config_event == XTCP_IFDOWN)
	      printstr("Config Event XTCP_IFDOWN\n");
	    else 
	      printstr("Config Event other\n");
	    break;
	  default:
	    // other event
	    break;
	  }
        //xtcp_ask_for_event(tcp_svr);
	xtcp_ask_for_conn_or_config_event(tcp_svr);
        break;    
      }

  }
}
And its output for startup and single page request:

Code: Select all

INFO: Ethernet Rx Server init..
INFO: Ethernet Rx Server started..
Using static ip
dhcp_init
Config Event XTCP_IFDOWN
Config Event XTCP_IFUP
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Postby davelacey » Thu Sep 09, 2010 5:04 pm

Folknology wrote:Hi Dave

I'm using linux (ubuntu)

Where in httpd.c does it filter the port?
:oops: Oops. Sorry I was looking at the wrong version of the code. You are right it does not filter.

And there is definitely MDNS config IFUP and IFDOWN requests on the network if I switch to xtcp_conn_or_config_event
These are not MDNS. There are just events representing the ethernet link going up or down. You initially get an IFDOWN event on startup to show the link is down and when the phy comes up you get an IFUP event.

Also when I add a printstr() before the http_handle_event() that makes it work and prints out 11 events.

Here is the expanded code using xtcp_conn_or_config_event for more info:

Code: Select all

void xhttpd(chanend tcp_svr) 
{
  xtcp_connection_t conn;

  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);
  httpd_init();
  //xtcp_ask_for_event(tcp_svr);
  xtcp_ask_for_conn_or_config_event(tcp_svr);
  while(1) {
    xtcp_conn_or_config_t event_type;
    xtcp_ipconfig_t ipconfig;
    xtcp_config_event_t config_event;
    select 
      {
      case xtcp_conn_or_config_event(tcp_svr,
                                     event_type,
                                     config_event, ipconfig,
                                     conn):
	//case xtcp_event(tcp_svr, conn):
	switch(event_type)
	  {
	  case XTCP_CONN_EVENT:
	      switch(conn.local_port)
		{
		case 80:
		  printstr("Conn event on port 80\n");
		  httpd_handle_event(tcp_svr, conn);
		  break;
		case MDNS_SERVER_PORT:
		  printstr("MDNS port\n");
		  break;
		case NETBIOS_PORT:
		  printstr("Netbios port\n");
		  break;
		default:
		  //printintln(conn.local_port);
		  printstr("Unknown port conn\n");
		  break;
		}
	      break;
	  case XTCP_CONFIG_EVENT:
            if (config_event == XTCP_IFUP) 
	      printstr("Config Event XTCP_IFUP\n");
	    else if (config_event == XTCP_IFDOWN)
	      printstr("Config Event XTCP_IFDOWN\n");
	    else 
	      printstr("Config Event other\n");
	    break;
	  default:
	    // other event
	    break;
	  }
        //xtcp_ask_for_event(tcp_svr);
	xtcp_ask_for_conn_or_config_event(tcp_svr);
        break;    
      }

  }
}
And its output for startup and single page request:

Code: Select all

INFO: Ethernet Rx Server init..
INFO: Ethernet Rx Server started..
Using static ip
dhcp_init
Config Event XTCP_IFDOWN
Config Event XTCP_IFUP
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
Conn event on port 80
OK. That makes sense to me. You get two config events and then a load of events on port 80 which is what you want. I'm still confused about why the print causes it to go from working to not working I'm afraid. It's a problem we can't recreate here.

Dave
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Postby Folknology » Thu Sep 09, 2010 5:25 pm

I get it working also by replacing the printstr line with :

Code: Select all

tmr when timerafter(t + 10000000) :> t;
anything less than this ~delay results in it not working..

Dave have you tried using simple_webserver 1v3 to test it on an XC2?
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Postby davelacey » Fri Sep 10, 2010 10:21 am

Folknology wrote:I get it working also by replacing the printstr line with :

Code: Select all

tmr when timerafter(t + 10000000) :> t;
anything less than this ~delay results in it not working..

Dave have you tried using simple_webserver 1v3 to test it on an XC2?
Yes. Despite me looking at the wrong version source code about the filtering it was 1v3 on an XC-2 that was tested. Also this combination would have been tested at the release of the component and at the release of the 10.4 tools (as we do with all the components). We definitely can't recreate this unfortunately.

Hmm. I'll have a think about what would be a sensible way to debug it from your end.

Dave

Who is online

Users browsing this forum: No registered users and 0 guests