MidNite USB Firmware Update Utility
Copyright MidNite Solar Inc. 2012
Andrew Meares
10/30/2012

Updated 10-16-2013 (boB)


Description:
The mnupdate utility is a Python script that uploads a MidNite firmware through
a USB COM port.  The script requires Python 2.7 and the pyserial module which 
can be installed in Debian or Ubuntu systems using:

apt-get install python-serial

In order to function, the mnupdate.py script must have execute permissions and
have permissions to access the serial port device.  In most systems the 
MidNite device, for example a Classic Charge Controller, should show up as 
"/dev/ttyACM0".


Instructions:
To update the firmware on your Classic Charge Controller use the following
procedure:
1. Switch off the Classic battery and PV inputs using your battery breaker.
   This turns your Classic off completely.
2. Plug your computer into the USB port on the Classic.
3. With the Classic off, run the mnupdate utility in your terminal with the
   proper options.  The options are described later in this document.
4. When "Waiting for serial device." is displayed, switch the battery breaker to
   turn on your Classic.  The Classic should boot and the mnupdate utility 
   should connect and automatically begin uploading the firmware.
5. The firmware can take a few minutes to upload, so be patient.
6. Once the mnupdate utility has finished running, cycle the power on your
   Classic.



Command Line Options:
usage: mnupdate.py [-h] [-d DEVICE] [-b {9600,19200,57600}] [-t TIMEOUT]
                   [-m MESSAGE] [-z SLEEP] [-r] [-s]
                   filename

A utility for updating firmware via a USB COM port.

positional arguments:
  filename              Firmware file path/name

optional arguments:
  -h, --help            show this help message and exit
  -d DEVICE, --device DEVICE
                        Device path/name
  -b {9600,19200,57600}, --baudrate {9600,19200,57600}
                        Device baudrate
  -t TIMEOUT, --timeout TIMEOUT
                        Timeout in seconds
  -m MESSAGE, --message MESSAGE
                        Upload message
  -z SLEEP, --sleep SLEEP
                        Sleep time in seconds
  -r, --repeat          Repeat message?
  -s, --silent          Silent?


Examples:
For a basic Classic update simply use:
./mnupdate.py INSERT_FILENAME.ctl

In order to update your MNGP you must use the repeat option and a special message.
./mnupdate.py -r -m uPlDrEMaLLfl INSERT_FILENAME.rem

The '-d' option can be used to specify a specific device other than '/dev/ttyACM0'. 
./mnupdate.py -d /dev/ttyACM1 INSERT_FILENAME.ctl

If for some reason the program trys to acquire the serial port too quickly, it
may work to increase the sleep time as follows.
./mnupdate.py -z 3 INSERT_FILENAME.ctl


Choosing a Firmware Update File:
The proper file for your particular device must be chosen.  There are different
firmwares for different Classic voltages and for the MNGP.  The Classic firmware
files terminate in '.ctl' and the MNGP terminate in '.rem'
and are available from the MidNite Solar web page.



Classic 150 example with a real file name...
To update the Classic firmware, first turn OFF the Classic's power,
run this line and then turn the Classic power ON and wait...

./mnupdate.py Classic_ALL_1849_150V_4-21-2014.ctl



To update the MNGP Remote firmware, first turn OFF the Classic's power,
run this line and then turn the Classic power ON and wait...
The MNGP code update passes through the Classic USB and through its
RS232 connecttion and so the -r option needs to be added for the
command to Repeat...

./mnupdate.py -r -m uPlDrEMaLLfl MNGP_ALL_1821_4-15-2014.rem


****************************************************************************
****************************************************************************

mnupdate.py will work for Linux and OSX. Ubuntu and Debian distributions will be the easiers from our experience.

Updating with Apple Mac OSX ....

Please refer to     README_Mac.txt

****************************************************************************
****************************************************************************

The catch with OSX is that the python and the pyserial module (see pyserial link below)
will have to be installed manually.

The classic usb device shows up as a different file (deadC0D or similar) instead of /dev/ttyACM0 as in Linux.


Resources:
http://www.midnitesolar.com/
http://pyserial.sourceforge.net/

