Po-util: The Ultimate Local Particle Experience for Linux and macOS

##2017-6-2: UPDATE

I am now using Gitbook and netlify to host the new po-util documentation!

I have also created the https://master.po-util.com branch subdomain on netlify which allows me to host the EXACT same files as in the master branch of the po-util repository on Github.

With this new branch subdomain I can provide cooler, shorter, and secure download links, like the new install script, which is available at https://master.po-util.com/install.

To install po-util on macOS or Linux you can now run the following to use the install script to automatically download the correct po-util version for your operating system:

$ bash <(curl -sL https://master.po-util.com/install)

I've also been making many improvements recently and I would recommend joining the po-util community on gitter to directly engage in discussing the development of po-util.

2017-6-22: UPDATE

I’ve addressed my feature request for particle-cli and now made it a feature of po-util. Using the following function, po-util will attempt to find the URL of a library, and if it is a github link it will ask you if you’d like to download the library repository using git instead of downloading a release with particle-cli:

getLibURL()
{
  TOKEN="$(cat ~/.particle/particle.config.json | grep 'token' | grep -oE '([0-Z])\w+' | grep -v 'token')"
  DATA=$(curl -sLH "Authorization: Bearer $TOKEN" "https://api.particle.io/v1/libraries/$1" | json_pp)
  LIBURL=$(echo "$DATA" | grep "url" | grep -oE '"((?:\\.|[^"\\])*)"' | grep "http" |  tr -d '"')
}

Here is how/where getLibURL is actually used within po-util when downloading a library:

getLibURL "$LIB_QUERY"

if  ( echo "$LIBURL" | grep "github" ) > /dev/null ;
then
  green_echo "$LIB_QUERY is availiable on GitHub!"
  read -rp "Would you prefer to download it this way? (yes/no): " answer

  if [ "$answer" == "yes" ] || [ "$answer" == "y" ] || [ "$answer" == "Y" ];
  then
    echo
    cd "$LIBRARY"
    git clone "$LIBURL" "$LIB_QUERY"
    echo
    blue_echo "Downloaded $LIB_QUERY from GitHub."
    return 0
  fi
  echo
fi

There is still more to be done with po-util and I plan to work on it a lot more this summer.

Is there Front end for po-util?

There is a front end of sorts. If you use Atom you can use the keyboard build shortcuts po-util generates for you or add your own on a per project basis. Po-util is open source so feel free to make any suggestions or contributions. I’d like to create a more end user friendly front end for po-util if there was demand for it.

This is coolest invention I ever seen. But uhm…
I have Redbear duo. I’ve tried this commands.

po dfu duo
po dfu redbear
po dfu red
po dfu bear

Please choose "photon", "P1", "electron", "core", or "pi",
or choose a proper command.

Common commands include:
build, flash, clean, ota, dfu, serial, init, config, setup, library
1 Like

@ParticleIce

“duo” should work for the Redbear Duo

For device dependent commands the device type comes before the option, so it would be po duo dfu

Once you have made a project with:

po duo init PROJECT_NAME
cd PROJECT_NAME

You should be able to run commands like:

po duo build

Update:

@ParticleIce, based on that error message it looks like you are using an older version of po-util, possibly before I fully added duo support. I would highly recommend updating via reinstallation or by running:

po update

Did you install po-util using Homebrew?

Also, are you running po-util on macOS or on Linux? I checked your post history and you are likely on macOS. Recently po-util has not been able to build firmware for duo on linux and I have no idea why, but everything works fine on macOS.

2017-6-25: UPDATE

Po-util can now list particle devices connected via serial and identify their platform. This works on both Linux and macOS.

Example:

$ po list

Found the following Particle Devices:

Photon: /dev/ttyACM0

Using po list is significantly faster than particle serial list.

If you could merge those improvements back into the CLI, everybody could benefit :wink:

1 Like

Well considering the reason it is faster (by a fraction of a second) is because there isn’t any NodeJS overhead I don’t know how I could merge my bash scripting into NodeJS. :wink:

I’m also terrible at NodeJS and wouldn’t know where to start with contributing to particle-cli.

1 Like

What does this mean?

                                                 __      __  __
                                                /  |    /  |/  |
          ______    ______           __    __  _██ |_   ██/ ██ |
         /      \  /      \  ______ /  |  /  |/ ██   |  /  |██ |
        /██████  |/██████  |/      |██ |  ██ |██████/   ██ |██ |
        ██ |  ██ |██ |  ██ |██████/ ██ |  ██ |  ██ | __ ██ |██ |
        ██ |__██ |██ \__██ |        ██ \__██ |  ██ |/  |██ |██ |
        ██    ██/ ██    ██/         ██    ██/   ██  ██/ ██ |██ |
        ███████/   ██████/           ██████/     ████/  ██/ ██/
        ██ |
        ██ |
        ██/                  Building firmware for duo...

text data bss dec hex filename
5148 8 2616 7772 1e5c /Users/mac/downloads/po-util/someProject/bin/firmware.elf
../build/platform-id.mk:72: *** "Unknown platform: duo. Stop.

$ po duo dfu

Device not found!

Your device must be connected by USB.

$ dfu-util -l

dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Deducing device DFU version from functional descriptor length
Found Runtime: [05ac:8215] ver=0208, devnum=5, cfg=1, intf=3, path="250-1.1.1", alt=0, name="UNKNOWN", serial="78CA3xxxxxxxx"
Found DFU: [2b04:d058] ver=0250, devnum=5, cfg=1, intf=0, path="253-1.3", alt=2, name="@Serial Flash /0x00000000/192004Kg,128004Kg,64004Kg,128004Kg", serial="1C005200095xxxxxxxxxxxxx"
Found DFU: [2b04:d058] ver=0250, devnum=5, cfg=1, intf=0, path="253-1.3", alt=1, name="@DCT Flash /0x00000000/01016Kg", serial="1C0052000951353338363332"
Found DFU: [2b04:d058] ver=0250, devnum=5, cfg=1, intf=0, path="253-1.3", alt=0, name="@Internal Flash /0x08000000/02
016Ka,02016Kg,01064Kg,07*128Kg", serial="1C005200095xxxxxxxxxxxxxx"

Does:

$ po duo update

Even work?

Po-util compiles duo firmware fine for me on macOS. Have you updated po-util to the most recent version yet?

It's latest update. I did. I'm not sure If I pricked redbear.

$po install

You are on macOS. po-util will be installed via Homebrew

Homebrew is installed.

Installing po-util with "brew"
Warning: nrobinson2000/po/po 91.0 is already installed

Installing Particle firmware from Github...
fatal: destination path 'firmware' already exists and is not an empty directory.

Installing RedBear Duo firmware from Github...
fatal: destination path 'firmware' already exists and is not an empty directory.

Installing ARM toolchain...
Already up-to-date.
Warning: px4/px4/gcc-arm-none-eabi-49 20150925 is already installed
Warning: dfu-util 0.9 is already installed

Node.js version v6.9.1 is already installed.

Installing particle-cli...
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
/usr/local/bin/particle -> /usr/local/lib/node_modules/particle-cli/bin/particle.js
/usr/local/bin/serialport-term -> /usr/local/lib/node_modules/serialport/bin/serialport-terminal.js
/usr/local/bin/serialport-list -> /usr/local/lib/node_modules/serialport/bin/serialport-list.js
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/node-pre-gyp -> /usr/local/lib/node_modules/node-pre-gyp/bin/node-pre-gyp

serialport@4.0.7 install /usr/local/lib/node_modules/serialport
node-pre-gyp install --fallback-to-build

node-pre-gyp info it worked if it ends with ok
node-pre-gyp verb cli [ '/usr/local/bin/node',
node-pre-gyp verb cli '/usr/local/lib/node_modules/serialport/node_modules/.bin/node-pre-gyp',
node-pre-gyp verb cli 'install',
node-pre-gyp verb cli '--fallback-to-build' ]
node-pre-gyp info using node-pre-gyp@0.6.32
node-pre-gyp info using node@6.9.1 | darwin | x64
node-pre-gyp verb command install
node-pre-gyp info check checked for "/usr/local/lib/node_modules/serialport/build/Release/serialport.node" (not found)
node-pre-gyp http GET https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.7/serialport-v4.0.7-node-v48-darwin-x64.tar.gz
node-pre-gyp http 200 https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.7/serialport-v4.0.7-node-v48-darwin-x64.tar.gz
node-pre-gyp info install unpacking .deps/
node-pre-gyp info install unpacking .deps/Release/
node-pre-gyp info install unpacking .deps/Release/obj.target/
node-pre-gyp info install unpacking .deps/Release/obj.target/serialport/
node-pre-gyp info install unpacking .deps/Release/obj.target/serialport/src/
node-pre-gyp info install unpacking .deps/Release/obj.target/serialport/src/serialport.o.d
node-pre-gyp info install unpacking .deps/Release/obj.target/serialport/src/serialport_poller.o.d
node-pre-gyp info install unpacking .deps/Release/obj.target/serialport/src/serialport_unix.o.d
node-pre-gyp info install unpacking .deps/Release/serialport.node.d
node-pre-gyp info install unpacking obj.target/
node-pre-gyp info install unpacking obj.target/serialport/
node-pre-gyp info install unpacking obj.target/serialport/src/
node-pre-gyp info install unpacking obj.target/serialport/src/serialport.o
node-pre-gyp info install unpacking obj.target/serialport/src/serialport_poller.o
node-pre-gyp info install unpacking obj.target/serialport/src/serialport_unix.o
node-pre-gyp info install unpacking serialport.node
node-pre-gyp info tarball done parsing tarball
node-pre-gyp info validate Running test command: '/usr/local/bin/node --eval 'require('/usr/local/lib/node_modules/serialport/build/Release/serialport.node')''
[serialport] Success: "/usr/local/lib/node_modules/serialport/build/Release/serialport.node" is installed via remote
node-pre-gyp info ok

  • serialport@4.0.7
  • node-pre-gyp@0.6.36
  • npm@5.0.3
  • particle-cli@1.22.0
    updated 4 packages in 52.408s
Thank you for installing po-util. Be sure to check out https://po-util.com
if you have any questions, suggestions, comments, or problems. You can use
the message button in the bottom right corner of the site to send me a
message. If you need to update po-util just run "po update" to download
the latest versions of po-util, Particle Firmware and particle-cli, or run
"po install" to update all dependencies.

po duo update

This command can only be used to update the system firmware for
photon, P1, electron, or duo.

It looks like you have multiple versions of po-util installed.

Please delete the non macOS version.

What do type po and which po say?

Here's what happened? I removed redbear duo to see if po util works.

second I

particle device add 1c005200xxxxxxxx
Claiming device 1c0052000xxxxxxxxxx
Failed to claim device, server said: Device is not connected

Next I copied this to make new redbear duo.

dfu-util -d 2b04:d058 -a 0 -s 0x8008000 -D fac-dct-r1.bin
dfu-util -d 2b04:d058 -a 0 -s 0x08020000 -D duo-system-part1.bin
dfu-util -d 2b04:d058 -a 0 -s 0x08040000 -D duo-system-part2.bin
dfu-util -d 2b04:d058 -a 2 -s 0x140000 -D duo-fac-tinker.bin
dfu-util -d 2b04:d058 -a 2 -s 0x180000 -D duo-wifi-r1.bin
particle keys doctor 1c00520009xxxxxx

I installed the whole thing po-utils.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

c$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown imac /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
HEAD is now at 13576111 Merge pull request #2822 from ilovezfs/software_spec-recursive-reqs
Updated 1 tap (nrobinson2000/po).
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/imac/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
==> Updated Formulae
nrobinson2000/po/po :heavy_check_mark:
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
Anonymous Analytics — Homebrew Documentation

==> Next steps:

  • Run brew help to get started
  • Further documentation:

po init duo

Directory is already Initialized!

I've tried almost everything. is there something I'm missing?

how do I delete the non macOS version?

What do type po and which po say? It should help you locate the linux version if it is installed.

$ po
__ __ __
/ | / |/ |
______ ______ __ __ ██ | ██/ ██ |
/ \ / \ ______ / | / |/ ██ | / |██ |
/██████ |/██████ |/ |██ | ██ |██████/ ██ |██ |
██ | ██ |██ | ██ |██████/ ██ | ██ | ██ | __ ██ |██ |
██ |__██ |██ __██ | ██ __██ | ██ |/ |██ |██ |
██ ██/ ██ ██/ ██ ██/ ██ ██/ ██ |██ |
███████/ ██████/ ██████/ ████/ ██/ ██/
██ |
██ |
██/ https://po-util.com

Copyright (GPL) 2017 Nathan D. Robinson

Usage: po DEVICE_TYPE COMMAND DEVICE_NAME
       po DFU_COMMAND
       po install [full_install_path]
       po library LIBRARY_COMMAND

Run "man po" for help.

Can you run:

$ type po

And:

$ which po

$ type po
po is aliased to `~/po-util.sh’

$ which po
/usr/local/bin/po

Perfect!

Can you delete ~/po-util.sh and remove the alias in your .bashrc?