nymea / nymea-networkmanager

This daemon allows to set up the wireless network using a Bluetooth LE connection.
GNU General Public License v3.0
55 stars 16 forks source link

Custom native app to interact with nymea #34

Closed jaumard closed 4 years ago

jaumard commented 4 years ago

Hello !!

I'm searching for a way to setup the WiFi via BT on my raspberry pi home automation system (https://github.com/mylisabox) and find Nymea/berrylan (https://github.com/nymea/berrylan).

Look pretty interesting ! But I'm a bit lost ^^ so from what I understand I have to install nymea-networkmanager on my PI and that's basically it for server side.

I can't use berrylan because I already have my own mobile app and want it integrated to it, so my idea was to look how you did on native side of the app but it's all QT code lol which I don't know. So I tried to look at the BT protocole you have here but it is not clear to me too :(

So my main question is what are the minimal steps I have to do to talk with nymea in bluetooth. Because I only need to setup the WiFi if not already setup and that's it and look like nymea is doing more. Or is there any example of native iOS / Android interaction with nymea I could look

Boernsman commented 4 years ago

Hi, the nymea-networkmanager works standalone, you won't need nymea installed, though nymea could be of interest for your project (java-script plug-ins are supported as well).

What is not clear on the BT protocol? @rhythm-section maybe you can give a helping hand

jaumard commented 4 years ago

Ok look like your documentation is super clear, I just didn't had enough knowledge about BLE connection ^^ I was able to connect to nymea and retrieve the services and characteristics.

But when I tried to call getNetworks I get the response {"c":0,"p":[],"r":0}, but when I run iwlist wlan0 scan I'm getting

wlan0     Scan completed :
          Cell 01 - Address: 24:7F:20:C5:C5:FC
                    Channel:11
                    Frequency:2.462 GHz (Channel 11)
                    Quality=58/70  Signal level=-52 dBm  
                    Encryption key:on
                    ESSID:"BibouBox"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000000000000000
                    Extra: Last beacon: 50ms ago
                    IE: Unknown: 00084269626F75426F78
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 03010B
                    IE: Unknown: 050402030000
                    IE: Unknown: 0706465220010D14
                    IE: Unknown: 2A0100
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1AAD011BFFFF0000000000000000000000000000000406E4A70C00
                    IE: Unknown: 3D160B080400000000000000000000000000000000000000
                    IE: Unknown: DD180050F2020101850003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK

So there is a a WiFi available but none are returned by nymea :/ did I miss something?

jaumard commented 4 years ago

I'm running nymea on a raspberry pi 3

mzanetti commented 4 years ago

Can you try to explicitly call "Scan" before "GetNetworks"?

jaumard commented 4 years ago

I just tried but no luck :( But on raspberry pi side when I call Scan I can see NetworkManager: Scan error: "org.freedesktop.NetworkManager.Device.NotAllowed" "Scanning not allowed while unavailable or activating" not sure what I can do about that

mzanetti commented 4 years ago

Can you paste the whole log from startup to reproducing the issue please.

jaumard commented 4 years ago

Sure here is my logs:

 nymea-networkmanager -m always
 I | Application: Using configuration file from: "/etc/nymea/nymea-networkmanager.conf"
 I | Application: =====================================
 I | Application: Starting nymea-networkmanager "0.3.0"
 I | Application: =====================================
 I | Application: Advertising name: "mylisabox"
 I | Application: Platform name: "mylisabox"
 I | Application: Mode: Core::Mode(ModeAlways)
 I | Application: Timeout: 60
 W | NymeaService: Invalid D-Bus HardwareManager interface.
 W | NymeaService: Could not init nymea D-Bus services
 I | Application: NetworkManager::NetworkManagerState(NetworkManagerStateConnectedGlobal)
 I | Application: Networkmanager networking is now enabled
 I | Application: Networkmanager wireless networking is now enabled
 I | Application: Init is running
 I | Application: Post run service
 I | Application: Start the bluetooth service because of "always" mode.
 I | Application: Start service
 W | NymeaService: Could not enable/disable bluetooth hardware resource. D-Bus interface not available.
 I | Application: Start bluetooth service
 I | Application: Bluetooth server started
 I | Application: Bluetooth client connected
 W | qt.bluetooth.bluez: sending error response; request: 16 handle: 51 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 1 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 11 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 12 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 20 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 21 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 23 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 24 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 37 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 39 code: 10
 W | qt.bluetooth.bluez: sending error response; request: 8 handle: 49 code: 10
 W | NetworkManager: Scan error: "org.freedesktop.NetworkManager.Device.NotAllowed" "Scanning not allowed while unavailable or activating"
mzanetti commented 4 years ago

Hmm... Quite strange... Can you try scanning in command line with nmcli?

nmcli d wifi list

Perhaps this could be of help https://unix.stackexchange.com/questions/567622/networkmanager-not-allowing-scan-of-available-wifi-aps

jaumard commented 4 years ago

Hum with nmcli d wifi list I have no result too

nmcli dev wifi rescan give me Error: Scanning not allowed while unavailable or activating look like wpa_supplicant is already running too

jaumard commented 4 years ago

So I have made a fresh install of raspbian to be test if it was better.

To install I've run:

echo "deb http://repository.nymea.io stretch main raspbian" | sudo tee /etc/apt/sources.list.d/nymea.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key A1A19ED6
nano /etc/apt/preferences.d/nymea

Content :

Package: *
Pin: release c=raspbian
Pin-Priority: 700

Package: *
Pin: origin repository.nymea.io c=main
Pin-Priority: 500
sudo apt-get update
sudo apt-get install nymea-networkmanager dirmngr

But result was the same :( still not able to have results on getNetworks

jaumard commented 4 years ago

I've tried to anyway called Connect and ConnectHidden with ssid and password and the result is {c: 1, r: 0} but no wifi connection on the PI at all...

jaumard commented 4 years ago

So I was able to have result on getNetworks!

But I had to do the following changes:

Edit /etc/dhcpcd.conf and add denyinterfaces wlan0 on it

Edit /etc/NetworkManager/NetworkManager.conf and change managed to true

And after a reboot getNetworks start giving me results!

So step 1 done ^^ but Connect still doesn't work for some reason :(

If I tried to connect from command line with nmcli device wifi con "SSID" password "PASS" it works. But from a Connect action it doesn't, it just say success but there is no connection and nothing in logs.

Any ideas ?

mzanetti commented 4 years ago

So, on our BerryLan/nymea images we completely remove dhcpcd.

Here you can see all the changes we make to the plain raspbian image:

https://github.com/nymea/pi-gen/commit/069f16df263c9072b5b490cb87ebb13464994956

jaumard commented 4 years ago

I've tried to build my own pi-gen version based on yours, but I encounter some issues

I have getNetworks working but one I tried to connect to the network I'm getting {c: 1, r: 7} but not sure to understand 7 error mean from the doc and mostly how to fix it ^^

mzanetti commented 4 years ago

Hmm... Error 7 seems to be "unknown error". I'm sure in that case the logs of nymea-networkmanager print something...

Here's a hint: if you configure nymea-networkmanager to be enabled always, you can connect the pi to ethernet and SSH into it and then use journalctl to live-monitor the logs while doing the bluetooth setup.

jaumard commented 4 years ago

I've checked the log nothing's popup but as I shows the json command I was able to find out the error, I got a bug in my send request and a character wasn't sent on ssid and password. So ssid wasn't existing as a character was missing. Once I fix that bug everything is ok now. Maybe adding another error like 8: "Network info wrong" would be helpful (even for people to show right error messages) because I tried with a good ssid but wrong password I also get a 7.

For me 7 is "An unknow error as occured" for error message dialog. I would like to be able to say "Network unreachable please check your password"

mzanetti commented 4 years ago

Fair point.

Glad you got it working.

jaumard commented 4 years ago

So I've made a Flutter package to interact with nymea network manager. So far so good :) thanks a lot for your help and for this!

https://github.com/mylisabox/nymea_network_manager

jaumard commented 4 years ago

Hello guys!

I'm back to you because for some reason nymea doesn't start the bluetooth server when the PI boots, if I launch it manually no problem. But is it normal it doesn't start with the system ? Anything I should do ? Or any logs I can look at to search for errors ?

jaumard commented 4 years ago

Look like on PI 3 it start on boot, but PI 4 it doesn't :( based on the image generated with the pi-gen

mzanetti commented 4 years ago

Hi @jaumard

wow, that's pretty cool.

For the problem you're facing. Perhaps you can try to check nymea-networkmanagers logs. Right now I'm not sure why it wouldn't work for you. When it doesn't work, please fetch the logs from sudo journalctl -u nymea-networkmanager from the boot until the end and post it here.