vigs
Posts: 1
Joined: Tue May 15, 2018 9:51 pm

Fast boot to use Pi Zero W's onboard BT - best approach?

Tue May 15, 2018 10:12 pm

Hope you all are having a pleasant day

I am working on a battery-powered project based on the Pi Zero W where a button (connected to Reset) is pressed to start the Pi, which connects via Bluetooth to a pre-trusted smartphone and uses the oFono telephony service to start a phone call to a predetermined number on said smartphone. Once the call is initiated, the Pi shuts down, disconnecting from the smartphone and allowing the call to be carried out using the phone's speaker/mic.

I've gotten a proof of concept working on Raspbian, where rc.local starts my Python script. In this script I use the subprocess class to issue the terminal commands to establish a Bluetooth connection with the smartphone, run the oFono script which initiates the call, then shutdown the system. My goal now is to optimize boot time.

I define boot time for this application as the time it takes from the pressing of the button to the call being initiated on the smartphone. Currently, on Raspbian, this is about 40-50 seconds. I would ideally like this to be less than 10 seconds, but my expectations may be completely skewed due to my lack of expertise.

I've come up with the following three approaches to reducing boot time:

1) analyze Raspbian's startup services and strip it down,
2) create a custom Linux system (using e.g. Buildroot or piCore) that only does what I need, or
3) a bare metal approach, where I communicate directly with the BCM4348 bluetooth chip

Out of these, 1 would be the easiest but probably be the least effective. 3 would give the best learning value as well as performance, but might be extremely tedious (documentation seems to be lacking). Going the route of 2 might work, but I'm pretty clueless as to what services I would need.

What's the best approach? Any useful resources/pointers? This isn't really a project for commercial use - I've just taken it on for a friend who wants a "physical button" speed dial and am using it for my learning experience more than anything else.

I'm just looking for thoughts, suggestions, and other ideas. Thanks in advance.

epoch1970
Posts: 1465
Joined: Thu May 05, 2016 9:33 am

Re: Fast boot to use Pi Zero W's onboard BT - best approach?

Wed May 16, 2018 1:00 pm

I think it is mostly a matter of systemd vs the rest of the world, often vs. busybox.

piCore would boot faster than a stock Raspbian Lite for sure. By how much, it depends on what your Raspbian system(d) finds necessary to do.
A great advantage of piCore is that it is much more resilient to power failure: root is in RAM, extensions (BT packages) mounted read-only. If you use the "copy2fs" facilities you can have everything in RAM, but boot takes a little extra time.
piCore is a binary distribution and there are plenty of packages already built. It's as easy as Debian, once you've understood the way it works.

Building your own distro is more involved.
I'm not sure a Buildroot system would go much faster than piCore, and if you want to run in RAM you have to setup the build for that. There is no packaging system in Buildroot. What you cross-compile is what you get on the target (and you can't build a compiler.)
Yocto (open embedded) is another popular build system. If someone has setup and maintains layers (recipes to build system) that you can reuse, then it works almost magic. By combining layers you get the effect of a package manager working from source. Besides, a Yocto build can generate binary packages if you ask it to (rpm, deb or ipk), and you can build a package manager in the target to install them at runtime.
If you don't find already made and well-maintained layers, I would choose Buildroot which is a simpler environment.
(Buildroot and Yocto can build systems that use systemd init but I guess you don't want that ...)
This blog has reasonably recent and really good posts on applying the Yocto and BR build chains to a Pi.

If you're interested in generating your distro, or even going bare-metal then take the time and do that. Otherwise I would go for piCore.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

hippy
Posts: 2837
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Fast boot to use Pi Zero W's onboard BT - best approach?

Wed May 16, 2018 1:43 pm

Seeing as this is a "battery powered, push a button, connect over Bluetooth, dial a number, turn off" application a microcontroller and serial controlled Bluetooth module may be more appropriate. Perhaps a micro:bit can do everything you need.

Just because a Pi is fairly cheap, an amazing product, it doesn't mean it is the best or even appropriate tool for every job. It is often better, easier and cheaper to use something more appropriate than it is to try and make a Pi suitable, having to overcome its limitations through not being designed for what one wants to do.

I don't know exactly what Bluetooth interactions you need to use but I would have thought the whole job could be done with a micro and HC-05 module in just a couple of dozen lines of code. No need to worry about power management, SD Card corruption, customised Linux and all that effort.

In the time taken trying to figure out how to jump over the hurdles choosing a Pi creates it seems entirely possible to have the thing up and running and finished using something more appropriate.

Don't get me wrong; I'm not against the Pi. It is brilliant for what it was designed for, but it wasn't designed to fit every role.

Return to “General discussion”

Who is online

Users browsing this forum: il_diavolo and 11 guests