logo elektroda
logo elektroda
X
logo elektroda

ESP01, GCC, Eclipse - how do I conveniently upload extended HTML with multiple quotes?

zbynio_k 423 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21541069
    zbynio_k
    Level 10  
    Hello.
    I am programming in gcc on Eclipses.
    I have set up a web server on ESP01, I think complete.
    I am able to send data to the websocket, to the browser, via the function
    websocket_write_all(buf, strlen(buf), WEBSOCKET_TEXT);

    as the HTML code of the page is defined
    #define HTML_INDEX_PAGE sent by function
    http_send_string(con, HTML_INDEX_PAGE, "text/html");

    The problem arises when I want to define HTML_INDEX_PAGE as the code of a more extended page, there are a lot of inverted commas in the code which effectively prevents me from defining the HTML code as a string.

    Please give me a hint on how I should send the extended HTML code to the browser.
    I am attaching screenshots and details/body of the function in the attachment.
    Regards

    edit - there are tons of examples for the Arduino IDE on the web.
    edit2 - code for ESP in NOTA and NONOS, important !

    Screenshot of a browser displaying a simple HTML page from ESP01, with Polish messages about websocket connection and a list of counters and times. .
    Screenshot of a web page for testing data send and receive with Wemos-D1 mini PRO, featuring DIRECT-1 and DIRECT-2 buttons and selection fields. .
  • ADVERTISEMENT
  • #2 21541115
    JacekCz
    Level 42  
    Chaos. I completely fail to understand what you want.

    The #define is not (although I know silly monkey-copy examples prefer it) the best means of defining constants or variables

    And already #define in #define it can't end well

    Where is this supposedly mature webserver, if you are still looking terribly low-level and proudly tapping code as if it doesn't exist?
    The mythical webserver is supposed to free you from just such nonsense, and has it documented for the user
  • ADVERTISEMENT
  • #3 21541122
    zbynio_k
    Level 10  
    1. low-level because the web server code is in gcc
    2. the HTML text in the example as #define - I don't see a problem

    in one sentence > how to send the HTML page code to the browser as a STRING ?
  • #4 21541133
    JacekCz
    Level 42  
    zbynio_k wrote:
    in one sentence > how to send the page code in HTML to the browser as a STRING ?
    .

    In one sentence: you send correctly (assuming there's no <gt> there, but probably not).

    You just don't understand what a C-string is in itself (any sequence of characters up to \0 ) , and what a string literal (a record of a constant in the language) differs from it.
    Unfortunately, programming IS FULL of differentiated abstractions, and doing something more complicated and not differentiating we have a problem.

    zbynio_k wrote:
    the web server code is in gcc
    .
    Give a link, because I don't know

    Added after 27 [minutes]:

    zbynio_k wrote:
    #define - I don't see a problem
    .

    And I have seen many problems
  • #5 21541179
    zbynio_k
    Level 10  
    I will try to be less chaotic, more to the point

    1. maybe I'm not super proficient in C(gcc) but I've always defined an ASCII text variable like this
    uint8_t *name ={"ESP_MASTER"}; or
    uint8_t name ={"ESP_MASTER"};
    or char instead of uint8_t

    and there is no problem with such an ASCII character string

    2. in the example page, ESP sends an ASCII string

    "<!DOCTYPE HTML><html><head>OK > is HERE: #define HTML_INDEX_PAGE</head><body><div style='width: 400px; height: 800px; overflow:auto;' id='wdata'></div><script src='websocket_test.js'></script></body></html>"
    so the theme is simple,

    3. I want to send the HTML code of the page (attached) to the browser and it seems to me that this way is not possible

    4. link to the "erected" web server
    https://github.com/zyperpl/esp8266-websocket-server

    By the way, I'm programming AVR's and I'm just getting into ESP
    but I have made a few working projects
    clocks of various sorts with time synchronisation after NTP, weather stations, communication after esp_now ...

    edit - maybe you can suggest how to do it
  • #7 21541238
    zbynio_k
    Level 10  
    so far, thanks
    I see that sending html code to the browser is not that simple
    unless there is another method than sending an ASCII string ?
  • ADVERTISEMENT
  • #8 21541385
    miszczo997
    Level 28  
    Use makefsdata, which will generate arrays for you from your file package to the server.
    This is more or less what it looks like
    https://github.com/plawnik/stm32f407_live_chart/tree/main/socket_test/LWIP/App
    The www contains the files you want to put on the server, the fsdata_custom.c file is an array file system.
    If you are working on windows look for the makefsdata.exe utility, it should be available somewhere with examples from ST. You'll also need some dll which you need to put in the same folder as the tool, I can't remember which one it was exactly anymore, but I think it was something from netframeworks - you'll get a message about a missing dll file when you try to use the tool. You'll get the resulting file when you drag a bunch of server files onto the exe file.
    If you're running Linux, there's a perl script available from makefsdata.co.uk that you should be able to run without any problems.
  • #9 21541395
    fred_onizuka
    Level 19  
    In HTML code, various unusual characters can be written as codes. There are several versions of how to write such characters, e.g. inverted commas are "&_#_34_;" or "&_quot_;" (I had to add the underscore characters "_" because they could not be written otherwise here).
  • Helpful post
    #10 21541447
    miszczo997
    Level 28  
    I found my notes on how to automate this in eclipse on windows, every time you compile, the contents of the www folder will be automatically generated into the fsdata.c file. You have to customize for yourself under your project, I used this with stm32.
    1. Project->properties->C/C++ Build->Settings->Build Steps->PreBuild steps->Command
    cmd /c "..\utils\makefsdata.bat"
    2. Copy makefsdata.exe to main project folder, add msvcr100d.dll if needed to this same location
    3. Make script in this same location ->makefsdata.bat
    SET "mypath=%~dp0"
    echo %mypath:~0,-1%
    "%mypath:~0,-1%\makefsdata.exe" "%mypath:~0,-1%\stronaWWW"
    move fsdata.c "%mypath:~0,-1%\Middlewares\Third_Party\LwIP\src\apps\httpd"
    4. Tune folders with source, and output file
    .
  • #11 21541719
    JacekCz
    Level 42  
    fred_onizuka wrote:
    quotation marks are "&_#_34_;" or "&_quot_;"
    .


    We are still waiting for the mythical HTTP server code that is supposedly included in GCC. Such recoding is a primer.
    Unless it's typical arduino code copied from weak programmers by weak programmers.

    ESP already has enough computing power to do this without strange compromises, and my intuition tells me that there is a high quality (i.e. standards-holding) yet simple http server in the ecosystem

    Added after 12 [minutes]:

    zbynio_k wrote:
    send html code to browser
    .

    Even the term itself lets you in on the mailny.
    It's not the sending itself, but the SECOND phase of the request-response cycle, and any quality HTTP server will do it right (including the first one)
  • #12 21544559
    zbynio_k
    Level 10  
    thanks, I'm using eclipse with 03.25 and the options you showed are not there
    1. project->properties->C/C++ Build->Settings->Build Steps->PreBuild steps->Command
    I also cannot find the makefsdata.exe file on the internet

    but your hint led me to a clue > it is possible to convert e.g. online HTML text to HEX array

    I have displayed this array and ... works
    not as I would like because I send it as plain text
    I try sending as
    http_send_string(con, HTML_INDEX_PAGE, "text/html");

    Greetings
  • ADVERTISEMENT
  • #13 21544649
    miszczo997
    Level 28  
    zbynio_k wrote:
    thanks, I'm using eclipse from 03.25 and those options you showed are not there
    1. project->properties->C/C++ Build->Settings->Build Steps->PreBuild steps->Command
    .
    It must 100% be in the options somewhere, look for it. If not then you can always manually fire it up by dragging the file package onto makefsdata

    zbynio_k wrote:
    I also cannot find the file makefsdata.exe on the internet
    .
    https://github.com/DuinOS/FreeRTOS/tree/maste.../httpserver_raw_from_lwIP_download/makefsdata

    zbynio_k wrote:
    I have displayed this board and ... works
    not as I would like because I send as plain text
    i will try sending as
    http_send_string(con, HTML_INDEX_PAGE, "text/html");


    You need to add the headers plus content type at the beginning of the array you created. Take a look at this example from github that I posted, the actual page starts with the raw data comment, before that you have all the extra data that needs to be sent beforehand that you can copy into your array for testing.
    As you run makefsdata it will be generated automatically.

Topic summary

The discussion addresses the challenge of serving extended HTML pages containing multiple quotation marks from an ESP01 web server programmed in GCC using Eclipse. The main issue is defining large HTML content as C strings due to embedded inverted commas, complicating direct string literal usage. Solutions include avoiding #define for large strings, understanding C string literals versus character arrays, and using external tools like makefsdata to convert HTML files into C arrays for embedding in firmware. The makefsdata utility automates generating filesystem data arrays from HTML files, facilitating HTTP serving without manual string escaping. Additional advice covers encoding special HTML characters as entities to avoid syntax conflicts. Integration of makefsdata into Eclipse build steps is suggested for automation, though some users report difficulty locating the tool or configuring Eclipse accordingly. References to existing ESP8266 websocket server projects and examples highlight practical implementations. The discussion emphasizes using filesystem-based approaches over raw string literals for serving complex web pages on resource-constrained embedded devices.
Summary generated by the language model.
ADVERTISEMENT