Dynamic jpeg update
Dynamic jpeg update
I have a camera connected to the UART on a MOD5282. The program downloads a jpeg formatted image into RAM once every 10 seconds. I want to display the image on the web page, but I can't figure out how to get the "index.htm" file to pick up from a variable.
If I use the <img src = "<!--FUNCTIONCALL GetPicture-->"> with a writestring(fd, Picture); in the c code, i get no image. If I use write(fd, Picture, sizeof(Picture)) it dumps the ASCII characters of the Picture variable onto the web page.
Can anyone suggest how I can get the image stored in a variable onto the web page displayed as an image?
If I use the <img src = "<!--FUNCTIONCALL GetPicture-->"> with a writestring(fd, Picture); in the c code, i get no image. If I use write(fd, Picture, sizeof(Picture)) it dumps the ASCII characters of the Picture variable onto the web page.
Can anyone suggest how I can get the image stored in a variable onto the web page displayed as an image?
Re: Dynamic jpeg update
Although not an expert, I have a demo product that does exactly what you want to do (unfortunately on another platfor). I couldn't get it to work using IExplorer. Just on a whim, I switched to another computer and Chrome... low and behold, the webcam image showed up. In my particular case, IExplore did not understand the format of the streaming data, while Chrome did. Before I spend too much time looking at the NetBurner side of things, I try another browser. Again, not an expert on jpeg, but I don't believe that it is simply a binary representation of you image. I believe that they are compressed, or at least have information regarding the characteristics of the image as well as control bytes within the data. You may have to take your RAM jpeg and decompress it or translate it into a fromat that browsers understand. Maybe the NetBurner code does that for you?
Good luck,
Bill B
Good luck,
Bill B
Re: Dynamic jpeg update
Maybe some kind of header needs to be sent before the data, so the browser knows its jpg
Re: Dynamic jpeg update
I tried Chrome and Safari, same results. The pictures are esentially static, one shot every 30 seconds or so stored in a memory variable. The pictures will show up properly if I put them in the /html/pictures file and then compile the project. The binary of the static picture in the system generated "htmldata.cpp" file is identical to the image stored in the variable. In fact, I tried putting the static binary into the memory variable and that didn't work either.
There must be some sort of processing, that needs to be done on the .jpg data, perhaps sending a header, or there is another FUNCTIONCALL method that will work.
I looked at the Bargraph example, it uses writestring() and passes a prefix of "HBAR.GIF?" followed by a few hex values, but no zeros. My Jpeg has embedded zeros and that ends the string after a few characters.
Is there any signifcance to the "?" in the header?
There must be some sort of processing, that needs to be done on the .jpg data, perhaps sending a header, or there is another FUNCTIONCALL method that will work.
I looked at the Bargraph example, it uses writestring() and passes a prefix of "HBAR.GIF?" followed by a few hex values, but no zeros. My Jpeg has embedded zeros and that ends the string after a few characters.
Is there any signifcance to the "?" in the header?
-
- Posts: 513
- Joined: Sat Apr 26, 2008 7:14 am
Re: Dynamic jpeg update
I'm not sure it's the browser...? I looked for one of the simple NB http examples that displays a graphic image. The HtmlFormPost Example displays some .gif images of the NB logo. I copied the .gif, turned it green so i could see the difference and saved it as a .jpg in the images folder of the project. I then edited the code to display the .jpg instead. The attached project works fine to display a .jpg, although the call is an html call not the <img src = "<!--FUNCTIONCALL GetPicture-->"> you were trying. I'm ising IE, so nothing special to show a .jpg...?
- Attachments
-
- HtmlFormPost_Example.zip
- (604.59 KiB) Downloaded 534 times
Re: Dynamic jpeg update
Jpegs will work if they are in the project's "/html/images" directory at compile time. The become "const unsigned char FilePointer0[]" in a system produced file called "htmldata.cpp" that shows up int the /debug or /release subdirectory when you compile the project.
My challenge is to be able to show a jpeg that resides in the device memory (preferably RAM and changes dynamically) on the webpage.
My challenge is to be able to show a jpeg that resides in the device memory (preferably RAM and changes dynamically) on the webpage.
Re: Dynamic jpeg update
Look at the example nburn\examples\web\bargraph.
Re: Dynamic jpeg update
The nburn\examples\web\bargraph example uses the <!--FUNCTIONCALL --> fed by a writestring(). The function returns a text string consisting of "HBAR.GIF?" followed by hex codes. I tried the same thing using "PICTURE.JPG?" followed by the hex code for the jpeg. The PICTURE doesn't show. The header and hex code show up in the webpage source, but it doesn't show the picture on the webpage.
Re: Dynamic jpeg update
The functioncall just Tells the system what gif to display.
The dynamic gif generation is a totally seperate part.
Look in mydoget in that example.
int MyDoGet( int sock, PSTR url, PSTR rxBuffer )
{
if ( strlen( url ) )
{
/* If it is 'the' image go get it */
if ( httpstricmp( url, "HBAR.GIF?" ) )
{
GenerateHBar( sock, url );
return 1;
}
}
return ( *oldhand ) ( sock, url, rxBuffer );
}
Yours will probably look something like:
You will probably need to add some includes....
htmlfiles.h http.h
int MyDoGet( int sock, PSTR url, PSTR rxBuffer )
{
if ( strlen( url ) )
{
/* If it is 'the' image go get it */
if ( httpstricmp( url, "DYNAMIC.JPG" ) )
{
SendJpg( sock);
return 1;
}
}
return ( *oldhand ) ( sock, url, rxBuffer );
}
Where SendJpg looks like:
void SendJpg(int sock)
{
//Assuming that the JPG image is in a buffer jpg_buf and is jpg_len long
//First write out the http response header...
char buffer[255];
siprintf( buffer,"HTTP/1.0 200 OK\r\nPragma: no-cache\r\nMIME-version: 1.0\r\nContent-Type: image/jpeg\r\nContent-length: %d\r\n\r\n",jpg_len );
writestring( sock, buffer );
//Now send the JPG image
writeall(sock,jpg_buf,jpg_len);
}
The dynamic gif generation is a totally seperate part.
Look in mydoget in that example.
int MyDoGet( int sock, PSTR url, PSTR rxBuffer )
{
if ( strlen( url ) )
{
/* If it is 'the' image go get it */
if ( httpstricmp( url, "HBAR.GIF?" ) )
{
GenerateHBar( sock, url );
return 1;
}
}
return ( *oldhand ) ( sock, url, rxBuffer );
}
Yours will probably look something like:
You will probably need to add some includes....
htmlfiles.h http.h
int MyDoGet( int sock, PSTR url, PSTR rxBuffer )
{
if ( strlen( url ) )
{
/* If it is 'the' image go get it */
if ( httpstricmp( url, "DYNAMIC.JPG" ) )
{
SendJpg( sock);
return 1;
}
}
return ( *oldhand ) ( sock, url, rxBuffer );
}
Where SendJpg looks like:
void SendJpg(int sock)
{
//Assuming that the JPG image is in a buffer jpg_buf and is jpg_len long
//First write out the http response header...
char buffer[255];
siprintf( buffer,"HTTP/1.0 200 OK\r\nPragma: no-cache\r\nMIME-version: 1.0\r\nContent-Type: image/jpeg\r\nContent-length: %d\r\n\r\n",jpg_len );
writestring( sock, buffer );
//Now send the JPG image
writeall(sock,jpg_buf,jpg_len);
}
Re: Dynamic jpeg update
Yes, I see that now. It worked.
Thank you very much!
Thank you very much!