Allow trigger for changed bssid

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
Sebastian Waschik
Posts: 5
Joined: 23 Oct 2016 21:29

Allow trigger for changed bssid

Post by Sebastian Waschik » 24 Oct 2016 07:17

Hello,

I do not find a trigger for connecting to a different wifi bssid but with the same ssid. In the forum I find only topics using a periodic timer ("German:wlan gebiete durch Mac Adresse trennen").

If I use the connect to wlan it will only trigger if I was not previously connected to the same ssid. If I use scan reports available I have to regularly scan the network: This requires also a periodic timer otherwise it does not trigger.

According to following website a trigger would be possible: In Llama the condition is possible because I can enter mac addresses/bssi in the "connected to wifi" dialog. This triggers then only if I connect to that specific bssid. Even if I was connected to the same ssid before.

Background: I have for all networks the same ssid for not entering the password in all devices several time. On of the access points is placed before the door so I could start a FHEM condition before leaving.

Thanks

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Allow trigger for changed bssid

Post by MURTUMA » 24 Oct 2016 08:47

You can save the current bssid to a globar var and when connecting again to a network check with condition Expression, if the newly connected bssid is the previous(the one saved in global var).

Sebastian Waschik
Posts: 5
Joined: 23 Oct 2016 21:29

Re: Allow trigger for changed bssid

Post by Sebastian Waschik » 24 Oct 2016 19:15

Thanks for you answer. But my problem is that I will not get a trigger when Wifi is changed. I think the wifi connected (German: "WLAN Verbunden: Alle SSIDs") is only triggered if the phone was not connected to any phone before. I think for many usecases this makes sense. But I like to trigger a wifi access point change for the same ssid. So I could trigger if I move around inside the building (for me that works fine for two areas).

I tried it also with the attach flow. For simplification I simply disable and enable WLAN to force connect message. I triggered it manually at 20:22:11. Then I walked to a different bssid. At 20:23:39 Llama reports WLAN change (actually connect to a specified bssid). For testing I triggered again at 20:24:06 manually.

At the moment I see as workaround in Automagic only a periodic trigger and check wifi connected condition (German: "WLAN verbunden") for the bssid.

Here the log with BSSID1 and BSSID2 for the bssids and SSID for the SSID. Globals are masked with "...".

Code: Select all

24.10.2016 20:22:11.386 [WLAN connect] Starting to execute flow 'WLAN connect' with Context{global{...},local{flow_name=WLAN connect,triggertime=1477333331384,trigger=Manual}}
24.10.2016 20:22:11.388 [WLAN connect] Start executing condition 'Expression: trigger == "Manual"'
24.10.2016 20:22:11.503 [WLAN connect] End executing condition 'Expression: trigger == "Manual"' with return value true
24.10.2016 20:22:11.509 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:22:11.510 [WLAN connect] Start executing action 'WLAN ein-/ausschalten: Aus'
24.10.2016 20:22:11.516 [WLAN connect] Action 'WLAN ein-/ausschalten: Aus' enable = false
24.10.2016 20:22:11.550 [WLAN connect] End executing action 'WLAN ein-/ausschalten: Aus'
24.10.2016 20:22:11.551 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:22:11.559 [WLAN connect] Start executing action 'Pause: 5s (Gerät wach halten)'
24.10.2016 20:22:11.594 [WLAN connect] Action 'Pause: 5s (Gerät wach halten)' Sleeping for 5s (keep device awake)
24.10.2016 20:22:16.610 [WLAN connect] End executing action 'Pause: 5s (Gerät wach halten)'
24.10.2016 20:22:16.706 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:22:16.707 [WLAN connect] Start executing action 'WLAN ein-/ausschalten: Ein'
24.10.2016 20:22:16.711 [WLAN connect] Action 'WLAN ein-/ausschalten: Ein' enable = true
24.10.2016 20:22:16.746 [WLAN connect] End executing action 'WLAN ein-/ausschalten: Ein'
24.10.2016 20:22:16.748 [WLAN connect] Flow ended.
24.10.2016 20:22:21.771 Trigger 'WLAN Verbunden: Alle SSIDs' going to execute flows
24.10.2016 20:22:21.773 [WLAN connect] Starting to execute flow 'WLAN connect' with Context{global{...},local{flow_name=WLAN connect,trigger=WLAN Verbunden: Alle SSIDs,triggertime=1477333341771,bssid=BSSID1,ssid=SSID}}
24.10.2016 20:22:21.775 [WLAN connect] Start executing condition 'Expression: trigger == "Manual"'
24.10.2016 20:22:21.881 [WLAN connect] End executing condition 'Expression: trigger == "Manual"' with return value false
24.10.2016 20:22:21.885 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:22:21.886 [WLAN connect] Start executing action 'Meldungsdialog: WLAN Connect {bssid}'
24.10.2016 20:22:30.529 [WLAN connect] End executing action 'Meldungsdialog: WLAN Connect {bssid}'
24.10.2016 20:22:30.703 [WLAN connect] Flow ended.
24.10.2016 20:24:06.712 [WLAN connect] Starting to execute flow 'WLAN connect' with Context{global{...},local{flow_name=WLAN connect,triggertime=1477333446710,trigger=Manual}}
24.10.2016 20:24:06.714 [WLAN connect] Start executing condition 'Expression: trigger == "Manual"'
24.10.2016 20:24:06.829 [WLAN connect] End executing condition 'Expression: trigger == "Manual"' with return value true
24.10.2016 20:24:06.833 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:24:06.834 [WLAN connect] Start executing action 'WLAN ein-/ausschalten: Aus'
24.10.2016 20:24:06.838 [WLAN connect] Action 'WLAN ein-/ausschalten: Aus' enable = false
24.10.2016 20:24:06.859 [WLAN connect] End executing action 'WLAN ein-/ausschalten: Aus'
24.10.2016 20:24:06.860 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:24:06.860 [WLAN connect] Start executing action 'Pause: 5s (Gerät wach halten)'
24.10.2016 20:24:06.861 [WLAN connect] Action 'Pause: 5s (Gerät wach halten)' Sleeping for 5s (keep device awake)
24.10.2016 20:24:11.863 [WLAN connect] End executing action 'Pause: 5s (Gerät wach halten)'
24.10.2016 20:24:11.973 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:24:11.974 [WLAN connect] Start executing action 'WLAN ein-/ausschalten: Ein'
24.10.2016 20:24:11.975 [WLAN connect] Action 'WLAN ein-/ausschalten: Ein' enable = true
24.10.2016 20:24:12.009 [WLAN connect] End executing action 'WLAN ein-/ausschalten: Ein'
24.10.2016 20:24:12.010 [WLAN connect] Flow ended.
24.10.2016 20:24:17.051 Trigger 'WLAN Verbunden: Alle SSIDs' going to execute flows
24.10.2016 20:24:17.054 [WLAN connect] Starting to execute flow 'WLAN connect' with Context{global{...},local{flow_name=WLAN connect,trigger=WLAN Verbunden: Alle SSIDs,triggertime=1477333457051,bssid=BSSID2,ssid=SSID}}
24.10.2016 20:24:17.058 [WLAN connect] Start executing condition 'Expression: trigger == "Manual"'
24.10.2016 20:24:17.172 [WLAN connect] End executing condition 'Expression: trigger == "Manual"' with return value false
24.10.2016 20:24:17.174 [WLAN connect] Flow continues executing with the next step.
24.10.2016 20:24:17.175 [WLAN connect] Start executing action 'Meldungsdialog: WLAN Connect {bssid}'
24.10.2016 20:24:24.542 [WLAN connect] End executing action 'Meldungsdialog: WLAN Connect {bssid}'
24.10.2016 20:24:24.744 [WLAN connect] Flow ended.
Attachments
flow_WLAN_connect_20161024_203729.xml
(2.62 KiB) Downloaded 912 times

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Allow trigger for changed bssid

Post by Martin » 25 Oct 2016 14:15

Hi,

Automagic should also execute the flow when the BSSID changes. Could you please enable Debug Log in the preferences of Automagic, enable the flow, wait until the BSSID changed (without turning WiFi temporarily off) and then send the log to me (on the flow list: menu->Manage->Log, Menu->Send log)?

Regards,
Martin

Sebastian Waschik
Posts: 5
Joined: 23 Oct 2016 21:29

Re: Allow trigger for changed bssid

Post by Sebastian Waschik » 26 Oct 2016 00:23

The log is actually useless:

Code: Select all

26.10.2016 00:25:04.130 Debug Log active
26.10.2016 00:46:29.661 Debug Log inactive
I have three access points. A with 2.4 and 5 GHz (with bsids <MAC_A1> and <MAC_A2>), B 2.4 GHz (with bssid <MAC_B>) and C 2.4 GHz (with bssid <MAC_C>)

My phone was connected to A. I walked to B and back. Then I enabled Llama and did that again. I got again a log like this:

Code: Select all

26.10.2016 00:51:09.581 Debug Log active
26.10.2016 00:55:37.073 Debug Log inactive
Log A says:

Code: Select all

26.10.16 00:54:00 WLAN-Gerät hat sich neu angemeldet (2,4 GHz), 72 Mbit/s, <NAME_PHONE>, IP <IP_PHONE>, MAC <MAC_PHONE>.
Log B says:

Code: Select all

26.10.16 00:52:26 WLAN-Gerät angemeldet , 72 Mbit/s, <NAME_PHONE>, IP <IP_PHONE>, MAC <MAC_PHONE>. [2 Meldungen seit 26.10.16 00:32:49]
Llama log contains:

Code: Select all

[...]
2016/10/26 00:52:25 - Events to Enqueue 0
2016/10/26 00:52:25 - IntentReceiver.onReceive
2016/10/26 00:52:25 - Service already started
2016/10/26 00:52:25 - Intent Action is android.net.wifi.supplicant.STATE_CHANGE
2016/10/26 00:52:25 WifiCond WifiCond: Wifi state is ASSOCIATED
2016/10/26 00:52:25 IntentProfile IntentProfile: android.net.wifi.supplicant.STATE_CHANGE = 6ms
2016/10/26 00:52:25 SW-RtcWakeLock SW-RtcWakeLock: RtcWakeLock wakelock not held
2016/10/26 00:52:26 - IntentReceiver.onReceive
2016/10/26 00:52:26 - Service already started
2016/10/26 00:52:26 - Intent Action is android.net.wifi.supplicant.STATE_CHANGE
2016/10/26 00:52:26 WifiCond WifiCond: Wifi state is COMPLETED
2016/10/26 00:52:26 WifiDebug WifiDebug: Handling wifi disconnect, seeing if we had a previous network
2016/10/26 00:52:26 WifiCond WifiCond: Last Wifi network was <SSID> with <MAC_A2>, running disconnect events
2016/10/26 00:52:26 EventBuffer EventBuffer: TestEvent: StateChange triggertype=16 got 2 triggerable events.
[...]

2016/10/26 00:52:26 - Events to Enqueue 0
2016/10/26 00:52:26 WifiCond WifiCond: New Wifi network is <SSID> with <MAC_B>
2016/10/26 00:52:26 EventBuffer EventBuffer: TestEvent: StateChange triggertype=15 got 2 triggerable events.
[...]
Ran actions for action with ID lo

2016/10/26 00:52:26 - Events to Enqueue 0
2016/10/26 00:52:26 IntentProfile IntentProfile: android.net.wifi.supplicant.STATE_CHANGE = 36ms
2016/10/26 00:52:26 SW-RtcWakeLock SW-RtcWakeLock: RtcWakeLock wakelock not held
2016/10/26 00:52:33 SignalStrength SignalStrength: Signal strength is -97 (8,-120,-120)
2016/10/26 00:52:33 EventBuffer EventBuffer: TestEvent: StateChange triggertype=45 got 0 triggerable events.
[...]
2016/10/26 00:54:00 - Events to Enqueue 0
2016/10/26 00:54:00 - IntentReceiver.onReceive
2016/10/26 00:54:00 - Service already started
2016/10/26 00:54:00 - Intent Action is android.net.wifi.supplicant.STATE_CHANGE
2016/10/26 00:54:00 WifiCond WifiCond: Wifi state is COMPLETED
2016/10/26 00:54:00 WifiDebug WifiDebug: Handling wifi disconnect, seeing if we had a previous network
2016/10/26 00:54:00 WifiCond WifiCond: Last Wifi network was <SSID> with <MAC_B>, running disconnect events
2016/10/26 00:54:00 EventBuffer EventBuffer: TestEvent: StateChange triggertype=16 got 2 triggerable events.
[...]

2016/10/26 00:54:00 - Events to Enqueue 0
2016/10/26 00:54:00 WifiCond WifiCond: New Wifi network is <SSID> with <MAC_A2>
2016/10/26 00:54:00 EventBuffer EventBuffer: TestEvent: StateChange triggertype=15 got 2 triggerable events.
TestEvent: Event 'Zuhause Licht aus' failed at condition com.kebab.Llama.EventConditions.WifiNetworkConnectedCondition
TestEvent: Event Zuhause Licht aus success but NO trigger condition

2016/10/26 00:54:00 - Events to Enqueue 0
2016/10/26 00:54:00 IntentProfile IntentProfile: android.net.wifi.supplicant.STATE_CHANGE = 54ms
2016/10/26 00:54:00 SW-RtcWakeLock SW-RtcWakeLock: RtcWakeLock wakelock not held
2016/10/26 00:54:01 - IntentReceiver.onReceive
2016/10/26 00:54:01 - Service already started
2016/10/26 00:54:01 - Intent Action is android.intent.action.SCREEN_OFF
2016/10/26 00:54:01 EventBuffer EventBuffer: TestEvent: StateChange triggertype=14 got 0 triggerable events.

[...]
Looks like Llama is using SUPPLICANT_STATE_CHANGED_ACTION: https://developer.android.com/reference ... State.html .


The phone has Android 4.2.2. I tried also another device with Android 5.1.1 and get the same behaviour. One time the switch from B to A was successful. Maybe that was because there was a disconnect before the connect.

Code: Select all

25.10.2016 23:20:43.366 Received intent Intent { act=android.net.wifi.flg=0x8000010       STATE_CHANGE (has extras) } extras: networkInfo=NetworkInfo: type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: <unknown ssid>, roaming: false, failover: false, isAvailable: true, bssid=<MAC_B>, linkProperties=InterfaceName: wlan0 LinkAddresses: [<IP_PHONE>/24,] Routes: [0.0.0.0/0 -> <IP_ROUTER>,] DnsAddresses: [<IP_ROUTER>,] HttpProxy: [ProxyProperties.mHost == null] 
25.10.2016 23:20:43.370 Received intent finished
25.10.2016 23:20:43.752 Received intent Intent { act=android.net.wifi.STATE_CHANGE flg=0x8000010 (has extras) } extras: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: "<SSID>", roaming: false, failover: false, isAvailable: true, bssid=<MAC_A2>, linkProperties=LinkAddresses: [] Routes: [] DnsAddresses: [] 
25.10.2016 23:20:43.753 Received intent finished
25.10.2016 23:20:44.681 Received intent Intent { act=android.net.wifi.STATE_CHANGE flg=0x8000010 (has extras) } extras: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/VERIFYING_POOR_LINK, reason: (unspecified), extra: "<SSID>", roaming: false, failover: false, isAvailable: true, bssid=<MAC_A2>, wifiInfo=, Supplicant state: COMPLETED, RSSI: -50, Link speed: 72, Net ID: 1, Metered hint: false, mFrequency: 2412, linkProperties=InterfaceName: wlan0 LinkAddresses: [<IP_PHONE>/24,] Routes: [0.0.0.0/0 -> <IP_ROUTER>,] DnsAddresses: [<IP_ROUTER>,] HttpProxy: [ProxyProperties.mHost == null] 
25.10.2016 23:20:44.683 Received intent finished
25.10.2016 23:20:44.686 Received intent Intent { act=android.net.wifi.STATE_CHANGE flg=0x8000010 (has extras) } extras: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/CAPTIVE_PORTAL_CHECK, reason: (unspecified), extra: "<SSID>", roaming: false, failover: false, isAvailable: true, bssid=<MAC_A2>, linkProperties=InterfaceName: wlan0 LinkAddresses: [<IP_PHONE>/24,] Routes: [0.0.0.0/0 -> <IP_ROUTER>,] DnsAddresses: [<IP_ROUTER>,] HttpProxy: [ProxyProperties.mHost == null] 
25.10.2016 23:20:44.693 Received intent finished
25.10.2016 23:20:44.696 Received intent Intent { act=android.net.wifi.STATE_CHANGE flg=0x8000010 (has extras) } extras: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "<SSID>", roaming: false, failover: false, isAvailable: true, bssid=<MAC_A2>, wifiInfo=, Supplicant state: COMPLETED, RSSI: -50, Link speed: 72, Net ID: 1, Metered hint: false, mFrequency: 2412, linkProperties=InterfaceName: wlan0 LinkAddresses: [<IP_PHONE>/24,] Routes: [0.0.0.0/0 -> <IP_ROUTER>,] DnsAddresses: [<IP_ROUTER>,] HttpProxy: [ProxyProperties.mHost == null] 
25.10.2016 23:20:44.698 Trigger 'WLAN Verbunden: Alle SSIDs' action matches, executing flows
25.10.2016 23:20:44.781 Trigger 'WLAN Verbunden: Alle SSIDs' going to execute flows
25.10.2016 23:20:44.782 Execution context acquire
25.10.2016 23:20:44.814 [WLAN connect] Starting to execute flow 'WLAN connect' with Context{global{},local{flow_name=WLAN connect,trigger=WLAN Verbunden: Alle SSIDs,triggertime=1477430444781,bssid=<MAC_A2>,ssid=<SSID>}}
25.10.2016 23:20:44.816 [WLAN connect] Start executing condition 'Expression: trigger == "Manual"'
25.10.2016 23:20:44.824 Removed worker
25.10.2016 23:20:44.825 Queue contains 0 workerInfos
25.10.2016 23:20:44.826 Received intent finished
25.10.2016 23:20:44.839 [WLAN connect] End executing condition 'Expression: trigger == "Manual"' with return value false
25.10.2016 23:20:44.840 [WLAN connect] Flow continues executing with the next step.
25.10.2016 23:20:44.841 [WLAN connect] Start executing action 'Meldungsdialog: WLAN Connect {bssid}'
25.10.2016 23:21:38.547 [WLAN connect] End executing action 'Meldungsdialog: WLAN Connect {bssid}'
25.10.2016 23:21:38.558 [WLAN connect] Flow ended.
25.10.2016 23:21:38.559 Flows need not to be saved
}

It also works most time if I switch between A and C with FRITZ!WLAN app. Then this looks also like a disconnect and a connect.

I read https://developer.android.com/reference ... GED_ACTION :
WIFI_STATE_CHANGED_ACTION
Added in API level 1

String WIFI_STATE_CHANGED_ACTION

Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown. One extra provides this state as an int. Another extra provides the previous state, if available.
As fare as I understand this will not report a change from enabled to enabled with a changed wifi connection. Maybe I am wrong. I have no experience in Android programming.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Allow trigger for changed bssid

Post by Martin » 26 Oct 2016 18:55

Thanks for the logs!

I was under the impression that the network-changed notification of Android that Automagic is using is sent when the WiFi connects to another BSSID since this info is included in the event, seems like this was a wrong assumption.
The WiFi state change event is only used to notify when the WiFi adapter is turned on and off but not when a connectivity change occurs.
I'll make some tests using the supplicant state event to see if this can be incorporated into the existing trigger without causing any trouble. I'll probably have access to a WiFi network with a few different BSSIDs tomorrow so I hope to have some more results soon.

You could also try to use the trigger General Broadcast with action android.net.wifi.supplicant.STATE_CHANGE (it's also available by pressing the [...]-button) and everything else in the trigger left empty to see if you can use this as a workaround in the meantime.

Regards,
Martin

Sebastian Waschik
Posts: 5
Joined: 23 Oct 2016 21:29

Re: Allow trigger for changed bssid

Post by Sebastian Waschik » 27 Oct 2016 00:39

Thank you. I will test that. So I hope my "problem" is solved. I will now try something with 'newState = getParcelableAsString("newState"); if (newState == "COMPLETED") { ...} '. I have to check for the newState. Otherwise I get multiple triggers. Maybe ASSOCIATED is better. There is also FOUR_WAY_HANDSHAKE.

While look for that I find also forum comments that have trouble with message for disconnect. But I wonder if that is the case.

Maybe this could be also tested with different ssids, as long as the machine knows all the passwords.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Allow trigger for changed bssid

Post by Martin » 28 Oct 2016 19:52

I had a chance to make some tests today. My device (Nexus 5X with Android 7.1-preview) properly executed the WiFi Connected trigger when the BSSID changed so it seems to be device dependent or does not behave the same on different versions of Android. I'll likely add a workaround so that android.net.wifi.supplicant.STATE_CHANGE is also considered by the trigger. In my tests today the COMPLETED state seems to work quite well, ASSOCIATED was missing sometimes (at least on my device).

Would be great if you could test the next EAP build of version 1.33 to see if my fix also works on your device.

Regards,
Martin

Sebastian Waschik
Posts: 5
Joined: 23 Oct 2016 21:29

Re: Allow trigger for changed bssid

Post by Sebastian Waschik » 31 Oct 2016 21:46

Hello,

sorry, I had not time to test earlier. Today I tested with EAP version 1.33.0-dev again with a Flow with "WLAN verbunden" with log writing and debug dialog. I see the indent but it seems not to be triggered. Maybe I used the wrong trigger. Because there should not flows from development version published outside the EAP section I send you the flow with mail. Extract from log file:

Code: Select all

31.10.2016 22:32:38.682 Debug Log active
31.10.2016 22:33:16.937 Received intent Intent { act=android.net.wifi.supplicant.STATE_CHANGE flg=0x28000010 (has extras) } extras: newState=FOUR_WAY_HANDSHAKE
31.10.2016 22:33:16.940 Received intent finished
31.10.2016 22:33:16.948 Received intent Intent { act=android.net.wifi.supplicant.STATE_CHANGE flg=0x28000010 (has extras) } extras: newState=COMPLETED
31.10.2016 22:33:16.949 Received intent finished
31.10.2016 22:33:56.249 Debug Log inactive

Locked