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?
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..