Recent changes
Slingshot user guide
tag Guide, user
NFCLamp user guide
tag Guide, user
Homepage
MPL115A2
Compiler Error 42
From the mbed microcontroller Cookbook.  

NetServices

This documentation is for the Segundo Equipo version of the NetServices library.

This library is based on Donatien's source V1.04 (5 August 2010).

The following improvements and bug fixes are made:

#pragma diag_remark directives are added to the following files to turn compiler warnings into remarks (which are not normally displayed)

base64.h

EmailMessage.cpp / .h

eth_drv.cpp / .h

Code

Ethernet* eth_interface();

EthernetNetIf.cpp / .h

Code

IpAddr ethIp = eth.getIp();
printf("Connected ok, IP : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
const char* hwAddr = eth.getHwAddr();
printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n",
   hwAddr[0], hwAddr[1], hwAddr[2],
   hwAddr[3], hwAddr[4], hwAddr[5]);

Code

// set hostname ready for DHCP
EthernetNetIf eth("mbedSE");

» Import this library into a program

Public Member Functions

EthernetNetIf (const char *hostname=NULL)
Instantiates the Interface and register it against the stack, DHCP will be used.
EthernetNetIf ( IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns)
Instantiates the Interface and register it against the stack, DHCP will not be used.
EthernetErr setup (int timeout_ms=15000)
Brings the interface up.
const char * getHwAddr () const
Returns an array containing the hardware address.
const char * getHostname () const
Returns a pointer to the hostname set in the constructor.
IpAddr getIp () const
Returns the IP of the interface once it's connected.

Code

#define HOSTNAME "mbedSE"
EthernetNetIf eth(HOSTNAME);
EthernetErr ethErr;
do {
    printf("Setting up...\n");
    ethErr = eth.setup();
    if (ethErr) printf("Timeout\n", ethErr);
} while (ethErr != ETH_OK);

mem.c

memp.c

lwipopts.h

Warning

MEM_POSITION becomes effective (due to mem.c and memp.c changes) and is defined as AHBSRAM1 (not AHBSRAM0)

lwipopts2.h

netCfg.h

NTPClient.cpp

Code

if ((int)time(NULL) < 1280000000) set_time( 1280000000 ); //End of July 2010... just there to limit offset range

RPCHandler.cpp

Code

#include "url.h"
...
void RPCHandler::cleanReq(char* data)
{
    char* decoded = url_decode(data);
    strcpy(data, decoded);
    free(decoded);
/*    
  char* p;
  static const char* lGarbage[2] = {"%20", "+"};
  for(int i = 0; i < 2; i++)
  {
    while( p = strstr(data, lGarbage[i]) )
    {
      memset((void*) p, ' ', strlen(lGarbage[i]));
    }
  }
*/  
}

SMTPClient.cpp / .h

timers.c

Code

void sys_timeouts_init(void)
{
  next_timeout = NULL;
...



calendar Page history
Last modified 28 Nov 2010, by   user Segundo Equipo   tag NetServices, source code | 6 comments  

6 comments on NetServices:

22 Dec 2010

Using the NTPClient to set the current time seems to eat all available memory (less than 240 bytes left). I'm not really sure where this comes from, since I experience the malloc problem described here: http://mbed.org/forum/bugs-suggestions/topic/1593/ .

When trying to build a short program to reproduce this, I found out that it seems to be heavily influenced by the program layout (e.g. changing the text of my debug printf() message made the bug go away...).

What I'm observing is that after an ntp.setTime() call, the memory available for malloc drops below 240 bytes (which is the last malloc I see executing in the AvailableMemory() call). But it doesn't matter how much memory is available on the beginning - if I allocate 16000 bytes before the NTP call, the time is still set and I also get less than 240 bytes left (but I can free my 16000 bytes and be happy).

I also see similiar problems when using HTTPClient together with HTTPStream - I have plenty of memory available, but not afterwards (or, in my case, in the loop handling the received data).

This issue might be related to the malloc problem I linked to - maybe it's just the internal memory handling which gets messed up.

My test program is published as http://mbed.org/users/hlipka/programs/ntp_mem .

03 Jan 2011

user Hendrik Lipka wrote:

Using the NTPClient to set the current time seems to eat all available memory (less than 240 bytes left). I'm not really sure where this comes from, since I experience the malloc problem described here: http://mbed.org/forum/bugs-suggestions/topic/1593/ .

Additionally, I see a similiar behaviour when using an HTTP stream. I see the OOM problem when receiving data (when the polling is done). But here my workaround with pre-allocating some memory doesn't work, because I don't know the amount of free memory at this point...

10 Jan 2011

user Hendrik Lipka wrote:

Using the NTPClient to set the current time seems to eat all available memory (less than 240 bytes left).

It gets stranger: I have found out that this problem happens exactly the moment the NTPClient object gets deleted (the destructor is called) - but only when the object has actually been used. So either one of the used member objects does something wrong during destruction, or it really is a compiler bug.

06 Feb 2011

Is it possible to dynamically set the hostname under program control instead of using a #define? The constructor must be outside the scope of a function, and I would like to set the hostname just prior to initalizing the network under program control, in case there are multiple mbeds on a network and all run the identical software.

17 Aug 2011

The EthernetNetIf destructor crashes if the EthernetNetIf object was created using the non-DHCP constructor. The following patch fixes the issue:

Code

  <NetServices>/if/eth/EthernetNetIf.cpp line 57
  
  m_useDhcp = false;
  m_pDhcp = NULL; /* <== added this line */
  m_setup = false;
25 Nov 2011

Am I the only one that have trouble finding a ethernet library that actually works.

Some crash on repeated initialization (memoryleak) while others cant be probed for available buffer size. (Calling send with -1 as length )

Some fixes are posted, but I cant seem to find the source to post it in.

All in all I find myself wasting lots of time.

What exact library (preferably source) do you guys use?

Please login to post comments.