redbear / IoT_pHAT

WiFi + Bluetooth, designed for the Raspberry Pi Zero
110 stars 32 forks source link

Problems using WIFI and BT at the same time #11

Open ralle12345 opened 8 years ago

ralle12345 commented 8 years ago

I'm having problems using WIFI and BT at the same time. I'm running a python application that scans for two BT MACs in order to find out if the phone they belong to are near or not. The goal is to have a working presence detection for home automation.

I already updated the Pi to the latest available firmware and kernel using rpi-update:

$ uname -a
Linux pizero 4.4.21+ #911 Thu Sep 15 14:17:52 BST 2016 armv6l GNU/Linux

The EEPROM has been updated as advised here as well:

$ cat /proc/device-tree/hat/product
IoT pHAT w/eep_v0.3

This is the lsb info for the distribution installed:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 8.0 (jessie)
Release:    8.0
Codename:   jessie

The system is freshly installed with only the dependancies for the script installed.

UART bootup message:

$ dmesg | grep uart
[    0.000000] Kernel command line: 8250.nr_uarts=0 dma.dmachans=0x7f35 
bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0x900093 
bcm2708.serial=0x57cd67 smsc95xx.macaddr=B8:27:EB:57:CD:67 bcm2708_fb.fbswap=1 
bcm2708.uart_clock=48000000 bcm2708.disk_led_gpio=47 vc_mem.mem_base=0x1ec00000 
vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 
root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

The application I'm using is sensorReporter.

This application runs a scan on Bluetooth once every 25 secs.

I'm observing that while the application is running there is major delay on WIFI that is not visible when the application is not running.

See below for mtr logs without the application running, then while the script runs and after the script has been stopped. All mtrs are pinging FROM another system TO the Pi zero!

Without BT activity:

$ mtr -n -c 1000 --report pizero
Start: Fri Sep 23 16:04:50 2016
HOST: 192.168.254.9           Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 192.168.254.50             0.1%  1000    5.2  12.0   1.9 118.7  17.9

With sensorReporter started:

# systemctl start sensorReporter

top - 16:58:55 up  3:00,  2 users,  load average: 0.00, 0.01, 0.00
Tasks:  98 total,   1 running,  97 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  0.0 sy,  0.0 ni, 98.7 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
KiB Mem:    445092 total,   101584 used,   343508 free,    14132 buffers
KiB Swap:   102396 total,        0 used,   102396 free.    48284 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 1181 root      20   0    5100   2428   2088 R  0.7  0.5   0:00.10 top
 1063 root      20   0       0      0      0 S  0.3  0.0   0:00.63 kworker/u2:1
 1127 pi        20   0   12204   3724   3016 S  0.3  0.8   0:00.21 sshd
 1156 root      20   0   40728  10496   6420 S  0.3  2.4   0:00.87 sensorReporter.
    1 root      20   0   22756   3836   2680 S  0.0  0.9   0:06.58 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.90 ksoftirqd/0
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H
    7 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kdevtmpfs
    8 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
    9 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 perf
   10 root      20   0       0      0      0 S  0.0  0.0   0:00.01 khungtaskd
   11 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 crypto

As you can see there is not a major load on the Pi, nevertheless there is an RTT of more then 11secs! The Wifi Access point reports excess packet loss on this wifi client in this situation.

$ mtr -n -c 1000 --report pizero
Start: Fri Sep 23 18:56:08 2016
HOST: 192.168.254.9              Loss%   Snt   Last   Avg  Best  Wrst StDev
 1.|-- 192.168.254.50             0.9%  1000    2.1 249.1   1.6 11525 1204.0

top at the end of the mtr test:

top - 17:15:30 up  3:17,  3 users,  load average: 0.00, 0.00, 0.00
Tasks: 102 total,   1 running, 101 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  1.0 sy,  0.0 ni, 98.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:    445092 total,   106340 used,   338752 free,    14332 buffers
KiB Swap:   102396 total,        0 used,   102396 free.    49784 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 1347 pi        20   0    5100   2164   1820 R  1.0  0.5   0:00.15 top
 1098 root      20   0       0      0      0 S  0.3  0.0   0:01.78 kworker/u2:0
 1156 root      20   0   40728  10500   6420 S  0.3  2.4   0:02.15 sensorRepor+
    1 root      20   0   22756   3836   2680 S  0.0  0.9   0:06.72 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:01.00 ksoftirqd/0
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H
    7 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kdevtmpfs
    8 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
    9 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 perf
   10 root      20   0       0      0      0 S  0.0  0.0   0:00.01 khungtaskd
   11 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 crypto
   13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 rpciod
   17 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kswapd0

After the python script is stopped everything returns to normal:


$ mtr -n -c 1000 --report pizero
Start: Fri Sep 23 19:17:51 2016
HOST: 192.168.254.9           Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 192.168.254.50             0.0%  1000    4.9  10.0   1.6 216.1  15.7

I have tested this with two pHATs and both show this problem.

Is there any info I can provide you with that helps diagnose the issue? I'll be happy to help since running this kind of application was the reason for getting the IoT pHAT.

Cheong2K commented 8 years ago

Hi, we are looking into this issue right now.

ralle12345 commented 8 years ago

I tested some more over the weekend. When I set the scan interval to 120sec the problem seems to be gone.

ralle12345 commented 7 years ago

@Cheong2K Have you been able to reproduce my issue? Is there anything I can do to help?

Cheong2K commented 7 years ago

I found that some latest versions of Raspbian have problem when pairing BT (Keyboard + mouse) and running WiFi at the same time, but I have one old version doesn't have problems. I am going to ask the Raspberry Pi team, they have 2 IoT pHATs there to test.