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

Might be getting a bit off this thread’s topic but how would I go about making a file structure like this work if files in one subfolder need to include files in another subfolder?

For example

firmware

  • folder1
    • folder1.h
    • folder1.cpp
      -folder2
    • folder2.h
    • folder2.cpp
  • main.cpp

and then in folder2.cpp I have:

#include "../folder1/folder1.h"

but I sense that doing things this way with the “…/” appended to the front of the file path is frowned upon. What is the correct way?

Does:

#include "folder1/folder1.h"

Work in folder2.cpp/.h to include folder1? Works for me when using libraries that depend on each other in the same project.

Right you are :wink: Cheers, this is awesome

1 Like

Even more awesome is that po-util will automatically try to download libraries that a library or project depends on. Also it has an example manager that will list avaliable examples for an installed library and allow you to load them into your project.

Here is an example, using particle-BNO055:

$ po init DEVICE_TYPE BNO055
$ cd BNO055
$ po lib get https://github.com/nrobinson2000/particle-BNO055
$ po lib ex ls particle-BNO055
$ po lib ex load particle-BNO055 simple
1 Like

You are welcome to join the po-util community on Gitter for extended discussion.

I am now using https://www.netlify.com/ to host the po-util website for free!

You can now view the site at https://po-util.com/

I like your tool. However the problem is with brew that I have no idea which directories and folder structures are created. Maybe you can add that in your description.

For example after installing I have now a folder particle and a folder redbearduo in my Github folder. Is that because I’ve run the installer from that folder? I have also a firmware folder for particle myself (I had an install before). So I don’t know if now everything is installed (particle-cli) twice?

I’m kind of a noob with terminal and Linux file structures, but I like to know where things end up on my harddrive. With brew a lot of magic happens behind the screens.

Is your tool updated with each particle firmware release, or can I do that myself by placing the firmware in the particle folder?

I am replying to this on gitter.

1 Like

##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.