Page 1 of 1

problem developing http server

Posted: Fri Feb 10, 2017 5:31 pm
by countxerox
Hi,

I'd like to serve up an html page, my server works fine with simple pages but when I try to use svg I get errors compiling and the build failed.

Code: Select all

const static char http_index_html[] =
		"<html><body><svg width=100% height=100% viewbox="0 0 200 200" id="svg"><rect .... etc

Code: Select all

/home/rob/esp32/workspace/myapp/main/./main.c:87:53: error: expected ',' or ';' before numeric constant
   "<html><body><svg width=100% height=100% viewbox="0 0 200 200" id="svg"><rect .... etc
                                                     ^
How should I define html the page properly?
Thanks
Rob

Re: problem developing http server

Posted: Sun Feb 12, 2017 2:46 pm
by countxerox
Hi, I found out the " characters were the problem, so I can easily escape them like \".

but is there a better way to store a static page on the esp32? As I develop the page further, it's getting boring adding \'s again and again.

Thanks
Rob

Re: problem developing http server

Posted: Sun Feb 12, 2017 10:33 pm
by rudi ;-)
countxerox wrote:Hi, I found out the " characters were the problem, so I can easily escape them like \".

but is there a better way to store a static page on the esp32? As I develop the page further, it's getting boring adding \'s again and again.

Thanks
Rob

hi

there are more ways for this..
one here:
try this:
example your file is named fine.txt
put this file in the folder of your project
example
\main\fine.txt

in your code write:

Code: Select all


extern const uint8_t my_extern_file[] asm("_binary_fine_txt_start");

then you can use it like you want to do:

Code: Select all

..
printf("%s", my_extern_file);
..
printf((char *)my_extern_file);
..

similar to this
you can create a html file like it is ( fine.html )

Code: Select all

extern const uint8_t my_extern_file[] asm("_binary_fine_html_start");
same procedure

Code: Select all

..
printf("%s", my_extern_file);
..
printf((char *)my_extern_file);
..
// and so on
// socket_send((char *)my_extern_file,......

if you compile your project
the file gets symbol and is fixed in the flash on write the bin to esp32

let me know how you get on in this
hope this helps

best wishes
rudi ;-)

edit:

Example: fine.tx

░♥░(¯`:´¯)░
░.(¯ `·.\|/.·´¯)
░(`♥·.(۞).·´¯)░(¯`:´¯)
░ (_.·´/|\`·._)(¯ `·.\|/.·´¯)
░ ░ (_.:._)…(¯ `·.(۞).·´¯)
░♥░ (¯`:´¯)░(_.·´/|\`·._)
♥░.(¯ `·.\|/.·´¯) ::(_.:._)
░ (¯ `·.(۞).·´¯)
░ ░(_.·´/|\`·._)
░♥♥». (_.:._)░





Example: SSL Zertifikate

OpenSSL Server Example

Re: problem developing http server

Posted: Mon Feb 13, 2017 12:06 am
by kolban
Another possibility is to use the "xxd" tool. This takes an arbitrary file as input (binary or text) and can produce a header file that contains the data in the file that is safe to include in your other C programs. See:

http://linuxcommand.org/man_pages/xxd1.html

[solved] problem developing http server

Posted: Tue Feb 14, 2017 8:51 pm
by countxerox
Hi,

Thanks both, this is great advice. :)

I added a line in component.mk to help the complier find the file I guess ...

Code: Select all

COMPONENT_EMBED_TXTFILES := fine.html
For netconn, the sizeof the data to send ...

Code: Select all

extern const uint8_t fine_html_start[] asm("_binary_fine_html_start");
extern const uint8_t fine_html_end[] asm("_binary_fine_html_end");
const unsigned int fine_html_bytes = fine_html_end - fine_html_start;
Then serving up the page is just ...

Code: Select all

netconn_write(conn, (char *)fine_html_start, fine_html_bytes, NETCONN_NOCOPY);
Thanks
Rob

Re: problem developing http server

Posted: Tue Feb 14, 2017 11:19 pm
by ESP_Angus
Hi Rob,

Glad you got this working well. For the reference of anyone who finds this later on, the documentation for the COMPONENT_EMBED_TXTFILES/COMPONENT_EMBED_FILES feature is here:
http://esp-idf.readthedocs.io/en/latest ... inary-data


Angus