Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By SwiCago
#22270 Cool, glad ESP8266WebServer has been updated. I see you are using
WiFiClient client = server.client();
To write large data directly to the requesting client. SmartI'll have to play with that.

Have you seen whether or not the new ESP8266WebServer code supports receiving large data from client?
I would like clients to be able to submit a images and store on SD card

Nevermind: Found this cool example to read and write to SD card
https://github.com/esp8266/Arduino/tree ... DWebServer
I should be able to tweak it for my purpose.
User avatar
By voyager
#22283 @ Torx
Hi looks good what you have done. I tried to compile the files you have posted. But failed. This is what i did.
I created a project in my sketchbook folder called WS_Flash. In that i copied your ino file and named it WS_Flash.ino. In the same folder i saved your Flash.h.
Created a Folder 'websites' under WS_Flash. Copied your sample websites.h into this folder.

Compiled and got the following message:
WS_Flash.ino:5:31: fatal error: websites/websites.h: No such file or directory
compilation terminated.
I am using Arduino 1.6.5.
What nonsense have i done?
User avatar
By HeavyFule
#34229 Thanks so much the post Torx.
It worked great for me. More importantly I learned a lot working through your code.
Nice!

Working on Windows, I needed an alternative to the shell script.
I've never programmed in Python so I thought I would give it a try.
It's probably pretty clunky but I will include it here in the hopes that
it will be useful to others.

I'm running Python 3.4 on my computer.

1.Paste it into an new IDOL file.
2.Change the target directory to your target directory.
3.Make sure you have a /website sub directory.
4.Run it.


Code: Select all#! python3
import os
import sys

# Set-up the directories
os.chdir('C:\\path\\to\\your\\target\\directory') #  <---Change this
CURDIR = os.getcwd()
OUTFILE = CURDIR + "\\website.h"
WEBSITE = "./website"

# Some predefined strings for the output file
header = '''//
// converted websites to mainly flash variables
//

#include "Flash.h"

'''
arrayPreamble = 'FLASH_ARRAY(uint8_t, file_'

structurePrototype = '''
struct t_websitefiles {
  const char* filename;
  const char* mime;
  const unsigned int len;
  const _FLASH_ARRAY<uint8_t>* content;
} files[] = {
'''

# Mime type - file extension is converted to lower before lookup
mimeDictionary = {'.jpg':'image/jpeg', '.jpeg':'image/jpeg', '.gif':'image/gif', '.css':'text/css', '.js':'application/javascript',
                  '.png':'image/png', '.htm':'text/html', '.html':'text/html', '.txt':'text/plain','.ico':'image/x-icon'}




BytesPerRow = 20  # This determines how wide the file will be
fileIndex = 0

if os.path.isdir(WEBSITE):
    outFile = open(OUTFILE,'w')
    outFile.write(header)
    os.chdir(WEBSITE)
    files = [f for f in os.listdir(os.curdir) if os.path.isfile(f)]  # All the files in the current directory
    print("Processed files :")
    for f in files:
        print(f)
        outFile.write(arrayPreamble + str(fileIndex) + ',\n  ')
        fp = open(f,'rb')
        fileLength = os.fstat(fp.fileno()).st_size
        totalWritten = 0
        bytesWrittenToRow = 0
        while totalWritten < fileLength - 1 :
            b = fp.read(1)
            outFile.write(hex(b[0]) + ',')
            bytesWrittenToRow += 1
            totalWritten +=1
            if bytesWrittenToRow >= BytesPerRow :
                outFile.write('\n  ')
                bytesWrittenToRow = 0

        b = fp.read(1)
        outFile.write(hex(b[0]) + '\n);\n\n')
        fp.close()
        fileIndex += 1

    outFile.write(structurePrototype)
    fileIndex = 0
    for f in files:
        extension = os.path.splitext(f)[1]
        extension = extension.lower()
        fileLength = os.stat(f).st_size
        fileType = mimeDictionary.get(extension,None)
        if fileType is None:
            import ctypes  # An included library with Python install.
            ctypes.windll.user32.MessageBoxA(0, b"Unknown file type", b"File Error", 0)
            outFile.write("-------------Unknown File Type <" + extension + "> Found----------------")
            outFile.close()
            os.chdir('..')  # Change back to the parent directory
            sys.exit(1)

        outFile.write('  {\n')
        outFile.write('    .filename = "' + f + '",\n')
        outFile.write('    .mime = "' + fileType + '",\n')
        outFile.write('    .len = ' + str(fileLength) + ',\n')
        outFile.write('    .content = &file_' + str(fileIndex) + '\n  },\n')
        fileIndex += 1

    outFile.write('};')
    outFile.close()
    os.chdir('..')  # Change back to the parent directory

else:
    print(WEBSITE +" Directory not found")
    sys.exit(2)


User avatar
By treii28
#64014 Oh sweet, thanks for the post. I was just playing with xxd myself for doing similar kind of stuff. I can't wait to try this out later. I've gotten file serving working with the sd server but wanted some kind of a solution for smaller implementations that just needed a very simple web gui. It occurred to me I could minify then gzip compress the data if I could find a way to embed it in the code as binary data then serve it up. I found xxd with the -i flag and was excited until I noticed it was using unsigned char and all the webserver functions wanted const char, string or a filehandle.
Not being familiar with c++ I wasn't sure what I could change to get it to work. I tried changing the xxd type from unsigned to const on a blind hunch but the output was empty in the browser. Were there any particular hitches you ran into once you got the updated server code that I should keep an eye out for?