tzachi-dar / LibreAllHouse

Use Raspberry pi devices to have all house coverage using the miaomiao device.
16 stars 12 forks source link

BT can not connect with RPi Zero W #2

Closed bordeb closed 5 years ago

bordeb commented 5 years ago

EDIT 27.12.2018.: Dear Reader, if you have found this searching around, I want to inform you that this was NOT LibreAllHouse issue! This was only the hardware issue with RPi Zero W. RPi Zero W is an excellent product (recommend it, I have several of them and I am happy with all) but this one by accident had faulty antenna so the only problem was hardware - antenna. LibreAllHouse worked excellent and now works excellent on my new replaced RPi.

On RPi 3B everything works great, but with my new RPi Zero W it seams that BT connection with miaomiao can not be established. The setup is the same on both RPis, clean Raspbian installation, latest updates... There is NO interference/collision between devices, that was ensured 100%. tail -F ~/LibreAllHouse/screen.log on RPi Zero W says:

INFO 2018-12-17 20:24:18,374 cought btle.BTLEException Failed to connect to peripheral XX:XX:XX:XX:XX:XX, addr type: random
2018-12-17 20:24:19.580:  event wait ended, ret = False

EDIT: It seams that by default RPi Zero W can not see BLE devices. E.g. through GUI Bluetooth "Add device..." windows only Bluetooth devices NOT using BLE are wisible while BLE connections are NOT visible. In the same time RPi 3B sees all devices.

tzachi-dar commented 5 years ago

This is strange. I'm using rpi zero without a problem. Is the xx:xx mac the number that is used or did you change it in the logs? what happen when you run the scan command? does it find anything?

bordeb commented 5 years ago

Hi @tzachi-dar ! Tnx for such fast response! The XX:XX... is just my personal modification of the logs. The actual MAC address was entered manually (copy-paste entire content into config.cfg) exactly the same (copy/paste) as it was in RPi 3B. So, I did not use scan command at all. I will try now with scan and report here.

EDIT - Report after trying: Unfortunately, what I was afraid, it is.

sudo python3 scan.py
['BTDevice', 'MongoData', 'TcpSockets']
scanning for miaomiao devices
devices found:
No miaomiao devices found, please try again. Program exiting.

100% checked: Working miaomiao device present at distance of 1 meter, Only 1 miaomiao present. Tried several times and always same result.

bordeb commented 5 years ago

In addition. Tried clean reinstall, everything from scratch, with latest Raspbian release but without any further upgrades and now scan.py results with:

sudo python3 scan.py
['BTDevice', 'MongoData', 'TcpSockets']
scanning for miaomiao devices
devices found:
09:68:08:34:5e:79 random None
Traceback (most recent call last):
  File "scan.py", line 45, in <module>
    ScanForTomatoOrDie()
  File "scan.py", line 28, in ScanForTomatoOrDie
    if 'miaomiao' in name:
TypeError: argument of type 'NoneType' is not iterable

MAC 09:68:08:34:5e:79 is NOT miaomiao, it is some unknown device probably from neighbours

tzachi-dar commented 5 years ago

Is this the mac of the miaomiao?

בתאריך יום ג׳, 18 בדצמ׳ 2018, 21:07, מאת bordeb notifications@github.com:

In addition. Tried clean reinstall, everything from scratch, with latest Raspbian release but without any further upgrades and now scan.py results with:

sudo python3 scan.py ['BTDevice', 'MongoData', 'TcpSockets'] scanning for miaomiao devices devices found: 09:68:08:34:5e:79 random None Traceback (most recent call last): File "scan.py", line 45, in ScanForTomatoOrDie() File "scan.py", line 28, in ScanForTomatoOrDie if 'miaomiao' in name: TypeError: argument of type 'NoneType' is not iterable

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tzachi-dar/LibreAllHouse/issues/2#issuecomment-448334022, or mute the thread https://github.com/notifications/unsubscribe-auth/AHkw5KX-gkjU2BQ0nCtDex8WRoI2xcLcks5u6TzhgaJpZM4ZW_MU .

bordeb commented 5 years ago

No, it is not, it is some unknown device from neighbors

bordeb commented 5 years ago

If I manually setup exact MAC of the miaomiao in config.cfg then again same error:

2018-12-18 19:24:57.433:  event wait ended, ret = False
Connecting...
INFO 2018-12-18 19:25:40,350 cought btle.BTLEException Failed to connect to peripheral XX:XX:XX:XX:XX:XX, addr type: random
tzachi-dar commented 5 years ago

Just making sure: when the miaomiao is connecting to another rpii or another phone, it can not be connected again. Do you see it when you scan using your phone?

What happens when you run: sudo hcitool -i hci0 lescan

bordeb commented 5 years ago

1.) Yes, I powered off RPi 3B and put far away aside the smartwatch that is forced collector and there is no data on the master phone, so I am 100% sure that miaomiao is not connected to anything else. I can see miaomiao while scanning with my phones. MM waits... :-) to be connected 2.) It successfully detects (lists MAC and name) the miaomiao as well as other devices

bordeb commented 5 years ago

One UPDATE: To exclude potential situation that the miaomiao is somehow not working properly, I have tested with another mioamiao (we have two MMs) and the situation is the same. Although sudo hcitool -i hci0 lescan successfully detects the miaomiao, the error is still present and the LibreAllHouse can not connect to it.

tzachi-dar commented 5 years ago

I want to understand that bluepy is installed:

So, please run: python3 import bluepy press control d to get out of python. did it print any errors?

bordeb commented 5 years ago

did this:

pi@rpi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bluepy
>>>
pi@rpi:~ $

No errors

tzachi-dar commented 5 years ago

Can you please edit the file scan.py and add one more line between the following lines: print (device.addr, device.addrType, name) if 'miaomiao' in name:

Please add: if name is None: continue

you should have something like: print (device.addr, device.addrType, name) if name is None: continue if 'miaomiao' in name:

then save the program and run it again: sudo python3 scan.py

bordeb commented 5 years ago

I did that and after multiple attempts on one occasion the scan.py succeeded to find the miaomiao and changed the config.cfg accordingly putting mac address inside. But the main.py still can not connect to mm with the same error

Connecting...
INFO 2018-12-19 01:03:59,860 cought btle.BTLEException Failed to connect to peripheral XX:XX:XX:XX:XX:9XX, addr type: random
2018-12-19 01:04:45.081:  event wait ended, ret = False

It seams to me that bluetooth hardware on this RPi zero W is somehow weak and of low quality. I don't know if this is possible. I have noticed that sudo hcitool -i hci0 lescan lists miaomiao only on very small distance like max 2meters while on 4 meters it does not succeed. Is it maybe possible that I have received some crappy RPi zero W with extremely low quality BT interface? Maybe that is the problem? I really don't understand what is going on

tzachi-dar commented 5 years ago

Yes, it might be a hw issue. You can either try another one, or try adding an external usb ble device, and see if that helps.

bordeb commented 5 years ago

I opened a technical support ticket, hopefully something will be replaced/resolved. In the meantime, just for me to be 100% sure, can you post version number (or some other relevant info, I am not sure about possible HW differences) about the RPi Zero W that successfully established BLE connection using LibreAllHouse? I will post mine asap and compare to. THANK YOU very much on your support and help

tzachi-dar commented 5 years ago

Will do that once I'm home.

On Wed, 19 Dec 2018 at 13:44, bordeb notifications@github.com wrote:

I opened a technical support ticket, hopefully something will be replaced/resolved. In the meantime, just for me to be 100% sure, can you post version number (or some other relevant info, I am not sure about possible HW differences) about the RPi Zero W that successfully established BLE connection using LibreAllHouse? I will post mine asap and compare to.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tzachi-dar/LibreAllHouse/issues/2#issuecomment-448566117, or mute the thread https://github.com/notifications/unsubscribe-auth/AHkw5LYW69UR09Cqf9wJSnK6H76B4fU5ks5u6iaEgaJpZM4ZW_MU .

bordeb commented 5 years ago

Tnx again

bordeb commented 5 years ago

Mine is: Raspberry Pi Zero W V1.1 FCC ID: 2ABCB-RPI0W IC: 20953-RPI0W

tzachi-dar commented 5 years ago

Here is mine:

cat /proc/cpuinfo processor : 0 model name : ARMv6-compatible processor rev 7 (v6l) BogoMIPS : 697.95 Features : half thumb fastmult vfp edsp java tls CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xb76 CPU revision : 7

Hardware : BCM2835 Revision : 9000c1 Serial : 000000002c832dc7

pinout .-------------------------. | oooooooooooooooooooo J8 | | 1ooooooooooooooooooo |c ---+ +---+ PiZero W|s sd| |SoC| V1.1 |i ---+|hdmi| +---+ usb pwr | `---| |--------| |-| |-'

Revision : 9000c1 SoC : BCM2835 RAM : 512Mb Storage : MicroSD USB ports : 1 (excluding power) Ethernet ports : 0 Wi-fi : True Bluetooth : True Camera ports (CSI) : 1 Display ports (DSI): 0

J8: 3V3 (1) (2) 5V GPIO2 (3) (4) 5V GPIO3 (5) (6) GND GPIO4 (7) (8) GPIO14 GND (9) (10) GPIO15 GPIO17 (11) (12) GPIO18 GPIO27 (13) (14) GND GPIO22 (15) (16) GPIO23 3V3 (17) (18) GPIO24 GPIO10 (19) (20) GND GPIO9 (21) (22) GPIO25 GPIO11 (23) (24) GPIO8 GND (25) (26) GPIO7 GPIO0 (27) (28) GPIO1 GPIO5 (29) (30) GND GPIO6 (31) (32) GPIO12 GPIO13 (33) (34) GND GPIO19 (35) (36) GPIO16 GPIO26 (37) (38) GPIO20 GND (39) (40) GPIO21

For further information, please refer to https://pinout.xyz/

cat /proc/device-tree/model Raspberry Pi Zero W Rev 1.1

bordeb commented 5 years ago

Dear @tzachi-dar thank you. Now I see detailed information. :-) I want to report that at the end it was HW issue. I figured it out that the antena had been partially damaged so the signal (BT as well as WIFI) was influenced. Wifi was working but very very slow with lousy signal strenght, and BT was :-( , as it is described here. At the end I am waiting for replacement and hopefully everything will be ok.

bordeb commented 5 years ago

Dear @tzachi-dar thank you once more on your dedicated help. The replacement came and new RPi Zero W works excellent with brilliant software as LibreAllHouse is! The only problem was hardware - the RPi Zero W antenna that was obviously damaged in transport or similar. We can now close this issue. Should I do that, or...?

IMPORTANT NOTICE 27.12.2018.: Dear Reader, if you have found this searching around, I want to inform you that this was NOT LibreAllHouse issue! This was only the hardware issue with RPi Zero W. RPi Zero W is an excellent product (recommend it, I have several of them and I am happy with all) but this one by accident had faulty antenna so the only problem was hardware - antenna. LibreAllHouse worked excellent and now works excellent on my new replaced RPi.

tzachi-dar commented 5 years ago

Thanks for reporting this, please close the issue.