JS libraries on flash memory
-
- Posts: 7
- Joined: Sun Mar 08, 2020 12:39 pm
JS libraries on flash memory
My ESP32 works as AP. Devices which are connected to this network can view a website written in html + javascript. But I need to use JS library (Chart.min.js in this case, 173kb) on this website and I don't know how to do that. I tried to send it to the flash and add it to a website by <script src="Chart.min.js"> but I get errors during uploading files to ESP.
So how to use javascript libraries on my website on ESP working as AP without internet connection?
So how to use javascript libraries on my website on ESP working as AP without internet connection?
Re: JS libraries on flash memory
I’m going to guess that the problem is that there are two dots in your file name. Try renaming it to remove the middle dot.
-
- Posts: 7
- Joined: Sun Mar 08, 2020 12:39 pm
Re: JS libraries on flash memory
I tried, but I don't see any difference:
Code: Select all
[1/1] Writing file Chartmin.js (173kb) with compression
Failed to write file, trying again...
Failed to write file, trying again...
Filecheck failed
Upload done, resetting board...
Re: JS libraries on flash memory
Which tools do you use for upload?
Is there sufficient space available in the ESP32 file system?
Did you try to specify the full path name for the target?
Is there sufficient space available in the ESP32 file system?
Did you try to specify the full path name for the target?
-
- Posts: 7
- Joined: Sun Mar 08, 2020 12:39 pm
Re: JS libraries on flash memory
I use Visual Studio Code with PyMakr extension. Right now I use 13kb of ESP flash memory for my files. I have 4Mb flash ESP32 edition
Re: JS libraries on flash memory
Try to use something more basic for file upload, like a dedicated ftp client (ft, filezilla) or tools like ampy, rshell, pyboard.py, ..
VSC + pymakr is IMHO a constant source of trouble. With every version of VSC - like once a week - pymakr may fail again.
VSC + pymakr is IMHO a constant source of trouble. With every version of VSC - like once a week - pymakr may fail again.
-
- Posts: 7
- Joined: Sun Mar 08, 2020 12:39 pm
Re: JS libraries on flash memory
Thank you it really helped. Now I don't have any errors during file transfer which was really annoying. But I still have a problem with usage of this library on my website. Here's part of code I'm using:
In html code I have
When web browser ask for Chartmin.js it gets PageHTML string text in return. So index page and Chartmin.js in browser sources looks the same. I understand why it happening like that, but I don't know how do it correctly. Should I handle a special GET request and send this library content as string or something? What's the best way to use this library on website?
Code: Select all
import network
import socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 8000))
s.listen(10)
while True:
conn, addr = s.accept()
FullRequest = str(conn.recv(1024))
conn.sendall('HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type:text/html\r\n\r\n')
conn.sendall(str(PageHTML())) #PageHTML returns a string with html code
conn.sendall('\n')
conn.close()
Code: Select all
<script src="Chartmin.js"></script>
Re: JS libraries on flash memory
You should use one of the web server libraries rather that rolling your own with sockets. I like microdot, but there are lots of options. https://github.com/miguelgrinberg/microdotSemicolonist wrote: ↑Thu Mar 12, 2020 1:40 pmWhen web browser ask for Chartmin.js it gets PageHTML string text in return. So index page and Chartmin.js in browser sources looks the same. I understand why it happening like that, but I don't know how do it correctly. Should I handle a special GET request and send this library content as string or something? What's the best way to use this library on website?
Importantly, it has a way to directly send a file from the flash -- see examples/gpio.py: "response = send_file('gpio.html')".
But yes, you are correct, your program needs to look at the request path (i.e. GET /path/foo.bar HTTP/1.1) and handle that. Using a library will make this much easier.
Re: JS libraries on flash memory
To stop the client browser from making subsequent requests, add some cache headers to your large static scripts