Skip to content

Commit

Permalink
Upgrade to esptool.py 2.6 as per the upstream repo
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstoer committed Mar 12, 2019
2 parents 18cc721 + 4954c93 commit b098526
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 169 deletions.
4 changes: 2 additions & 2 deletions About.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class AboutDlg(wx.Dialog):
<p>For help and support, please visit <a style="color: #004CE5;"
href="https://support.thingpulse.com">support.thingpulse.com</a>.
<p>Original work &copy; 2018 Marcel St&ouml;r.<br/>
Modifications &copy; 2018 ThingPulse, Ltd.<br/>
<p>Original work &copy; 2019 Marcel St&ouml;r.<br/>
Modifications &copy; 2019 ThingPulse, Ltd.<br/>
Open source under the MIT license.</p>
<p>
Expand Down
76 changes: 35 additions & 41 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
from serial.tools import list_ports
from esptool import ESPLoader
from esptool import NotImplementedInROMError
from esptool import FatalError
from argparse import Namespace

__version__ = "1.0"
__version__ = "2.0"
__app_name__ = "ThingPulse App Fairy"
__auto_select__ = "Auto-select"
__auto_select_explanation__ = "(first port with Espressif device)"
__supported_baud_rates__ = [9600, 57600, 74880, 115200, 230400, 460800, 921600]

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -58,46 +61,34 @@ def __init__(self, parent, config):

def run(self):
try:
print("esptool.py v%s" % esptool.__version__)
initial_baud = min(ESPLoader.ESP_ROM_BAUD, self._config.baud)

esp = ESPLoader.detect_chip(self._config.port, initial_baud)
print("Chip is %s" % (esp.get_chip_description()))
print("Features: %s" % ", ".join(esp.get_chip_features()))
esptool.read_mac(esp, Namespace())

esp = esp.run_stub()

if self._config.baud > initial_baud:
try:
esp.change_baud(self._config.baud)
except NotImplementedInROMError:
print("WARNING: ROM doesn't support changing baud rate. Keeping initial baud rate %d." %
initial_baud)

args = Namespace()
args.flash_size = "detect"
args.flash_mode = self._config.mode
args.flash_freq = "40m"
args.no_progress = False
args.no_stub = False
args.verify = False # TRUE is deprecated
args.compress = True
args.addr_filename = [[int("0x00000", 0), open(self._config.firmware_path, 'rb')]]

print("Configuring flash size...")
esptool.detect_flash_size(esp, args)
esp.flash_set_parameters(esptool.flash_size_bytes(args.flash_size))
command = []

if not self._config.port.startswith(__auto_select__):
command.append("--port")
command.append(self._config.port)

command.extend(["--baud", str(self._config.baud),
"--after", "no_reset",
"write_flash",
"--flash_mode", self._config.mode,
"0x00000", self._config.firmware_path])

if self._config.erase_before_flash:
esptool.erase_flash(esp, args)
esptool.write_flash(esp, args)
# The last line printed by esptool is "Leaving..." -> some indication that the process is done is needed
print("\nDone. Unplug/replug or reset device.")
command.append("--erase-all")

print("Command: esptool.py %s\n" % " ".join(command))

esptool.main(command)

# The last line printed by esptool is "Staying in bootloader." -> some indication that the process is
# done is needed
print("\nApplication successfully installed. Unplug/replug or reset device \nto switch back to normal boot "
"mode.")
except SerialException as e:
self._parent.report_error(e.strerror)
raise e


# ---------------------------------------------------------------------------


Expand All @@ -117,7 +108,7 @@ def load(cls, file_path):
if os.path.exists(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
conf.port = data['port']
conf.port = data.get('port', "")
conf.baud = data['baud']
conf.mode = data['mode']
conf.erase_before_flash = data['erase']
Expand All @@ -143,7 +134,7 @@ def is_complete(self):
class NodeMcuFlasher(wx.Frame):

def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(700, 650),
wx.Frame.__init__(self, parent, -1, title, size=(725, 650),
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
self._config = FlashConfig.load(self._get_config_file_path())

Expand All @@ -154,9 +145,11 @@ def __init__(self, parent, title):

sys.stdout = RedirectText(self.console_ctrl)

self.SetMinSize((640, 480))
self.Centre(wx.BOTH)
self.Show(True)
print("Connect your device")
print("\nIf you chose the serial port auto-select feature you might need to ")
print("turn off Bluetooth")

def _init_ui(self):
def on_reload(event):
Expand Down Expand Up @@ -211,7 +204,7 @@ def on_pick_file(event):
file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, on_pick_file)

serial_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
serial_boxsizer.Add(self.choice, 1, wx.EXPAND)
serial_boxsizer.Add(self.choice, 1, wx.EXPAND)
serial_boxsizer.AddStretchSpacer(0)
serial_boxsizer.Add(reload_button, 0, wx.ALIGN_RIGHT, 20)

Expand Down Expand Up @@ -263,7 +256,8 @@ def add_erase_radio_button(sizer, index, erase_before_flash, label, value):
button.Bind(wx.EVT_BUTTON, on_clicked)

self.console_ctrl = wx.TextCtrl(panel, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
self.console_ctrl.SetFont(wx.Font(13, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.console_ctrl.SetFont(wx.Font((0, 13), wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL))
self.console_ctrl.SetBackgroundColour(wx.WHITE)
self.console_ctrl.SetForegroundColour(wx.BLUE)
self.console_ctrl.SetDefaultStyle(wx.TextAttr(wx.BLUE))
Expand Down Expand Up @@ -299,7 +293,7 @@ def _select_configured_port(self):

@staticmethod
def _get_serial_ports():
ports = [""]
ports = [__auto_select__ + " " + __auto_select_explanation__]
for port, desc, hwid in sorted(list_ports.comports()):
ports.append(port)
return ports
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Self-contained installer based on [NodeMCU PyFlasher](https://github.com/marcelstoer/nodemcu-pyflasher) for ThingPulse applications

![Image of NodeMCU PyFlasher GUI](images/gui.png)
![Image of ThingPulse App Fairy](images/gui.png)

## Installation
ThingPulse App Fairy does not have to be installed, just double-click it and it'll start. Check the [releases section]
Expand All @@ -22,9 +22,19 @@ support forum](https://support.thingpulse.com).
## Build it yourself
If you want to build this application yourself you need to:

- Install Python 3.x
- Install [wxPython 4.x](https://wxpython.org/) manually or run `pip install wxpython`
- Install [esptool.py](https://github.com/espressif/esptool#easy-installation) and its dependencies manually or run `pip install esptool`
- Install [Python 3.x](https://www.python.org/downloads/) and [Pip](https://pip.pypa.io/en/stable/installing/) (it comes with Python if installed from `python.org`).
- Create a virtual environment with `python -m venv venv`
- Activate the virtual environment with `. venv/bin/activate` (`. venv/Scripts/activate` if you are on Windows with [Cygwin](https://www.cygwin.com/) or [Mingw](http://mingw.org/))
- Run `pip install -r requirements.txt`

**A note on Linux:** As described on the [downloads section of `wxPython`](https://www.wxpython.org/pages/downloads/), wheels for Linux are complicated and may require you to run something like this to install `wxPython` correctly:

```bash
# Assuming you are running it on Ubuntu 18.04 LTS with GTK3
pip install -U \
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 \
wxPython
```

## License
[MIT](http://opensource.org/licenses/MIT) © Marcel Stör (a ThingPulse co-founder)
7 changes: 5 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env bash
#rm -fr build dist
VERSION=2.0
NAME="ThingPulse App Fairy"

pyinstaller --log-level=DEBUG \
--noconfirm \
build-on-mac.spec

#https://github.com/sindresorhus/create-dmg
create-dmg --overwrite "dist/ThingPulse App Fairy.app"
mv "ThingPulse App Fairy 0.0.0.dmg" "dist/ThingPulse-App-Fairy.dmg"
create-dmg --overwrite "dist/$NAME.app"
mv "$NAME 0.0.0.dmg" "dist/$NAME-$VERSION.dmg"
Loading

0 comments on commit b098526

Please sign in to comment.