Hi all, thanks a bunch for this post - it helped me a lot and I got my custom Arduino Simblee doing OTA programming from Android, and also using flash memory for user data retention.
I wrote the below idiots step-by-step guide, mostly paraphrasing tolson's wisdom. I figured it's worth posting because the more information out there on this, the better. Yep, I even registered an account just to post it.
I also did some trial and error on sketch sizes (44% is about the limit) and how they are dealt with in OTA programming, which is at the end.
SteveSimblee OTA using Android (step by step):
To set up for it:
0. I'm running Windows 10 on PC
1. Install Python 2.7 (NOT 3)
2. Install packages to make it work, ie.:
b. Microsoft Visual C++ v9.0 (per link in error message)
c. The latest version of nrfutil (0.5.2) that still works with Simblee, from https://github.com/NordicSemiconductor/pc-nrfutil/tree/0_5_2
d. DON'T JUST AUTOMATICALLY INSTALL THE LATEST NRFUTIL VERSION - it won't work
e. install with "python setup.py install" (may need to be in the same folder or put in paths)
f. may need to move the "nordicsemi" folder to the right place
3. Install on android phone "nRF toolbox" app
4. Make sure the code in the Simblee has functionality for OTA (and if you upload via USB cable, you should see the main and the ota memory banks get written).
To do it:
1. Compile (Ctrl-R) the sketch in Arduino IDE or whatever you like
2. Check size of sketch is ok - ie. 33% works, 44% seems not to
3. Find the resulting hex file - should be at C:\Users\<your name>\AppData\Local\Temp, and called "ElkLight_V_rev0_4_trimmed.ino.hex" or similar
4. Copy this to C:\Python27\Scripts
5. Run command line and navigate to C:\Python27\Scripts
6. Paste nrfutil dfu genpkg SFlightSmall.zip --application ELtesting.hex --application-version 0xffff --dev-revision 0xffff --dev-type 0xffff --sd-req 0xfffe
7. (SFlightSmall.zip is the name of the output file that goes to the smartphone)
8. Copy the created zip file (ie. SFlightSmall.zip) to your phone memory somehow (Dropbox is easy, and works very well)
9. Ensure bluetooth is enabled on the Simblee (DOESN'T have to be in FWU or whatever, just normal mode)
10. On Android smartphone, run the "nRF Toolbox" app and select DFU
11. Select file, and browse to the zip file ("select Distribution packet (ZIP)") - you should be returned to the DFU (Device Firmware Update) screen and your selected file name should be shown.
12. Hit "Select Device" and scan if necessary, your Simblee should come up under "Available Devices" (NOT "bonded devices"). Even if it's already selected, this is just remembered from last time - it's worth selecting again so you know for sure bluetooth is activated
13. Select the Simblee, and the you will be returned to the DFU screen - your Simblee name should show at the top and the "Upload" button is no longer greyed out.
14. Hit the "Upload" Button
15. You should see a bit of stuff happen in the status bar, and then an uploading % sequency go from 0 to 100%. This took about 30sec for me, and then there's a success message.
16. Try to avoid the phone screen going off - it goes a bit weird sometimes
17. The Simblee should reset and be running the new firmware straight away.
1. If you are writing user data to flash (ie. as you would for EEPROM in regular Arduino) then you are likely using page 251 per the examples. This will screw up your OTA programming.
Thanks to Tim's post at http://forum.rfduino.com/index.php?topic=1347.0
I've done some investigation and found that sketches and SimbleeBLE are written to flash starting at page 124, and the OTA boot loader occupies pages 240-251. That leaves pages in between for writing application data.
I used page 237 for successful implementation of both OTA and flash memory writing. Tested for preservation of data between resets/power cycles, but doesn't preserve data between programming.
Other values I tried (and results):
230,235,237 - preserve data across resets, and allow OTA to work
250, 251 - preserve data across resets, but prevents OTA from working
238,239 - allows OTA to work, but doesn't preserve data across resets
240 - stops the whole thing running when it's written to!
2. Size of sketch for OTA. By trial and error, I determined the maximum allowable size for OTA to still work is about 59kB (that's the zip file size - about 44% of memory by the by Arduino IDE).
"Sketch uses 59,272 bytes (45%) of program storage space. Maximum is 131,072 bytes.
Global variables use 4,492 bytes of dynamic memory."
You don't get any error messages if you go slightly higher, and you can still program by USB cable just fine - the OTA will just quietly not work, and drive you mad. I didn't test this with using flash memory for user data, so it's probably a bit less in this case.