Would anyone have a good example of how to use the Photon as a JPEG image server? I would like to use a browser like Chrome and view a JPEG image hosted by Photon.
Thanks.
You can use the Webduino lib to do it.
First you need to convert your jpeg to a byte array, xxd -i on linux can do that for you.
Then paste that into your application code, making sure its marked as const so that its not copied into ram.
Then find the exact size of the file.
const char jpgfile[] = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
....
//In setup()
webserver.addCommand("test.jpeg", &Web_jpeg);
void Web_jpeg(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
//webserver.httpSuccess("image/jpeg", "Content-Encoding: gzip");
webserver.httpSuccess("image/jpeg");
uint16_t length = 12254; //Length of file
for (uint16_t pos=0; pos<length; pos++)
{
webserver.print(jpgfile[pos]);
}
}
1 Like