Author Topic: Bugs in oak cli - --device doesn't work as expected.  (Read 1939 times)

JohnP

  • Newbie
  • *
  • Posts: 11
Bugs in oak cli - --device doesn't work as expected.
« on: October 01, 2016, 12:16:03 pm »
oak -d device

I'm trying to automate programming a fleet of oaks with a makefile

The following works as expected, using whatever board I've previously selected with the oak cli tool:

Code: [Select]
BUILD="digistump:oak:oak1:CpuFrequency=80,UploadTool=oak_ota,FlashSize=OAK,RomConfig=Full"
$(ARDUINO)  --board $(BUILD) --upload $(PROJECT).ino

Now I'd like to use more than one board, and switch between them in the various Makefiles.  The oak cli says
Quote
$ oak --help

  Usage: nexe [-d deviceName] <binary file to upload>
  Options:
    -h, --help                  output usage information
    -V, --version               output the version number
    -d, --device <device name>  target device name
  • Bug #1: The displayed program name is wrong:  nexe?
  • Bug #2: The tool gratuitously clears the screen and presumes it will be used interactively to choose more than one board.  Huh?  That's NOT how a CLI works.  One task, one job, not an interactive tool.  Fix:  add --loginname and --loginpassword (or, better, allow them to be set in env variables for security), and only bring up interactive mode if no arguments given.
  • Bug #3: Until I sudo oak once, it prompts me for particle credentials interactively every time it is invoked.  Why does it have to be superuser to remember my credentials?
  • Bug #4: Even when I use -d <devID>, the tool doesn't exit - it stays in interactive mode, making it useless for use as a command line tool.
  • Bug #5: What's with the <binary file to upload>?  The Arduino CLI environment doesn't produce a binary to upload, it does the upload itself.  Treat this argument as optional, and do nothing if not given.




PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Bugs in oak cli - --device doesn't work as expected.
« Reply #1 on: October 02, 2016, 02:22:57 am »
OakCLI is an odd tool... it is either meant to be run interactively to change the default board being programmed - or run by the Arduino IDE to do the actual upload (which I'll talk about further in a moment). I still generally agree with #1-4 on the whole though... it may have been better to have made it two separate programs (although I also know plenty of programs that are interative if you run them with no parameters, and if you give them the right ones, they become non-interative / batch mode). I might go poking around in the code on github and see if I can send Erik some pull requests to make some of that a bit more user friendly.

Just on #5 ... No... the arduino IDE does NOT upload to the Oak itself. This is the case with standard arduino boards, but not with the Oak, Digispark, STM32 devices, ESP8266 devices, and a few others. It is actually passed on to the helper programs, and in the case of the Oak, this is... oakcli! :D The Arduino IDE builder compiles the code into a binary as per the compiler recipes, and passes the binary file to OakCLI for OTA upload, or to esptool.py (correct naming?) for serial upload.

i.e. if you run the Arduino IDE, and go Sketch -> Export compiled binary, you should be able to get the generated binary (which has been copied from the temporary folder to the sketchbook folder, so do a Sketch -> Show Sketch Folder to see the contents of the sketch folder, and get the binary file that you should then be able to shove into oakcli.

However, getting back to your makefile... maybe it would be easier to avoid using oakcli for this specific task? What you really want to do is to change the default device to be programmed, and then let the Arduino IDE compile and upload (thus using oakcli as it was intended). On windows, you would be able to achieve this by editing one (or possibly three) lines in the %appdata%\Oak\config.json file (when you change the device in oakcli, it should tell you up the top where the config file is when it updates it). Since I believe you're on a Mac... maybe look for the equivalent file, and either make several copies of it which you can swap in and out as you want to change devices, or edit the file accordingly. The contents of the file looks like this (minus the Xs!):

Code: [Select]
{
  "access_token": "c796XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "devices": [
    {
      "device_id": "d957XXXXXXXXXXXXXXXXXXXX",
      "device_name": "Oak1",
      "active": false
    },
    {
      "device_id": "d957XXXXXXXXXXXXXXXXXXXX",
      "device_name": "Oak3",
      "active": false
    },
    {
      "device_id": "d957XXXXXXXXXXXXXXXXXXXX",
      "device_name": "Oak5",
      "active": true
    },
    {
      "device_id": "d957XXXXXXXXXXXXXXXXXXXX",
      "device_name": "Oak2",
      "active": false
    },
    {
      "device_id": "d957XXXXXXXXXXXXXXXXXXXX",
      "device_name": "Oak4",
      "active": false
    }
  ],
  "device_id": "d957XXXXXXXXXXXXXXXXXXXX",
  "device_name": "Oak5 (Device ID: d957XXXXXXXXXXXXXXXXXXXX)"
}

You only need to which one is active if you want to change the default OTA upload target. The extra device_id and device_name listed at the bottom doesn't appear to be used or displayed.

Hope that is of some help.

JohnP

  • Newbie
  • *
  • Posts: 11
Re: Bugs in oak cli - --device doesn't work as expected.
« Reply #2 on: October 04, 2016, 08:36:41 am »
> swap json files in and out from makefile...

Great idea - and thanks for the insight on oakcli

  -John