Separate the interface and code

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
alexsus
New user
Posts: 5
Joined: 13 Feb 2016, 17:10

Separate the interface and code

#1 Post by alexsus » 20 Oct 2016, 07:12

It is necessary to separate the interface (html, css, js) and the code.
A simple way to do ".h" file is xxd

It's my 2h.sh

Code: Select all

#!/bin/bash
xxd -i $1 |\
	sed "s/unsigned/const/"|\
	sed "s/\[\] \=/[] PROGMEM =/" 
Use:

Code: Select all

2h.sh dist/minipage.html

Code: Select all

const char dist_minipage_html[] PROGMEM = {
  0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20,
  0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x22, 0x76, 0x69, 0x65, 0x77, 0x70, 0x6f,
  0x72, 0x74, 0x22, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x3d,
...
  0x32, 0x5d, 0x29, 0x3b, 0x3c, 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
  0x3e
};
const int dist_minipage_html_len = 5137;
Warrning:
!!! There is a feature. In the end of the const char dist_minipage_html [] no 0x00.

alexsus
New user
Posts: 5
Joined: 13 Feb 2016, 17:10

Re: Separate the interface and code

#2 Post by alexsus » 20 Oct 2016, 09:24

If we estimate the resources
Esp8266 - thin server
Browser - thick client

Therefore it is necessary to transfer processing to the client.

For this
- create a page on computer and put it in a flash
- on request send page from flash and add useful data from code

Code: Select all

<script type='text/espeasy'>
...
<script>
<html>
...
</html>
Script with unknown type is ignore in browser. Data may be put before or after html.

Get the following data in JS is not difficult.

alexsus
New user
Posts: 5
Joined: 13 Feb 2016, 17:10

Re: Separate the interface and code

#3 Post by alexsus » 20 Oct 2016, 09:42

What is good and how to fight it?

- double quotes not necessary
- any text data

Code: Select all

<script type='text/espeasy'>
1,2,3,4,5,6,7
hi, all
<script>

As varian sepate rules may be:

lines split by \n
values split by \t

If you want I can write JS data parse functions.

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 1 guest