WebServer - Further criticism (if you don't mind)

Hey all,

I have been rewriting and debugging in the last couple of days.

I have some code I wrote for the arduino (with ethernet shield) that processes webserver requests. It works a few times in a row before showing dodgy results when you request a webpage.

Each component when tested separately works without fail but when I put em together it shows unexpected results. I think I am having memory issues… perhaps not removing all items after each page request?

Could anyone willing please have a look and criticise where appropriate?

Project attached.

Thanks

WebServer.zip (3.99 KB)

First glance said there were a lot of strings in there.
They'd gobble up RAM.

I'd look at putting the fixed ones into PROGMEM.

AWOL:
I'd look at putting the fixed ones into PROGMEM.

Evening. Fixed ones?

The ones that you don't plan on changing.
Constants.

I don't think I use any?

There are some strings in webserver.pde but these are written directly to httpclient.

There are some strings in webserver.pde but these are written directly to httpclient

Are you suggesting that they don't consume RAM?

EDIT: just noticed who posted.
Bye.

I will look into this PROGMEM stuff, it sounds very useful... but I am not convinced this is the issue. It still acts strange when I comment out these const string lines.

Do I need to initialise Items along with Count in the constructor of the NameValueCollection?

class NameValueItem
{
  public:

  String Name;
  String Value;
  
  NameValueItem();
  ~NameValueItem();
};

class NameValueCollection
{
  public:

  unsigned int Count;
  NameValueItem Items[10];

  NameValueCollection();
  ~NameValueCollection();

  void Add(const String& Name, const String& Value);
  String& Item(const String& Name);
  String& Name(const unsigned int& Index);
  String& Value(const unsigned int& Index);
  boolean Exists(const String& Name);
};

NameValueCollection::NameValueCollection()
{
  Count = 0;
}

AWOL:
Are you suggesting that they don't consume RAM?

EDIT: just noticed who posted.
Bye.

Always forgive your enemies; nothing annoys them so much.
Oscar Wilde

Beakie:
I don’t think I use any?

These are fixed strings:

HTTPClient.println("<html>");
HTTPClient.println("<head>");
HTTPClient.print("<title>");

Namely “”, “”, “” and the others you use. They are copied from program memory into RAM.

Also I’m a bit curious about this:

class NameValueCollection
{
  public:

  unsigned int Count;
  NameValueItem Items[10];

You have allowed for exactly 10 items. Your Add function doesn’t check if you have reached the limit of 10. Nor do you ever seem to free them up, except perhaps by simply discarding the whole class. What happens if 11 items appear?