My experiences with power saving on an iPhone 6S+ (may also apply to iPhone 6/6S) and older devices

I was writing this up for a friend, and I thought maybe others would benefit from this post.

iPhone power saving details

These are idea’s to pursue, if you need to satisfy the inner scientist try each one out to see what nets you the most benefits.  Newer devices won’t benefit as much.

You can always enable Low Power Mode which does other changes and is simpler that help extend battery charge without changing anything listed below.

OS Version;
iOS 11.0 had power draw issues out the gate for my iPhone 6S+
If Possible get the latest iOS 11.2, lots of fixes here.

Bluetooth;
Bluetooth when it’s on, and on older devices, it uses more power, especially in a noisy Bluetooth environment. You can check to see what is going on with a BLE app like LightBlue. That is only half the story as its only the low energy.

Wifi;
Old 2.4Ghz network mode will work the best for battery life. This is like 3G 4G mode.
The 5Ghz modes will really drain the power. This is like LTE.

If you have access to the Wifi router, you can enable some power saving features for Wifi,  you can explore if your router has that option (not to mention QoS that supports better VoIP quality.).  The feature Called WMM or WMM APSD

LTE;
And yes, you can turn off Voice over LTE, and in some cases turn off LTE altogether if you want to see the battery last longer.

Turning off Voice over LTE will prevent LTE to Wifi handoff, where the phone can hand off a voice call between the two.

 

1. Bluetooth blueborne security breach info;
   Quoted from that page
iOS
All iPhone, iPad and iPod touch devices with iOS 9.3.5 and lower, and AppleTV devices with version 7.2.2 and lower are affected by the remote code execution vulnerability
    (and iOS 10 and later the breach is fixed)

 

SpriteKit a whole new layer of debug capability! View UI Hierarchy

I knew about the UI Hierarchy for normal User Interface views, I just didn’t know I could use it with sprite kit!

ui hierarchy debugging

It also allows you to peel the layers forward/reverse to see things as they were added.

In this one screen, I’ve selected an object I had no idea was there. Holder (object 0 in an array) shouldn’t be showing up at all? What gives! Now just to figure it out and zap that bug!

Working on bCandied new release

To speed up release, I am working in Objective-C, removed the C++ PowerVR parts and refactored those bits as modules for Objective-C.  I’ve also moved over to SpriteKit. After four years it felt the right thing to do.

I’ve made numerous small edits over the years, but most everything that was at one time available has been deprecated.  And now with the Power VR chipset going byebye with the A11 Bionic chip. Yes Spritekit makes total sense.

Similarly SudokuGeek I have re-written in SceneKit but not worked on finishing it just yet in favor of bCandied!

bCandied Dev ScreenShot

One of the larger challenges was to let go of the old project and start it from scratch.  I didn’t really loose anything this way and it got rid of a Lot of SpriteKit issues that seemed like random crashes.  Perhaps something wasn’t mixing with having SpriteKit and all the old C++ PowerVR Code, at any rate, if you see SpriteKit having random crashes that don’t have solutions. You may want to do the same, step back, start fresh, copy to a new project.

This also benefited Xcode 9 immensely, it allowed development to become quicker and efficient. It no longer was looking at all the old files that were not going to be used.

Xcode screen

I am also impressed that spritekit works hard at managing power consumption now.  If there are no updates on screen, you can see here it drops to 1 FPS, easily at a glance I can tell what is going on with the game all inside Xcode and not having to run the GPU profiler.

At any rate, I’m enjoying Xcode 9 and Sprite kit immensely!

Specific challenges:
Make the game more fun and enticing!

Debian Stretch release – wifi woes with NetworkManager – quick fix

Goal;
Get all four USB Wifi Dongles working. Most importantly I want the AC one to work. I read lots of articles that it didn’t work. Well I got it working in Debian Stretch with Network Manager (nmcli).

Some of the story;
I was remembering that Debian Jessie was fantastic with Wifi. So it had to be something with stretch.

A little over a month and half later, I’m trying the four wifi dongles I have, to see which one actually works.

Tonight, guess what? None of the four USB wifi adapters I have are working. (They will, just continue reading.)
All the tools I’m familiar with are not installed either. Just NetworkManager (the GUI tool) and “iw” on the command line, and ifconfig.

Four USB Wifi Dongles;
Edimax EW-7811Un – Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]

ASUS USB N13 – iface wlx20cf30a29c9a

Netgear A6210 AC – just ID’s as Netgear Inc.
https://github.com/jurobystricky/Netgear-A6210 << using this driver
modprobe mt7662u_sta

Netgear High Speed Wifi USB adapter – NetGear, Inc. WNDA4100 802.11abgn 3×3:3 [Ralink RT3573]

This post assisted me;
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=839605

And the only change I needed from it was as follows;
sudo vi /etc/NetworkManager/NetworkManager.conf #add these two lines
[device-mac-randomization]
wifi.scan-rand-mac-address=no

sudo service network-manager restart

Four Network Devices;
Netgear, Inc. WNDA4100 802.11abgn 3×3:3 [Ralink RT3573] = Confirmed Working.
wlx6cb0ceefa32d: connected to faith-5G
“NETGEAR WNDA4100″
wifi (rt2800usb), 6C:B0:CE:EF:A3:2D, hw
ip4 default
inet4 192.168.1.235/24
inet6 fe80::b0a6:c0c0:dbc7:f2c4/64

iwconfig
wlx6cb0ceefa32d IEEE 802.11 ESSID:”faith-5G”
Mode:Managed Frequency:5.745 GHz Access Point: …………
Bit Rate=300 Mb/s Tx-Power=20 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=70/70 Signal level=-29 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:54 Missed beacon:0

Netgear A6210 AC = Confirmed working
nmcli shows;
wlan0: unmanaged
“NETGEAR A6210”
wifi (RALINK WLAN), 00:00:00:00:00:00, hw, mtu 1500

Confirmed working; (I had to reboot to get it online)
wlan0: connected to Wi-Fi connection 1
“NETGEAR A6210”
wifi (usb), 6C:B0:CE:E8:DD:11, hw, mtu 1500
inet4 192.168.1.34/24
inet6 fe80::7936:ee8f:711b:9356/64

ASUS USB N13 = Confirmed Working.
A reboot brought it back online. I can scan access points with iwlist wlx20cf30a29c9a scanning
dhcp discover fails.
‘device not managed’ by NetworkManager
Ok I looked that up; https://wiki.debian.org/NetworkManager
then removed wlan0 and wlx20cf30a29c9a from /etc/network/interfaces and now wifi works on the ASUS USB N13!

Edimax = Confirmed Working.

root@BillsStretch:~# nmcli
enp4s0: connected to Wired connection 1
“Qualcomm Atheros Killer E220x Gigabit Ethernet Controller”
ethernet (alx), D4:3D:7E:EB:49:06, hw, mtu 1500
ip4 default
inet4 192.168.1.231/24
inet6 fe80::d63d:7eff:feeb:4906/64

wlx20cf30a29c9a: connected to faith 2
“Ralink 802.11 n WLAN”
wifi (rt2800usb), 20:CF:30:A2:9C:9A, hw, mtu 1500
inet4 192.168.1.97/24
inet6 fe80::26de:bce2:c87:e589/64

lo: unmanaged
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

DNS configuration:
servers: 192.168.1.1
interface: enp4s0

servers: 192.168.1.1
interface: wlx20cf30a29c9a

Conclusion;

Don’t install any extra tools.  Stick with nmcli nmtui and NetworkManager. Dig deeper if the setting I list doesn’t work.

Rest assured, if your wifi worked before, you can probably get it to work again in Linux. See the solution I used to get NetworkManager to working on stretch.

Quick Notes;
A. Do not add any interfaces to /etc/network/interfaces if you plan to use the tools nmcli and network manager in Debian stretch.

B. The change listed above about the mac address in NetworkManager.conf got all my wifi usb dongles to work.

C. Hot Swapping some of the dongles resulted in the wifi usb dongle not working. restarting the network-manager after hotswap didn’t always work. A full reboot got it working each time however.

D. Notice any Strange MAC address’s as all Zero’s? 00:00:00:00:00  time to do a full reboot (well you could probably rmmod and modprobe/insmod it again, anything to prod it to reload the firmware.)  Frankly the reboot is the easiest in my mind.

E. Check your dmesg.  Some dmesg stuff can be misleading.  The AC6210 kept spitting out illegal channel information and wouldn’t work with the WPA Supplicant commands.  It will however work with nmcli/NetworkManager.

PocketCHIP Bluez 5.23 A2DP to headset for audio

The reason for this post is to find a baseline for the actual bluetooth hardware on the PocketCHIP and see if bluez works properly on the device at all.

PocketCHIP is Jessie Debian based, I needed this information here, which I will build upon;
https://wiki.debian.org/BluetoothUser/a2dp

sudo apt-get install pulseaudio pulseaudio-module-bluetooth pavucontrol bluez-firmware
sudo service bluetooth restart
killall pulseaudio
sudo vi /etc/bluetooth/main.conf
Added “Enabled=Source,Sink” in [General] Section

reboot

sudo vi /etc/pulse/default.pa
load-module module-switch-on-connect

I needed a music player, this seemed great for this platform;
sudo apt-get install moc

mocp is command line to start it.

The sequence goes like this;

bluetoothctl to scan/trust/pair the a2dp headset

pacmd list sinks (sinks are outputs)
and
pactl set-default-sink bluez-device

pacmd list sinks | grep blue
Default sink name: bluez_sink.30_21_0A_30_06_CC
name: <module-bluetooth-policy>
module.description = “When a bluetooth sink or source is added, load module-loopback”
name: <module-bluetooth-discover>
name: <module-bluez5-discover>
name: <module-bluez4-discover>
name: <module-bluez5-device>
argument: <path=/org/bluez/hci0/dev_30_21_0A_30_06_CC>
name: <bluez_sink.30_21_0A_30_06_CC>
driver: <module-bluez5-device.c>
card: 1 <bluez_card.30_21_0A_30_06_CC>
bluetooth.protocol = “a2dp_sink”
device.api = “bluez”
device.bus = “bluetooth”
bluez.path = “/org/bluez/hci0/dev_30_21_0A_30_06_CC”
bluez.class = “0x240408”
bluez.alias = “BTH175”
device.icon_name = “audio-handsfree-bluetooth”
name: <bluez_sink.30_21_0A_30_06_CC.monitor>
driver: <module-bluez5-device.c>
card: 1 <bluez_card.30_21_0A_30_06_CC>
device.api = “bluez”
device.bus = “bluetooth”
bluez.path = “/org/bluez/hci0/dev_30_21_0A_30_06_CC”
bluez.class = “0x240408”
bluez.alias = “BTH175”
device.icon_name = “audio-handsfree-bluetooth”
name: <bluez_card.30_21_0A_30_06_CC>
driver: <module-bluez5-device.c>
device.api = “bluez”
device.bus = “bluetooth”
bluez.path = “/org/bluez/hci0/dev_30_21_0A_30_06_CC”
bluez.class = “0x240408”
bluez.alias = “BTH175”
device.icon_name = “audio-handsfree-bluetooth”
bluez_sink.30_21_0A_30_06_CC/#1: BTH175
bluez_sink.30_21_0A_30_06_CC.monitor/#2: Monitor of BTH175
chip@chip:~$ pactl set-default-sink bluez_sink.30_21_0A_30_06_CC

mocp

Notes on quality, pops in sound etc;
Worked great.
Sounded great.
It continually streamed properly like you would expect for a commercial device. 20+ minutes no issues.
PocketCHIP turned its display off and the audio kept playing.

Conclusions for this single test: A2DP wireless headsets can be used for PocketCHIP reliably.  The games will also use the pulseaudio default sink thru A2DP/Bluetooth which is great (no wires needed). With the Jessie provided Bluez 5.23 to boot.

Cross building bluez-5.46-1 for ARMHF

bluez is an interesting beast, requiring about 10 additional libraries to build if your building without a build system like dpkg-buildpackage.

Back Story: Last week I gave up cable TV (save yourself $100!!) to pursue more Linux projects to come up to speed with the community.  I love PocketCHIP and RaspberryPi 3 this year.  I want so many other linux gadgets (Voder, ReSpeaker V2 to name a few) I think I need to master  a few before looking much further.    The one constant with these small platforms is hindered by the ability to debug easily and effectively.  I’ve been actually working on a MIPSEL platform for 4 months and gdbserver interferes to much with our app, its slow. But to install GDB would require to many dependencies and we only have 95MB of free space.  Ideally a statically linked GDB would possibly work.  For now we (our team) will rely on static code checking, gdbserver, and gdb-multiarch.

Truly the Debian community have engineered wonderful solutions to the problems of multi-platform building.

I still need pbuilder to work on stretch, I will work that out today.  Once I do, I will then be able to provide ‘backport’ bluez packages to the debian community in the backports repository.

I need a Debian package sponsor!

How do I compile so fast?
quad core, but notice I’m not using -j4 to indicate four jobs.
look up and configure ccache for yourself.

A) First I check that the source and build system can build the package for the native architecture;

What surprised me here is that last week, I did a ‘sudo dpkg –add-architecture armhf’ and its still active.  At least I will be ready to cross build bluez.

sudo apt-get build-dep bluez
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libasan3:armhf libatomic1:armhf libc6-dev:armhf libcap-ng0:armhf
libdbus-1-3:armhf libdbus-1-dev:armhf libdbus-glib-1-2:armhf libexpat1:armhf
libffi6:armhf libgcc-6-dev:armhf libgcrypt20:armhf libglib2.0-0:armhf
libgomp1:armhf libgpg-error0:armhf libical2:armhf libicu57:armhf
liblz4-1:armhf libpcre16-3:armhf libpcre3-dev:armhf libpcre32-3:armhf
libpcrecpp0v5:armhf libstdc++-6-dev:armhf libstdc++6:armhf libsubunit0:armhf
libsystemd0:armhf libubsan0:armhf linux-libc-dev:armhf zlib1g-dev:armhf
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
check:armhf libcap-ng-dev:armhf libdbus-glib-1-dev:armhf
libglib2.0-dev:armhf libical-dev:armhf libicu-dev:armhf libsubunit-dev:armhf
The following NEW packages will be installed:
check libcap-ng-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev
libical-dev libicu-dev libpcre3-dev libpcre32-3 libpcrecpp0v5 libsubunit-dev
libsubunit0 zlib1g-dev
0 upgraded, 13 newly installed, 7 to remove and 0 not upgraded.
Need to get 0 B/21.6 MB of archives.
After this operation, 30.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

B) Well at this point I just grab my source,  the source is multi-platform dpkg-buildpackage ready.
wget https://github.com/eSpecialized/bluez-5.46-rpi3/archive/5.46-1.tar.gz
tar xvf 5.46-1.tar.gz
mv bluez-5.46-rpi3-5.46-1/ bluez-5.46

C) Native architecture build time.
time dpkg-buildpackage -rfakeroot -uc -b
real 1m25.610s
user 1m13.108s
sys 0m3.988s

D) Moving on to build for arm!
https://wiki.debian.org/CrossCompiling << I use this a lot

sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install build-essential crossbuild-essential-armhf
sudo apt-get build-dep -aarmhf bluez
dpkg-buildpackage -rfakeroot -Tclean -d
time CONFIG_SITE=/etc/dpkg-cross/cross-config.armhf DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -aarmhf -rfakeroot -uc -b
real 1m35.282s
user 1m21.416s
sys 0m4.432s

D) Moving on to build for mipsel!

sudo dpkg --add-architecture mipsel
sudo apt-get update
sudo apt-get install build-essential crossbuild-essential-mipsel
sudo apt-get build-dep -amipsel bluez

#you must use -d to skip deps checking for cleaning.
dpkg-buildpackage -rfakeroot -Tclean -d
time CONFIG_SITE=/etc/dpkg-cross/cross-config.mipsel DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -amipsel -rfakeroot -uc -b
real 1m47.038s
user 1m34.288s
sys 0m4.996s

Results are three platforms all ready to install

bill@BillsStretch:~/crossBuildArm/bluez-5.46$ ls ../*amd64.deb ; ls ../*armhf.deb ; ls ../*mipsel.deb

../bluez_5.46_amd64.deb ../bluez-hcidump_5.46_amd64.deb ../libbluetooth3 dbg_5.46_amd64.deb
../bluez-cups_5.46_amd64.deb ../bluez-obexd_5.46_amd64.deb ../libbluetooth-dev_5.46_amd64.deb
../bluez-dbg_5.46_amd64.deb ../libbluetooth3_5.46_amd64.deb

../bluez_5.46_armhf.deb ../bluez-hcidump_5.46_armhf.deb ../libbluetooth3-dbg_5.46_armhf.deb
../bluez-cups_5.46_armhf.deb ../bluez-obexd_5.46_armhf.deb ../libbluetooth-dev_5.46_armhf.deb
../bluez-dbg_5.46_armhf.deb ../libbluetooth3_5.46_armhf.deb

../bluez_5.46_mipsel.deb ../bluez-hcidump_5.46_mipsel.deb ../libbluetooth3-dbg_5.46_mipsel.deb
../bluez-cups_5.46_mipsel.deb ../bluez-obexd_5.46_mipsel.deb ../libbluetooth-dev_5.46_mipsel.deb
../bluez-dbg_5.46_mipsel.deb ../libbluetooth3_5.46_mipsel.deb

 

What comes after this?

I’ve documented cross building. Unfortunately this won’t work for your old Jessie Raspberry Pi Rasbian. If you have stretch then yes it will work.  I won’t release the packages I just built until I get pbuilder up and running.

Well I will need to setup pbuilder, and setting up a debian repo for testing with. Finally getting a sponsor to provide backports.

Test out bluez 5.46 for stability.   My PocketCHIP had a corrupt NAND cell (or 2). It has been re-flashed, so I will test out this build on the chip AFTER I test 5.23 with a2dp and BLE.

 

What is backports?
Debian backports allow you to use new software on older systems like Jessie.  That or you are left with just doing what I did here. Unfortunately bluez is not in that pool of packages.

https://backports.debian.org/

What is pbuilder?
it allows a clean room environment to build package, thus ensuring a minimal package dependency build on your target platform, and a properly built one at that.  Notice that I’m using a fakeroot, but that isn’t quite the same. You still get all the packages and dependencies on my system (and Debian Stretch) that were used to build the packages.

pbuilder lets me target OS’s like Jessie and further back.

 

Pocket Chip updated with Bluez 5.46 first try worked great!

I got my pocket chip in the mail this past week. And I’ve been curious if I had to do anything to my bluez 5.46-1 build working on chip

Pocket Chip comes with the original CHIP (not the pro). It has some spaces and breathing room to do a lot in 3.3GB (2.6G free) of space.

On to trying out bluez 5.46;  I just installed it and it worked out of the box.   https://github.com/eSpecialized/bluez-5.46-rpi3

Pocket Chip once updated is at version Debian 8.9.

Preliminary tests;
bluetoothctl
scan on = success
scan off = success

after reboot; still running
when I removed the bluetooth from within my paired iPhone and tried to start up bluetoothctl, bluetoothd was dead.

I power cycled the device, to ensure it is still running.
bluetoothd is back online.  And it all works great. This means the firmware is loading at boot time properly.
remove (iPhone Mac address) = success.
trust 64:A5:C3:B8:9A:2B:D6 = worked
pair 64:A5:C3:B8:9A:2B:D6 = worked

I’m all paired up with my iPhone again.

What benefits does this have?
I’ll get back to this. Today is looking like a beach day for my family.  Least to say BLE works really great in Bluez 5.46, plus numerous other bug fixes since 5.23.

My true plans are really to work with the BLE and see how well it works. Also to work with some A2DP with stereo headsets and play some mp3’s.

Trying PAN with Bluez 5.46

chip@chip:~$ cat bnepconnect
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Connect string:nap


chip@chip:~$ bash ./bnepconnect
method return sender=:1.18 -> dest=:1.17 reply_serial=2
string "bnep0"

chip@chip:~$ sudo vi /etc/network/interfaces

#add these two lines
auto bnep0
iface bnep0 inet dhcp

chip@chip:~$
chip@chip:~$ sudo /sbin/ifup bnep0
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/bnep0/a0:2c:36:63:d3:7f
Sending on LPF/bnep0/a0:2c:36:63:d3:7f
Sending on Socket/fallback
DHCPDISCOVER on bnep0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on bnep0 to 255.255.255.255 port 67 interval 9
DHCPREQUEST on bnep0 to 255.255.255.255 port 67
DHCPOFFER from 172.20.10.1
DHCPACK from 172.20.10.1
bound to 172.20.10.2 — renewal in 33235 seconds.
chip@chip:~$

chip@chip:~$ ip addr show
6: bnep0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether a0:2c:36:63:d3:7f brd ff:ff:ff:ff:ff:ff
inet 172.20.10.2/28 brd 172.20.10.15 scope global bnep0
valid_lft forever preferred_lft forever
inet6 2607:fb90:8232:e7f4:a22c:36ff:fe63:d37f/64 scope global mngtmpaddr dynamic
valid_lft forever preferred_lft forever
inet6 fe80::a22c:36ff:fe63:d37f/64 scope link
valid_lft forever preferred_lft forever

Contact me here;
https://www.facebook.com/especialized

 

todo: finish this post later.

todo: power draw requirements for bluetooth PAN over WIFI.

Raspberry PI with I2S audio out, and trying I2S audio in.

The basic concept is that I2S Audio runs on SPI1 on the PI3.  The PI2/PI3 have 2 SPI’s (SPI1 and SPI0). With SPI0 evidently being a full featured interface with two enable pins, while SPI0 has only one enable pin.

It does appear possible to run 4 audio streams on I2S thru SPI0.  The speaker Bonnet would have 2 streams for stereo output, and the MEMS mic would have 2 streams for stereo input. To wire them together causes contention in the drive currently.  With two different drivers to drive two different audio functions on the same bus.   I have limited knowledge on how to use either SPI thru the new kernel interfaces (device tree).

RPI pinout

The Adafruit Speaker Bonnet uses I2S and a MISO (Master In Slave Out) pin.  The I2S mic uses a MOSI (Master Out Slave IN) pin. I2S is via SPI1.

The speaker out uses snd_bcm2835, and mic in uses a kernel module you have to build.

At the moment the two are conflicted;


[    3.540234] i2c /dev entries driver
[    3.644933] my_loader: loading out-of-tree module taints kernel.
[    3.650534] request module load 'bcm2708-dmaengine': 0
[    3.650955] register platform device 'asoc-simple-card': 0
[    3.651115] Hello World :)
[    3.841256] systemd-udevd[147]: starting version 215
[    4.285633] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
[    4.334938] snd-hifiberry-dac soc:sound: pcm5102a-hifi <-> 3f203000.i2s mapping ok
[    4.546427] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[    4.621951] bcm2835-i2s 3f203000.i2s: Trying to bind component to card "snd_rpi_simple_card" but is already bound to card "snd_rpi_hifiberry_dac"
[    4.621966] asoc-simple-card asoc-simple-card.0: ASoC: failed to instantiate card -19

So what would the next steps be to have both types of I2S audio working, microphone in, and speaker output through the same SPI1?

I already looked some at the kernel my_loader.c and other c sources. Not being familiar with Kernel module compiling it has some very special changes.

I think the easiest way to have both I2S devices working on the same Raspberry PI would be to use the two separate SPI’s one for each task. It wasn’t immediately apparent on how to do this, so I think it requires ‘digging’ to find a solution.

MEM’s mic module;
https://github.com/PaulCreaser/rpi-i2s-audio

https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/overview

 

Speaker Module;
https://learn.adafruit.com/adafruit-speaker-bonnet-for-raspberry-pi/overview

It’s just a start.

So these two bits of info talk about using SPI0, and that it has two enable pins out on the pin header.

https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md

https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial

Bluez 5.46 hciuart configuration changes

Update; 2017-08-13 Sunday
I discovered the problem is really in the tools/hciattach_bcm43xx.c file
I have now uploaded a patch to the git repo.

1. The speed cannot be set before the fiimware is uploaded

2. Wait 1 second before the reset command is sent.

Patch information;


git diff tools/hciattach_bcm43xx.c
diff --git a/tools/hciattach_bcm43xx.c b/tools/hciattach_bcm43xx.c
index 81f38cb..13a877c 100644
--- a/tools/hciattach_bcm43xx.c
+++ b/tools/hciattach_bcm43xx.c
@@ -43,7 +43,7 @@
#include "hciattach.h"
#ifndef FIRMWARE_DIR
-#define FIRMWARE_DIR "/etc/firmware"
+#define FIRMWARE_DIR "/lib/firmware"
#endif
#define FW_EXT ".hcd"
@@ -368,8 +368,6 @@ int bcm43xx_init(int fd, int def_speed, int speed, struct termios *ti,
if (bcm43xx_locate_patch(FIRMWARE_DIR, chip_name, fw_path)) {
fprintf(stderr, "Patch not found, continue anyway\n");
} else {
- if (bcm43xx_set_speed(fd, ti, speed))
- return -1;
if (bcm43xx_load_firmware(fd, fw_path))
return -1;
@@ -380,6 +378,7 @@ int bcm43xx_init(int fd, int def_speed, int speed, struct termios *ti,
return -1;
}
+ sleep(1);
if (bcm43xx_reset(fd))
return -1;
}

Nikolay patch; This has the binary file in it hciattach you can just replace yours with..
https://bugs.launchpad.net/snappy/+bug/1674509/+attachment/4854099/+files/bluez.tar.xz

Nikolay solution Is here;
https://bugs.launchpad.net/snappy/+bug/1674509

Nikolay (2xl) wrote on 2017-04-04:
I did the same patch – modify firmware patch and speed initialization patch… and I got bluetooth working on RPi!

############################## older information

When you upgrade to the latest bluez 5.46-1 everything will work as of 2017-08-12.

goal;  that firmware simply loads on boot and bluetooth works.

Indications that firmware loading failed;
   the mac address is all AA’s


hciconfig
hci0: Type: Primary Bus: UART
BD Address:  AA:AA:AA:AA:AA:AA ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:2095 acl:0 sco:0 events:118 errors:0
TX bytes:1974 acl:0 sco:0 commands:118 errors:0

How does it work to update bluez-5.46 then later not?

The Chip still has its firmware uploaded, until you reboot. Then the firmware needs to be reloaded.  And there is the change;

/etc/firmware is expected location from hciattach
BCM43430A1.hcd << one file needed

/var/firmware is where all the RPI’s firmware is located.
/var/firmware/BCM43430A1.hcd << cp this

mkdir /etc/firmware
cp /var/firmware/BCM43430A1.hcd /etc/firmware

 

Other related files;
/usr/bin/btuart
/lib/systemd/system/hciuart.service

 

My final analysis in retrospect;
The bluez 5.23 package that is in Jessie has an edit not part of the patches in tools/hciuart_bcm43xx.c, and this lead to a missed non working update to 5.46.  All is working in the 5.46-1 release.

Bluez 5.46 and Personal Area Network PAN connectivity with RPI3

For all purposes PAN connection should work with a lot of revisions of Bluez. This is really focused on 5.46 but the changes to get PAN connection from 5.23 should still work.

#Check the version of your software first;
bluetoothctl -v
5.46

Paring serves multiple purposes;
1.Being able to connect by PAN with established services.
In order for PAN to become an option, your smart phone must have Hot Spot for bluetooth enabled.

To do it properly for a PAN connection to an iPhone;
a. Turn on “hotspot” on your iPhone
b. Ensure its only set to bluetooth and USB.
c. Begin the Pair process from the linux side.


pi@billspi3:/usr/src $ bluetoothctl
[NEW] Controller B8:27:EB:1E:EF:45 billspi3 [default]
[NEW] Device 64:A5:C3:DC:F7:1C Bills iPhone6+
Agent registered

[bluetooth]# remove 64:A5:C3:DC:F7:1C
[DEL] Device 64:A5:C3:DC:F7:1C Bills iPhone6+
Device has been removed

[bluetooth]# pairable on
Changing pairable on succeeded

 

[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:1E:EF:45 Discovering: yes
[NEW] Device 64:A5:C3:DC:F7:1C Bills iPhone6+
[bluetooth]# scan off

[CHG] Controller B8:27:EB:1E:EF:45 Discovering: no
Discovery stopped

[bluetooth]# trust 64:A5:C3:DC:F7:1C
[CHG] Device 64:A5:C3:DC:F7:1C Trusted: yes
Changing 64:A5:C3:DC:F7:1C trust succeeded

[bluetooth]# pair 64:A5:C3:DC:F7:1C
Attempting to pair with 64:A5:C3:DC:F7:1C
[CHG] Device 64:A5:C3:DC:F7:1C Connected: yes

Request confirmation
[agent] Confirm passkey 675499 (yes/no): yes

[CHG] Device 64:A5:C3:DC:F7:1C Modalias: bluetooth:v004Cp6F01d0A30
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00000000-deca-fade-deca-deafdecacafe
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 64:A5:C3:DC:F7:1C ServicesResolved: yes
[CHG] Device 64:A5:C3:DC:F7:1C Paired: yes

Pairing successful
[CHG] Device 64:A5:C3:DC:F7:1C ServicesResolved: no
[CHG] Device 64:A5:C3:DC:F7:1C Connected: no

[bluetooth]#

Once Paired this way, you can use PAN to connect;

Bluez makes extensive use of Dbus, so the best way to get that connection rolling is to send this NAP command thru the dbus at the proper device.

Connect;
sudo dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Connect string:"nap"

Successful Output;
method return sender=:1.28 -> dest=:1.45 reply_serial=2
string “bnep0”

Disconnect;
sudo dbus-send –system –print-reply –type=method_call –dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Disconnect

You can form a second PAN connection from your PC/MAC.

Note: PAN allows multiple devices to connect to it.

After about 1 minute for the connection to settle, you can then ssh to the PI so long as you are on the same PAN connection.

Turn off all other connections temporarily;


sudo ifdown wlan0
sudo ifdown eth0
sudo ifconfig wlan0 down
sudo ifconfig eth0 down

NOTE: when you turn off WLAN0 or ETH0, and you were SSH’d, expect large long delays and disconnect. Simply reconnect after waiting about 1 minute for the PAN connection to settle.

Raspbian on the Pi3 comes setup with mDNS so you simply just look for it by <name>.local

Williams-iMac:Downloads speccy67$ ping billspi3.local
PING billspi3.local (172.20.10.4): 56 data bytes
64 bytes from 172.20.10.4: icmp_seq=0 ttl=64 time=26.763 ms
64 bytes from 172.20.10.4: icmp_seq=1 ttl=64 time=77.890 ms
64 bytes from 172.20.10.4: icmp_seq=2 ttl=64 time=31.794 ms
64 bytes from 172.20.10.4: icmp_seq=3 ttl=64 time=31.039 ms

ssh pi@billspi3.local

Introspecting the Dbus to find the Network Device Name;

You can use d-feet and inspect the /org/bluez/hci0 interface to find the PAN device.


sudo dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.freedesktop.Dbus.Introspectable.Introspect

sudo dbus-send –system –print-reply –type=method_call –dest=org.bluez /org/bluez/hci0 org.freedesktop.Dbus.Introspectable.Introspect | grep “node name”

</method></interface><node name=”dev_64_A5_C3_DC_F7_1C”/></node>”

To compose your dbus send command;


1. sudo dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0
2. /dev_64_A5_C3_DC_F7_1C
3. org.bluez.Network1.Connect string:"nap"

results;
sudo dbus-send –system –print-reply –type=method_call –dest=org.bluez /org/bluez/hci0/dev_64_A5_C3_DC_F7_1C org.bluez.Network1.Connect string:”nap”

Measuring the speed and time

LTE 2 bars; 13 feet away from RPI3, 1 foot next to OSX
pi@billspi3:~ $

time wget http://www.blog.willandnora.com/downloads/gatt-service
--2017-08-05 19:16:42-- http://www.blog.willandnora.com/downloads/gatt-service
Resolving www.blog.willandnora.com (www.blog.willandnora.com)... 208.113.170.218
Connecting to www.blog.willandnora.com (www.blog.willandnora.com)|208.113.170.218|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 221880 (217K) [text/plain]
Saving to: ‘gatt-service’
gatt-service 100%[====================================================================================>] 216.68K 62.7KB/s in 3.5s

2017-08-05 19:16:46 (62.7 KB/s) – ‘gatt-service’ saved [221880/221880]
real 0m4.459s
user 0m0.040s
sys 0m0.020s

Splitting the difference; iPhone between both devices
LTE 2 bars; 6 feet from OSX, 7 feet from RPI3.
pi@billspi3:~ $ time wget http://www.blog.willandnora.com/downloads/bluez-5.46-deb-src.tar.gz
–2017-08-05 19:18:55– http://www.blog.willandnora.com/downloads/bluez-5.46-deb-src.tar.gz
Resolving www.blog.willandnora.com (www.blog.willandnora.com)… 208.113.170.218
Connecting to www.blog.willandnora.com (www.blog.willandnora.com)|208.113.170.218|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 2369419 (2.3M) [application/x-tar]
Saving to: ‘bluez-5.46-deb-src.tar.gz’
bluez-5.46-deb-src.tar.gz 100%[====================================================================================>] 2.26M 84.9KB/s in 27s
2017-08-05 19:19:23 (84.3 KB/s) – ‘bluez-5.46-deb-src.tar.gz’ saved [2369419/2369419]
real 0m27.911s
user 0m0.050s
sys 0m0.140s