Skip to content

Commit

Permalink
Merge pull request #35 from elfrinjo/master
Browse files Browse the repository at this point in the history
Fixes for python 3 and screenshots of vs-code
  • Loading branch information
idolpx committed Jan 17, 2020
2 parents 8e70d6e + b3737f1 commit 9b66d4c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
15 changes: 10 additions & 5 deletions README.md
Expand Up @@ -33,18 +33,23 @@ I use PlatformIO to build this. http://platformio.org/
* Once updated and restarted, clone the "mobile-rr" project to a folder and open the project in PlatformIO
* Next build the firmware by clicking the checkmark icon on the toolbar

![Build Firmware](doc/1.buildfirmware.png)
| Atom | Visual Studio Code |
:-----------------------------------------:|:-----------------------------------------------:|
![Build Firmware](doc/1.buildfirmware.png) | ![Build Firmware](doc/1.buildfirmware_vscode.png)

## Upload Firmware and SPIFFS data
After your firmware build is successful you can upload it by clicking the arrow under the checkmark in the PlatformIO toolbar.

![Upload Firmware](doc/2.uploadfirmware.png)
| Atom | Visual Studio Code |
:-------------------------------------------:|:-------------------------------------------------:|
![Upload Firmware](doc/2.uploadfirmware.png) | ![Upload Firmware](doc/2.uploadfirmware_vscode.png)

You can add/edit the files in the "www" folder to your liking. (Files in the "www" folder will be cloned and gzipped to the "data" folder when building.) Then follow the instructions below to build and upload the SPIFFS file system image to your ESP8266.

![Upload SPIFFS 1](doc/3.uploadspiffs.png)

![Upload SPIFFS 2](doc/4.uploadspiffs.png)
| Atom | Visual Studio Code |
:-----------------------------------------:|:-----------------------------------------------:|
![Upload SPIFFS 1](doc/3.uploadspiffs.png) | ![Upload SPIFFS 1](doc/3.uploadspiffs_vscode.png)
![Upload SPIFFS 2](doc/4.uploadspiffs.png) | ![Upload SPIFFS 2](doc/4.uploadspiffs_vscode.png)

**Note: Anytime you make changes to the firmware or the data you can rebuild and upload either without the need to install the other again. They reside in different areas of the flash memory.**

Expand Down
Binary file added doc/1.buildfirmware_vscode.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/2.uploadfirmware_vscode.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/3.uploadspiffs_vscode.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/4.uploadspiffs_vscode.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions platformio.ini
Expand Up @@ -46,7 +46,6 @@ upload_speed = 921600

# Uncomment the following lines to update Over The Air (OTA)
#upload_port = 10.10.10.1
#upload_flags = --auth=password
#upoad_flags = --auth=password

upload_port = /dev/cu.wchusbserial14440
upload_speed = 921600
upload_port = /dev/cu.wchusbserial14440
38 changes: 19 additions & 19 deletions www_proc.py
Expand Up @@ -69,41 +69,41 @@ def minify_css(css):

# output rule if it contains any declarations
if properties:
print "%s{%s}" % ( ','.join( selectors ), ''.join(['%s:%s;' % (key, properties[key]) for key in porder])[:-1] )
print("%s{%s}" % ( ','.join( selectors ), ''.join(['%s:%s;' % (key, properties[key]) for key in porder])[:-1] ))

return css

def embed_css(content):
pattern = re.compile(ur'<link.*href=[\'"](.*?)[\'"].*/>')
pattern = re.compile(u'<link.*href=[\'"](.*?)[\'"].*/>')

# Combine CSS
matches = re.findall(pattern, content)
css_content = ''
for match in matches:
css_content = css_content + '<style>\n' + read_file(data + match) + '\n</style>\n'
os.remove(data + match)
print match
print(match)

if len(css_content.strip()):
# Remove CSS includes from Content
content = pattern.sub('', content)

css_content = minify_css(css_content)
pattern = re.compile(ur'</head>')
pattern = re.compile(u'</head>')
content = pattern.sub(css_content + '\n</head>', content)

return content


def combine_js(content):
# Combine Javascript
pattern = re.compile(ur'<script.*src=[\'"](.*?)[\'"].*?</script>')
pattern = re.compile(u'<script.*src=[\'"](.*?)[\'"].*?</script>')
matches = re.findall(pattern, content)
js_content = ''
for match in matches:
js_content = js_content + read_file(data + match) + '\n'
os.remove(data + match)
print match
print(match)

# Save combined file
if len(js_content.strip()):
Expand All @@ -119,13 +119,13 @@ def combine_js(content):

# Update HTML Content
if len(js_content.strip()):
pattern = re.compile(ur'</head>')
content = pattern.sub(ur'<script src="script.js"></script>\n</head>', content)
pattern = re.compile(u'</head>')
content = pattern.sub(u'<script src="script.js"></script>\n</head>', content)

return content

def embed_media(content):
pattern = re.compile(ur'<(?:img|audio).*src=[\'"](.*?)[\'"].*>')
pattern = re.compile(u'<(?:img|audio).*src=[\'"](.*?)[\'"].*>')

# Combine CSS
matches = re.findall(pattern, content)
Expand All @@ -134,14 +134,14 @@ def embed_media(content):
media_content = read_media(data + match)
media_content = "data:" + get_mimetype(match) + ";base64," + media_content
os.remove(data + match)
print match
print(match)
content = re.sub(match, media_content, content)

return content

# Build httpdocs for web server
def before_buildfs(source, target, env):
print "before_buildfs"
print("before_buildfs")

# SPIFFS Stats With Different Combinations of Processing
# Updated: 12.28.2016
Expand All @@ -163,7 +163,7 @@ def before_buildfs(source, target, env):
if re.search(r'css|js|media', options):
for file in files:
if re.search(r'\.htm', file):
print file
print(file)
content = read_file(file)
if re.search(r'css', options):
content = embed_css( content )
Expand All @@ -179,34 +179,34 @@ def before_buildfs(source, target, env):

# gzip appropriate files
if re.search(r'gz', options):
pattern = re.compile(ur'\.htm|\.css|\.js|\.map|\.svg|\.ico')
pattern = re.compile(u'\.htm|\.css|\.js|\.map|\.svg|\.ico')
for file in files:
if re.search(pattern, file):
if os.path.exists(file):
print file
print(file)
gzFile( file )


# remove 'data' folder after upload
def after_uploadfs(source, target, env):
print "after_uploadfs"
print("after_uploadfs")
rmtree(data)

Import("env")
config = configparser.ConfigParser()
config.read("platformio.ini")

options = config.get("env:d1_mini_pro","custom_option")
print config.sections()
print(config.sections())

# Set parameters from environment variables
data = env['PROJECT_DIR'] + "/data/"
www = env['PROJECT_DIR'] + "/www/"

# Show parameters
print data
print www
print options
print(data)
print(www)
print(options)

# Only run when building & uploading SPIFFS image
#env.AddPreAction("buildfs", before_buildfs)
Expand Down

0 comments on commit 9b66d4c

Please sign in to comment.