Extending the File Server Example to Load and Run HTML, CSV, and JS(called from script in HTML) #2384
Replies: 9 comments
-
Posted at 2016-04-13 by ClearMemory041063 Current files are attached. Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-13 by @gfwilliams Looks good! About post - I've definitely had Do you just get no calls to it at all? Perhaps you could try POSTing from something like To be honest for simple on/off stuff I've just been encoding it on the URL ( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-13 by ClearMemory041063 Hi Gordon,
One thing I've tried to troubleshoot the POST problem is to use a I set out to modify a program I used on Android using SL4A that reads analog inputs and plots them on a strip chart on the client. It makes use of the Flot graphics. The HTML loads a Flot JS file which is rather large even in minified form. I stubbed the Android calls in the HTML program, put the HTML and Flot JS files on the SD card. It runs but takes several minutes to load at 115k Baud. I've yet to try loading the Flot JS file from the client side which should speed up the loading. Otherwise it's create a light version of a strip chart. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-14 by ClearMemory041063 Found the bug
Notice that in the example fileserver code and my program there is no res.end().
By changing the program as follows:
The error goes away. I first tried 512 instead of 4096 and only got a partial load of my HTML file. The 4096 is the length of the HTML file. Does the chunkSize parameter need to be the file length?
Pdata= {"name":"LED2","a":true,"cmd":"pobj.a=!pobj.a;digitalWrite(LED2,pobj.a)"}{"name":"LED2","a":0,"cmd":"pobj.a=!pobj.a;digitalWrite(LED2,pobj.a)"} So there are two questions.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-14 by @gfwilliams I think:
Is the problem, and would explain What happens is by typing
It sounds like you weren't actually doing that at the time - but maybe you're doing something very similar somewhere else. Definitely calling
No, this should be the maximum size of a chunk of data that is sent down the pipe each time data is available. (Pipe effectively reads chunkSize bytes from the source and then writes them to the destination whenever data is available)
Maybe do it when the connection itself closes, on |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-15 by ClearMemory041063 Program is working now, files attached
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-15 by @allObjects Some serious engineering is going on here... I like it very much. I like it very much and like it very much for Espruino! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-16 by d0773d Good work! This will definitely come in handy for my project :-) I would like to implement this on a Pico. Is there anything else I need to impliment along with following the File IO and SD cards example? I would try this out, but I don't have a SD breakout... So I'm only brain storming ATM. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-16 by ClearMemory041063 Taking a break I was working on the GET side of the code with the pipe function, it's arguments and the error message that appears. It seems this didn't fix the POST bug like I thought. Just getting a better handle on how the on('data') function works was part of the learning curve that fixed the problem. I did manage to edit the HTML file to remove the message from the header and replace it with "CMD". The message gets posted after the header. This change works.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-04-13 by ClearMemory041063
This runs on an Espruino board connected to an ESP8266 running the AT commands.
The ESP8266 is on a separate 3.3V supply and connects to Serial port 4 of the Espruino board
Put an HTML and a CSV file on an SD card and insert it into the Espruino board,
Load the following code into the Espruino board via USB.
Open a browser and use the IP address to access the hardware via Wi-Fi.
Example:
http://192.168.1.3:8080/
You should see a directory of the SD card.
If you click on an HTML file, it will load the Webpage instead of displaying the content as text.
If the HTML file loads a .js file on the SD card it should work as well.
From the SD card directory, if you clicl on a .csv file, your browser will launch Excel and download the csv file into a workbook. You can then save the data to your hard drive.
The code follows:
Note the POST function is a stub for now.
These links may be of use in the switch statement
https://en.wikipedia.org/wiki/Media_type
https://www.iana.org/assignments/media-types/media-types.xhtml#application
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Beta Was this translation helpful? Give feedback.
All reactions