problem developing http server

countxerox
Posts: 4
Joined: Fri Feb 10, 2017 5:14 pm

problem developing http server

Postby countxerox » Fri Feb 10, 2017 5:31 pm

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

countxerox
Posts: 4
Joined: Fri Feb 10, 2017 5:14 pm

Re: problem developing http server

Postby countxerox » Sun Feb 12, 2017 2:46 pm

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

User avatar
rudi ;-)
Posts: 1730
Joined: Fri Nov 13, 2015 3:25 pm

Re: problem developing http server

Postby rudi ;-) » Sun Feb 12, 2017 10:33 pm

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
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: problem developing http server

Postby kolban » Mon Feb 13, 2017 12:06 am

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
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

countxerox
Posts: 4
Joined: Fri Feb 10, 2017 5:14 pm

[solved] problem developing http server

Postby countxerox » Tue Feb 14, 2017 8:51 pm

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

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: problem developing http server

Postby ESP_Angus » Tue Feb 14, 2017 11:19 pm

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

Who is online

Users browsing this forum: Bing [Bot] and 110 guests