MasterDevX / lampify

A simple CLI application to control the BLE lamp
29 stars 6 forks source link

Unable to setup (Raspberri PI 3) #1

Open ReX1983 opened 1 year ago

ReX1983 commented 1 year ago

Hello!

Firstly - let me thank you for your effort - I was looking for a way to control my lamp from Home Assistant and your project would be a great starting point. I have this ceiling lamp with hidden fans that I can control with its remote or via FanLamp Pro (Android app).

I tried to compile your project on a Raspberri PI 3 (running a fresh install of Raspberry Pi OS) but make failed:

/usr/bin/ld: /tmp/ccKXiblm.o: in function `hciSetParams':
lampify.c:(.text+0xa8c): undefined reference to `hci_send_req'
/usr/bin/ld: /tmp/ccKXiblm.o: in function `sendPacket':
lampify.c:(.text+0xacc): undefined reference to `hci_get_route'
/usr/bin/ld: lampify.c:(.text+0xad8): undefined reference to `hci_open_dev'
/usr/bin/ld: lampify.c:(.text+0xb38): undefined reference to `hci_send_req'
/usr/bin/ld: lampify.c:(.text+0xb64): undefined reference to `hci_send_cmd'
/usr/bin/ld: lampify.c:(.text+0xb7c): undefined reference to `hci_le_set_advertise_enable'
/usr/bin/ld: lampify.c:(.text+0xb9c): undefined reference to `hci_le_set_advertise_enable'
/usr/bin/ld: lampify.c:(.text+0xbac): undefined reference to `hci_close_dev'
/usr/bin/ld: /tmp/ccKXiblm.o: in function `decodeCommand':
lampify.c:(.text+0xe18): undefined reference to `notify_init'
/usr/bin/ld: lampify.c:(.text+0xe28): undefined reference to `notify_notification_new'
/usr/bin/ld: lampify.c:(.text+0xe34): undefined reference to `notify_notification_set_timeout'
/usr/bin/ld: lampify.c:(.text+0xe40): undefined reference to `notify_notification_show'
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1

After some research, I understood that it is a common issue that should be solved by using pkg-config, so my Makefile became:

`gcc -Wall -Ofast -o lampify `pkg-config --cflags glib-2.0 gdk-pixbuf-2.0` lampify.c `pkg-config --libs glib-2.0 gdk-pixbuf-2.0 libnotify` -lbluetooth`

In this way, make succeeds, but unfortunately lampify still doesn't pair with the lamp (setup doesn't result in the lamp blinking 3 times). When I try verbose mode for setup, I get right away [W] Failed to send notification!, without any timeout, so I am not even sure if it tries to send anything.

Any idea?

Thanks!

techedgeoff commented 1 year ago

Всем привет! Как оказалось, здесь важен порядок передачи библиотек. Просто поместите -lbluetooth и -lnotify после lampify.c В моём случае это сработало! Окончательный вид команды таков:

gcc -Wall -Ofast -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/gdk-pixbuf-2.0 -o lampify lampify.c -lbluetooth -lnotify

P.S. Мой светильник EStares работает с приложением LampSmart Pro. Удалось успешно подключить его через lampify, однако работает не стабильно, буду разбираться дальше.

NBreskvar commented 1 year ago

Hello, I was so exicted to find this app, since I have some lights that use LampSmart Pro on Android and I would love to get time schedule working for turning them on and off at specific times with a Raspberry Pi.

I first tried to install it on a Raspberry Pi 3b+ and found the same issue as @ReX1983. It now runs and says Connecting to the lamp, but then stops right away. Of course the lamps also don't flash, so it's not connecting to the lamps.

I then tried it on a laptop with a Live Ubuntu on a usb drive, on which I successfully installed it, but got a different error when trying to run "lampify q setup" which is : "[E] Failed to set advertising parameters!". I also tried it with a Live Debian Cinnamon, but it wouldn't recognise my bluetooth card there.

I'm not sure what to do next, but I would really love to get this working so I'm open to try anything!

bilalhp commented 1 year ago

@MasterDevX trying to run this on Raspberry Pi 3b+ and also observed that this is not working.

Everything seems to compile and run properly, but setup never happens.

Either for some reason the RPi does not transmit the advertising packet or something is wrong.

Zulex commented 1 year ago

Did anyone seem to fix this? I wanted to integrate it in HA on the Rpi3 too

Justin8428 commented 1 year ago

I also couldn't get this working on a laptop running Debian 12 (with AX210 wireless card which supports BLE). After installing libbluetooth-dev the app compiles properly however when running it the app gets stuck on "[E] Failed to set advertising parameters!" similar to @NBreskvar Doing some simple debugging in gdb seems to suggest the app gets stuck with the function hci_send_req() which appears to be part of the core bluez stack -- the function always returns -1 which I think means that the app is unable to communicate with the bluetooth card. Not sure if this is related to hci being depreciated in Bluez. It would be nice if @MasterDevX could tell us what version / distro of Linux and what bluetooth card they were using so we can see whether using an older operating system would help.

I think "[W] Failed to send notification!" refers to the libnotify library which is probably only relevant for sending desktop notifications for GNOME-based environments.

(Interestingly when debugging the app on Ubuntu 20.04 it complains it can't find hci.c, again not sure if this has to do with modern Ubuntu putting the bluez stack in a snap. I'm not a C developer so feel free to correct the above statements if someone finds something else interesting.)

Justin8428 commented 1 year ago

update: working on Debian 12 with an Intel AC-8265 wireless card, interestingly the AX210 might be too new / unsupported for the hci_send_req() function. not sure what has changed in the linux bluetooth stack in the past three years but maybe this code only works on certain bluetooth cards / distros

MasterDevX commented 1 year ago

First of all, I'm sorry for responding that late. Anyways..

When I try verbose mode for setup, I get right away [W] Failed to send notification!, without any timeout, so I am not even sure if it tries to send anything.

This message itself is a not an error but a warning, so the program should work normally even if this pops up. What you can try to do is to download the nRF Connect app on your phone, click "Scan" and check if something actually appers on the screen when you run Lampify commands. If not, that means your device you have Lampify installed on doesn't send any data to the lamp.

I first tried to install it on a Raspberry Pi 3b+ and found the same issue as @ReX1983. It now runs and says Connecting to the lamp, but then stops right away. Of course the lamps also don't flash, so it's not connecting to the lamps.

It's also a good idea to start with playing around nRF connect, check the paragtaph above.

I then tried it on a laptop with a Live Ubuntu on a usb drive, on which I successfully installed it, but got a different error when trying to run "lampify q setup" which is : "[E] Failed to set advertising parameters!".

Can you specify the exact laptop model? First, you can try using bluetooth as you would usually do (connect wireless headset, transfer files, etc.) to make sure the bluetooth actually works while booted with live USB.

Either for some reason the RPi does not transmit the advertising packet or something is wrong.

You can check that via nRF connect, details at the beginning of my comment.

It would be nice if @MasterDevX could tell us what version / distro of Linux and what bluetooth card they were using so we can see whether using an older operating system would help.

The distro is Arch Linux with kernel version 6.4.7. Laptop model: Lenovo ideapad 330-15IKB. The bluetooth card is Qualcomm Atheros QCA9377 (rev 31).

not sure what has changed in the linux bluetooth stack in the past three years but maybe this code only works on certain bluetooth cards / distros

The thing I've noticed is that the card you reported Lampify worked on has bluetooth version 4.2, while the other one has 5.3. First, I thought this is the reason and the code is just incompatible with buetooth 5.x version, but then I've checked on my bluetooth card specs once again and it has bluetooth 5.0. So it looks like this is not the cause of the problem.

bilalhp commented 11 months ago

You can check that via nRF connect, details at the beginning of my comment.

I checked it, and there is activity. I can see RSSI value from "raspberrypi" updated each time I run setup. I guess it sends the packet and RSSI value is also good, but setup still never happens.

Is there a way to sniff BLE when I try setup with the original Lampsmart App?

RomuloGatto commented 8 months ago

Hello guys! I'm having the same issue, but I've found something that may be useful.

First, I was getting Failed to find adapter, then, I installed bluez and it evolved into the same error as @ReX1983 [W] Failed to send notification!

I was making some changes and then I discovered that hcitool(that is part of bluez, together with gatttool and bluetoothctl) seems to be incompatible with Bluetooth 5.0+, that way if I ran hcitool lescan, the error returned is Set scan parameters failed: Input/output error, which reassembles the error we all have on the on lampify.

image

For Bluetooth 5.0+, we should use bluetoothctl scan le, and it works as expected.

image

That's something that leads me to think that the code needs to do some checking to determine the version of the adapter and modify the command when 5.0+