UDP problems

28 Oct 2010

Hi All

I'm just getting started with UDP and have hacked Donation's UDPExample into the code you see here. Unfortunately both the calls to  "bind" and "sendto" fail with UDPSOCKET_MEM errors

 

EthernetNetIf eth;
UDPSocket     cfgSocket;

void onUDPSocketEvent(UDPSocketEvent e)
{
    if ( e == UDPSOCKET_READABLE )
    {
        char buf[64] = {0};
        Host host;
        while( int len = cfgSocket.recvfrom( buf, 63, &host ) )
        {
            if( len <= 0 )
                break;
            pc.printf("From %d.%d.%d.%d: %s\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], buf);
        }
    }
}

int main() 
{
    pc.baud(115200);
    pc.printf ("HEllo World - 7 *\n");
    
    EthernetErr ethErr = eth.setup();
    if( ethErr == ETH_OK )
    {
        IpAddr ip = eth.getIp();
        pc.printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
    }
    else pc.printf ("ETHERNETSETUP FAILED\n");

    cfgSocket.setOnEvent(&onUDPSocketEvent);
    UDPSocketErr udpErr = cfgSocket.bind( Host(IpAddr(),5555) );
    if ( udpErr != UDPSOCKET_OK )
        ShowError(udpErr);

    int i = 0;
    Host brdHost(IpAddr(255,255,255,255), 5555);                    //broadcast test msg
    char cfgRqstMsg[]="SERVER CONFIG REQUEST";
    
    Timer tmr;
    tmr.start();
    while(1) 
    {
        Net::poll();
        if( tmr.read() > 5)
        {
            tmr.reset();
            int nSent = cfgSocket.sendto(cfgRqstMsg,strlen(cfgRqstMsg),&brdHost);
            pc.printf("PLONKER %d :: %d\n",++i,nSent);
            if ( nSent < 0 )
                ShowError((UDPSocketErr)nSent);
        }            
    }
}
can anybody see why ??

thanks

dave

 

 

02 Nov 2010

bump

anybody?

22 Nov 2010

IS the support here always this crap

yeah I know , dont answer that, noboby does anyway

22 Nov 2010

Hi Dave,

I just had a go at building the UDP example that Donatien published a while back:

I built it for the LPC2368 (which I think is what you have), and set it running:

Do you get the same results with that base example?

Simon

22 Nov 2010

This is a forum for users and not a helpdesk so stop whining!!!

You can post a message / question and  other users can give an answer. Can be right away or after a few days. If nobody has an answer or knowledge about that topic, it can take a long long time.

My first comment is to post the complete listing of you're program, you left out most important lines...
please declare ShowError, brdHost, etc.

Give something reproducible to your problem so other users can have a look into it.


It is a matter of how to phrase your question to get the right answer....

 

22 Nov 2010

Hi Simon, Dave,

I build the example too and it works fine.

I connected a second one and modified the code a bit. I added a button and an led. If I press the button on MBED_1 the led on MBED_2 lit on and the otherway around...

So, no problem so far....

As I stated, please post everything, otherwise it's hard to debug...


Ben

23 Nov 2010

 

Simon

Yes i get the same result from Donatiens example BUT that code makes no check of the return code from the bind or the sendto. So the fact that it goes round the loop printing hello world doesnt actually show that the UDP code is working, or have you used wireshark or tcpdump or something to actually see the stuff on the wire?  I looked for for any output from mine (ignoring the return code errors) and didnt see any, nor did the server thats expected to reply.

I'm so happy your code works Brian but err yeah, so what. That doesnt help point out what is wrong with the code I posted above. I didnt leave out the most importent lines, just padding. ShowError just converts a return code to a string and brdHost is a variable. The complete code is in the BUGS forum.

I was hoping that someone (Donatien maybe?) would glance at the code and point out what a twat i was being because blah blah whatever was all wrong but .......

Dave

 

 

 

23 Nov 2010

user Stuart Hadfield wrote:
I'm so happy your code works Brian but err yeah, so what.
Brian?!? I assume that's me, Dave...

Why don't you address Donatien directly?

23 Nov 2010

Hi Dave,

I think I may have found the discrepancy!

It looks like from your profile you are using the LPC2368 mbed? Is that right? I just found one of these and do indeed get the out of memory error if I run your example on that. However, with the newer LPC1768 mbed, it doesn't throw the error.

I suspect therefore that when Donatien was doing his experiments, it wasn't tested on the older beta hardware. Still, nice of him to publish his code, even if it is not fully functional and needs some help from others :)

So, not a solution yet, but certainly makes more sense why people were seeing different results if that is the case! It may therefore be you are charting new territory getting UDP up and running on the LPC2368.

Simon

23 Nov 2010

Hi Dave,

Try this: http://mbed.org/users/simon/programs/UDPSocketExample/lic6y6 i.e. Just import the whole thing in to your compiler workspace.

I took Segundo's NetServiceTribute code he has been improving from Donatiens, and adjusted the memory setting to be the same for LPC2368 as they were for LPC1768. Seems to build and run at least the same as the LPC1768 version now. btw, it'll take a while to build, as it is all source.

Please tell me how you get on.

Simon

23 Nov 2010

 

Hi Simon

thanks for that. I'm not actually in a position today to test that code or look and see if its a 2368 that I'm using(I'm not posting from my usual desk) although I suspect it is. I'll definately do it tomorrow.

I do already have UDP code running on the whatever it is i'm using but that is older lwp code that i copied/hacked from the 1st cookbook, now depricated? I was looking to update/extend my app and thought it would be a good time move over to the newer code libraries. Arent Donatiens library's the "official libraries".

cheers

dave

23 Nov 2010

 

Sheesh brain fade

As i was typeing I was talking about radio phone ins with a friend and the first phone in, in this country (UK) was hosted by Brian Hayes ( I believe).  So Ben/Brian/Ben i did mail Donatien and didnt get a reply or maybe he did reply but it went to stuarts email and i didnt hear about it.

Simon while i'm here , this system of 1 account for 1 mbed is not neccassarily the best. When i say my app in the previous post, i'm being a bit loose, as I'm the third person to work on it and use this mbed, Stuart just happend to be the first. It would be better if i had my own account. I know i can change the name/email address in the profile but i'll always been logged in as stuartah

cheers

Dave

24 Nov 2010

 

Simon that's solved the problem, goodO, but I have to ask how?

I see your using the NetServices library rather than EtherNetIf. Does that mean that EtherNetIf is now redundant?  When I started this i just went to http://mbed.org/cookbook/Networking-Stack-Releases and took the latest.

When you say "adjusted the memory setting to be the same for LPC2368 as they were for LPC1768"  what do you mean how/where did you do that?

Again with memory, my original code with EthernetIf library  the compiler->program details->build memory usage is shown as 11K, theoretically plenty of room, should those numbers be taken with a pinch of salt?  btw the new code shows usage at 3.6K

Dave

25 Nov 2010

Hi Stuart,

Quote:

When you say "adjusted the memory setting to be the same for LPC2368 as they were for LPC1768" what do you mean how/where did you do that?

I'm not familiar with the details of the internals of the NetServices code, so this was the process I used to help you:

  • Reconstructed your example based on what you'd posted, and guessing the rest of what you did
  • Compiled and ran it, seemed to work, responded

Then when you reported continued problems:

  • Looked at your profile, which says you had the LPC2368, so found one of them and rebuilt for that
  • Got the out of memory error!
  • Looked at the cookbook to see what the latest Networking code people had written was
  • Found the "NetServices(Tribute)" which seemed to be based on the original work by user Donatien, with some fixes by another user
  • Imported that to replace first library, to see if that solved the problem; it didn't
  • Right-clicked the "NetServices" library and chose "Edit Library..."
  • Browsed the codebase to look for anything to do with memory allocation; found "lwipopts.h" in directory "lwip"
  • Found two sections with numbers around buffer sizes etc, guarded by #ifdef TARGET_LPC1768, #elsif TARGET_LPC2368; noticed the settings were different, and guessed the original author probably was adjusting/testing one, but never ported it for the other
  • Changed the settings for the LPC2368 to match the LPC1768
  • Recompiled, tested, ok!
  • Published a working example for you to test.

Quote:

Again with memory, my original code with EthernetIf library the compiler->program details->build memory usage is shown as 11K, theoretically plenty of room, should those numbers be taken with a pinch of salt? btw the new code shows usage at 3.6K

FLASH/RAM sizes in the build details is only static memory sizes, and don't (can't) take in to account dynamic memory allocated when the program is running (i.e. what is "free" is left available for the stack/heap). I'm not sure whether the error message you received was actually you running out of memory, or the allocation by these setting being exceeded; for that, you'd need to investigate a little more of the lwip implementation.

Just as an aside, whilst the core mbed libraries (as featured in the handbook) are officially developed, maintained, supported, regression tested etc, we can't make any promises for code in the cookbook. That is a community contributed area, with all the benefits and downfalls of diversity and quality that brings!

Simon

26 Nov 2010

 

fantastic , thanks for the help

dave