[Solved..but..] Http.get does not work with ip urls?

31 Mar 2010 . Edited: 01 Apr 2010

I have been playing with the Httpclient and found out (after a lot of head scratching) that http.get does not seem to work if the url consists of an ip-address instead of some domain name. The program seems to get forever stuck when doing the get function.

Example:

http.get("http://somedomain.somewhere.com/something.html", fp) works

http.get("192.168.1.20/something.html", fp) does not work

This is a problem because the mbed is supposed to get files from my local server (which hasn't got any domain name). How do I overcome this?

Any help appreciated..

01 Apr 2010

Hi Tommi,

I'm not up to date whats changed in the last quarter, but it should work.

Try to specify a port and protocoll, like this:

http.get("http://192.168.1.20/something.html", fp);
or

http.get("http://192.168.1.20:80/something.html", fp);
If I remeber correctly it might work.

 

Cheers

Rolf

01 Apr 2010 . Edited: 01 Apr 2010

My Billy Bass project started out very smoothly, but now everything seems to go wrong :(

Eventually I got the ip address url working with http.get, but I'm not sure what really was cause. I believe it was using dhcp for configuring the mbeds network settings. With manually set ip, netmask etc. the get function seemed to wait forever with local ip addresses and when trying an external site, I finally got a timeout message. Changing to dhcp seemed to fix the problem, so it was probably some kind of dns problem (I set my dsl box as dns when manually configuring the httpclient).

Anyway, using current setup the mbed is able to download a wav file (using the httpclient) from my local server and save it on the sd card. BUT, here next problem comes ahead. After downloading the wave file, the program starts playing it (I copy-pasted the waveplayer example found here). The file plays nicely, but at the end the program fails (BLOD) with the error: 'Oops -- not enough slices in the wave file'.

Comparing the original file (on the server) and the downloaded one (on the sd card) there is a few bytes difference in size. The downloaded file is a bit smaller (amount depends on file size). Both files play on a pc and on the mbed too, but the waveplayer program crashes. If I save the same wave file directly on the sd card using a pc, the program does not crash.

Example: wav file size on server disk is 241850 bytes. Http.get reports 240590 as read result, and below is the waveplayers printout:

--------------------------------------------------------------------

Playing wave file '/sd/snd.wav'

Read chunk ID 0x46464952, size 0x3b0b2

 

RIFF chunk

chunk size 241842 (0x3b0b2)

RIFF type 0x45564157

Read chunk ID 0x20746d66, size 0x10

FORMAT chunk

chunk size 16 (0x10)

compression code 1

1 channels

11025 samples/sec

22050 bytes/sec

block align 2

16 bits per sample

Read chunk ID 0x61746164, size 0x3b08e

DATA chunk

chunk size 241806 (0x3b08e)

120903 slices

Ideal sample interval=90

programmed interrupt tick interval=90

 

Oops -- not enough slices in the wave file

--------------------------------------------------------------------------

 

And here is the vital part of my program:

 

...

 

int main() {
led1 = 1;
//download sound from server
download_snd();

//play downloaded file (copy-pasted waveplayer code)
play_wave("/sd/snd.wav");

// Work is done!
while(1) {
led1 = !led1;
wait(0.2);
}
}//main


void download_snd() {

led2 = 1;
// Open a file to write.
FILE *fp = fopen("/sd/snd.wav", "w");

led3 = 1;

int koko;
// Request a page and store it into a file.
koko = http.get("http://192.168.1.2/talk/snd.wav", fp);

 

// some debug print
printf("size is %u \n", koko);

// Close the file.
fclose(fp);

}//download_snd

...

Does the http.get leave something out, or am I doing something else wrong?

04 Apr 2010 . Edited: 05 Apr 2010

Project update:

After doing some more studying (I'm a real noob with C), the waveplayer seems to hang when called multiple times. My programs goes around in a neverending loop where it first downloads the sound, then plays it using the waveplayer code. Then next round starts all over again..

The first round works, but when calling the waveplayer for the second time it hangs just before it starts writing out samples on the analog out pin. The program does not exit reporting any errors, it just freezes.

I got it working by doing some *really* dirty tricks, but I wonder how should it be done correctly? Am I forgetting to "unload" or "free" some resources or what?

I got rid of the "Oops.." message just by commenting out the if-statement (including the exit(1) line) that checks for the feof of the wavefile.

And the freeze problem I fixed making the mbed reset itself after each main loop round.

Dirty fixes, but they work. I'll fix them when I learn how to.

 

Project update: April 5, 2010

I finally got a preliminary version of my Billy mod working. Now Billy speaks and moves when getting stuff to say. I'll write a more detailed description in my notebook soon.