Force connect to specific access point

Is it possible to force connect to a specific AP? I have I home network consisting out of a modem/router and an additional access point using the same ssid.

My problem is that I have a script running that automatically connects to a vpn at boot, and disconnects the connection when ping fails. To my understanding the connection completely breaks when the rpi2 switches from the initial router connection to the AP because of a better signal strength.

So I want to force to connect to specific access point. I do not want to change the ssid names. I read that on raspbian you would be able to prioritise a particular channel. I am looking for such a solution.

I don’t believe that it’s possible to prioritise wifi networks with connman unfortunately.

However you should be trying to solve the underlying problem of why the VPN connection drops when your Pi roams from one AP to the other, as roaming should not cause the VPN to drop.

Most likely your two AP’s are not using the same IP range, for example because your second AP is doing NAT of its own. Thus any TCP connections will drop when roaming from one AP to the other.

Make sure your second wifi router is in bridging mode not NAT mode and confirm that the client IP address is not changing when it roams from one AP to the other.

Thank you for your reply.
The router only handles ip addresses, since the AP is in bridge mode.
AP’s ip is outside of the dhcp range of the router. So i think all that is properly set up.

I have managed to get a log from the disconnect instance. I hope that you can help me look where the problem is.
At 18:52:50 the roaming starts, and connection breaks soon after.
(please help me how to format code in a forum message on OSMC forum. I don’t see the proper format options)

– Logs begin at Tue 2016-06-14 16:26:52 CEST, end at Tue 2016-06-14 19:10:28 CEST. –
Jun 14 18:47:19 osmc sshd[7434]: Accepted password for osmc from 192.168.2.155 port 49738 ssh2
Jun 14 18:47:19 osmc sshd[7434]: pam_unix(sshd:session): session opened for user osmc by (uid=0)
Jun 14 18:47:19 osmc systemd-logind[326]: New session c4 of user osmc.
Jun 14 18:47:19 osmc systemd[7447]: pam_unix(systemd-user:session): session opened for user osmc by (uid=0)
Jun 14 18:47:19 osmc systemd[7447]: Starting Paths.
Jun 14 18:47:19 osmc systemd[7447]: Reached target Paths.
Jun 14 18:47:19 osmc systemd[7447]: Starting Timers.
Jun 14 18:47:19 osmc systemd[7447]: Reached target Timers.
Jun 14 18:47:19 osmc systemd[7447]: Starting Sockets.
Jun 14 18:47:19 osmc systemd[7447]: Reached target Sockets.
Jun 14 18:47:19 osmc systemd[7447]: Starting Basic System.
Jun 14 18:47:19 osmc systemd[7447]: Reached target Basic System.
Jun 14 18:47:19 osmc systemd[7447]: Starting Default.
Jun 14 18:47:19 osmc systemd[7447]: Reached target Default.
Jun 14 18:47:19 osmc systemd[7447]: Startup finished in 45ms.
Jun 14 18:47:47 osmc kernel: IW_SCAN_THIS_ESSID, ssid=Apollo KPN, len=10
Jun 14 18:47:47 osmc kernel: Drop duplicate management frame with seq_num = 941.
Jun 14 18:47:47 osmc kernel: Drop duplicate management frame with seq_num = 941.
Jun 14 18:47:47 osmc kernel: Drop duplicate management frame with seq_num = 941.
Jun 14 18:47:47 osmc kernel: Drop duplicate management frame with seq_num = 941.
Jun 14 18:47:48 osmc kernel: survey done event(1a) band:0 for wlan0
Jun 14 18:52:48 osmc kernel: IW_SCAN_THIS_ESSID, ssid=Apollo KPN, len=10
Jun 14 18:52:50 osmc wpa_supplicant[593]: wlan0: Trying to associate with 4c:09:d4:60:3d:e8 (SSID=‘Apollo KPN’ freq=2462 MHz)
Jun 14 18:52:50 osmc connmand[336]: wlan0 {RX} 46945 packets 17531883 bytes
Jun 14 18:52:50 osmc connmand[336]: wlan0 {TX} 33173 packets 6904482 bytes
Jun 14 18:52:50 osmc connmand[336]: wlan0 {update} flags 102403 <UP,LOWER_UP>
Jun 14 18:52:50 osmc connmand[336]: wlan0 {newlink} index 3 address C4:E9:84:1B:F9:50 mtu 1500
Jun 14 18:52:50 osmc connmand[336]: wlan0 {newlink} index 3 operstate 5
Jun 14 18:52:50 osmc kernel: survey done event(11) band:0 for wlan0
Jun 14 18:52:50 osmc kernel: OnDeAuth Reason code(7)
Jun 14 18:52:50 osmc kernel: OnDeAuth, STA:ac:64:62:80:0f:d9, ignore = 0
Jun 14 18:52:50 osmc kernel: receive_disconnect
Jun 14 18:52:50 osmc kernel: report_del_sta_event: delete STA, mac_id=0
Jun 14 18:52:50 osmc kernel: OnDeAuth Reason code(7)
Jun 14 18:52:50 osmc kernel: OnDeAuth, STA:ac:64:62:80:0f:d9, ignore = 0
Jun 14 18:52:50 osmc kernel: receive_disconnect
Jun 14 18:52:50 osmc kernel: OnDeAuth Reason code(7)
Jun 14 18:52:50 osmc kernel: OnDeAuth, STA:ac:64:62:80:0f:d9, ignore = 0
Jun 14 18:52:50 osmc kernel: receive_disconnect
Jun 14 18:52:50 osmc kernel: HW_VAR_BASIC_RATE: BrateCfg(0x15d)
Jun 14 18:52:50 osmc kernel: HW_VAR_BASIC_RATE: BrateCfg(0x15d)
Jun 14 18:52:50 osmc connmand[336]: wlan0 {RX} 46945 packets 17531883 bytes
Jun 14 18:52:50 osmc connmand[336]: wlan0 {TX} 33173 packets 6905389 bytes
Jun 14 18:52:50 osmc wpa_supplicant[593]: wlan0: Association request to the driver failed
Jun 14 18:52:50 osmc connmand[336]: wlan0 {update} flags 36867
Jun 14 18:52:50 osmc wpa_supplicant[593]: wlan0: CTRL-EVENT-DISCONNECTED bssid=4c:09:d4:60:3d:e8 reason=0
Jun 14 18:52:50 osmc kernel: rtw_wx_set_auth…call rtw_indicate_disconnect
wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM
Jun 14 18:52:50 osmc kernel: set_mode = IW_MODE_INFRA
Jun 14 18:52:50 osmc kernel:
wpa_ie(length:22):
Jun 14 18:52:50 osmc kernel: 0x30 0x14 0x01 0x00 0x00 0x0f 0xac 0x04
Jun 14 18:52:50 osmc kernel: 0x01 0x00 0x00 0x0f 0xac 0x04 0x01 0x00
Jun 14 18:52:50 osmc kernel: 0x00 0x0f 0xac 0x02 0x00 0x00 0x43 0xe9
Jun 14 18:52:50 osmc kernel: SetHwReg8192CU, 5132, RCR= 700060ca
Jun 14 18:52:50 osmc kernel: =>rtw_wx_set_essid
Jun 14 18:52:50 osmc kernel: ssid=Apollo KPN, len=10
Jun 14 18:52:50 osmc kernel: Set SSID under fw_state=0x00000008
Jun 14 18:52:50 osmc kernel: [by_bssid:0][assoc_ssid:Apollo KPN][to_roaming:0] new candidate: Apollo KPN(ac:64:62:80:0f:d9, ch6) rssi:-70
Jun 14 18:52:50 osmc kernel: [by_bssid:0][assoc_ssid:Apollo KPN][to_roaming:0] new candidate: Apollo KPN(4c:09:d4:60:3d:e8, ch11) rssi:-68
Jun 14 18:52:50 osmc kernel: rtw_select_and_join_from_scanned_queue: candidate: Apollo KPN(4c:09:d4:60:3d:e8, ch:11)
Jun 14 18:52:50 osmc kernel: link to Broadcom AP
Jun 14 18:52:50 osmc kernel: <=rtw_wx_set_essid, ret 0
Jun 14 18:52:50 osmc kernel: Set BSSID under fw_state=0x00000088
Jun 14 18:52:50 osmc kernel: rtl8192c_set_FwJoinBssReport_cmd mstatus(0)
Jun 14 18:52:50 osmc kernel: hw_var_set_opmode()-4236 mode = 2
Jun 14 18:52:50 osmc kernel: start_join_set_ch_bw: ch=0, bwmode=0, ch_offset=0
Jun 14 18:52:50 osmc connmand[336]: wlan0 {newlink} index 3 address C4:E9:84:1B:F9:50 mtu 1500
Jun 14 18:52:50 osmc connmand[336]: wlan0 {newlink} index 3 operstate 2
Jun 14 18:52:50 osmc connmand[336]: Probably roaming right now! Staying connected…
Jun 14 18:52:50 osmc avahi-daemon[328]: Withdrawing address record for 192.168.2.11 on wlan0.
Jun 14 18:52:50 osmc avahi-daemon[328]: Leaving mDNS multicast group on interface wlan0.IPv4 with address 192.168.2.11.
Jun 14 18:52:50 osmc avahi-daemon[328]: Interface wlan0.IPv4 no longer relevant for mDNS.
Jun 14 18:52:50 osmc connmand[336]: wlan0 {del} address 192.168.2.11/24 label wlan0
Jun 14 18:52:50 osmc connmand[336]: wlan0 {del} route 192.168.2.0 gw 0.0.0.0 scope 253
Jun 14 18:52:50 osmc kernel: issue_deauth_ex(wlan0) to 00:00:00:00:00:00, ch:0, 5/5 in 540 ms
Jun 14 18:52:50 osmc kernel: rtl8192c_set_FwJoinBssReport_cmd mstatus(0)
Jun 14 18:52:51 osmc connmand[336]: Skipping disconnect of 41706f6c6c6f204b504e_managed_psk, network is connecting.
Jun 14 18:52:51 osmc connmand[336]: ipconfig state 2 ipconfig method 1
Jun 14 18:52:51 osmc wpa_supplicant[593]: wlan0: Trying to associate with ac:64:62:80:0f:d9 (SSID=‘Apollo KPN’ freq=2437 MHz)
Jun 14 18:52:51 osmc kernel: wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM
Jun 14 18:52:51 osmc kernel: set_mode = IW_MODE_INFRA
Jun 14 18:52:51 osmc kernel:
wpa_ie(length:22):
Jun 14 18:52:51 osmc kernel: 0x30 0x14 0x01 0x00 0x00 0x0f 0xac 0x04
Jun 14 18:52:51 osmc kernel: 0x01 0x00 0x00 0x0f 0xac 0x04 0x01 0x00
Jun 14 18:52:51 osmc kernel: 0x00 0x0f 0xac 0x02 0x00 0x00 0x00 0x00
Jun 14 18:52:51 osmc kernel: hw_var_set_opmode()-4236 mode = 2
Jun 14 18:52:51 osmc kernel: SetHwReg8192CU, 5132, RCR= 700060ca
Jun 14 18:52:51 osmc kernel: =>rtw_wx_set_essid
Jun 14 18:52:51 osmc kernel: ssid=Apollo KPN, len=10
Jun 14 18:52:51 osmc kernel: Set SSID under fw_state=0x00000008
Jun 14 18:52:51 osmc kernel: [by_bssid:0][assoc_ssid:Apollo KPN][to_roaming:0] new candidate: Apollo KPN(4c:09:d4:60:3d:e8, ch11) rssi:-68
Jun 14 18:52:51 osmc kernel: rtw_select_and_join_from_scanned_queue: candidate: Apollo KPN(4c:09:d4:60:3d:e8, ch:11)
Jun 14 18:52:51 osmc kernel: link to Broadcom AP
Jun 14 18:52:51 osmc kernel: <=rtw_wx_set_essid, ret 0
Jun 14 18:52:51 osmc kernel: start_join_set_ch_bw: ch=11, bwmode=0, ch_offset=0
Jun 14 18:52:51 osmc kernel: Set BSSID under fw_state=0x00000088
Jun 14 18:52:51 osmc wpa_supplicant[593]: wlan0: Association request to the driver failed
Jun 14 18:52:51 osmc kernel: link to Broadcom AP
Jun 14 18:52:51 osmc kernel: OnAuthClient
Jun 14 18:52:51 osmc kernel: network.SupportedRates[0]=82
Jun 14 18:52:51 osmc kernel: network.SupportedRates[1]=84
Jun 14 18:52:51 osmc kernel: network.SupportedRates[2]=8B
Jun 14 18:52:51 osmc kernel: network.SupportedRates[3]=96
Jun 14 18:52:51 osmc kernel: network.SupportedRates[4]=24
Jun 14 18:52:51 osmc kernel: network.SupportedRates[5]=30
Jun 14 18:52:51 osmc kernel: network.SupportedRates[6]=48
Jun 14 18:52:51 osmc kernel: network.SupportedRates[7]=6C
Jun 14 18:52:51 osmc kernel: network.SupportedRates[8]=0C
Jun 14 18:52:51 osmc kernel: network.SupportedRates[9]=12
Jun 14 18:52:51 osmc kernel: network.SupportedRates[10]=18
Jun 14 18:52:51 osmc kernel: network.SupportedRates[11]=60
Jun 14 18:52:51 osmc kernel: bssrate_len = 12
Jun 14 18:52:51 osmc kernel: declare supporting RX STBC
Jun 14 18:52:51 osmc connmand[336]: wlan0 {RX} 46945 packets 17531883 bytes
Jun 14 18:52:51 osmc connmand[336]: wlan0 {TX} 33173 packets 6905389 bytes
Jun 14 18:52:51 osmc connmand[336]: wlan0 {update} flags 102403 <UP,LOWER_UP>
Jun 14 18:52:51 osmc connmand[336]: wlan0 {newlink} index 3 address C4:E9:84:1B:F9:50 mtu 1500
Jun 14 18:52:51 osmc connmand[336]: wlan0 {newlink} index 3 operstate 5
Jun 14 18:52:51 osmc wpa_supplicant[593]: wlan0: Associated with 4c:09:d4:60:3d:e8
Jun 14 18:52:51 osmc kernel: OnAssocRsp
Jun 14 18:52:51 osmc kernel: report_join_res(3)
Jun 14 18:52:51 osmc kernel: rtw_joinbss_update_network
Jun 14 18:52:51 osmc kernel: +rtw_update_ht_cap()
Jun 14 18:52:51 osmc kernel: rtw_joinbss_update_stainfo
Jun 14 18:52:51 osmc kernel: HW_VAR_BASIC_RATE: BrateCfg(0x15d)
Jun 14 18:52:51 osmc kernel: WMM(0): 0, a42b
Jun 14 18:52:51 osmc kernel: WMM(1): 0, a44f
Jun 14 18:52:51 osmc kernel: WMM(2): 0, 5e4322
Jun 14 18:52:51 osmc kernel: WMM(3): 0, 2f3222
Jun 14 18:52:51 osmc kernel: HTOnAssocRsp
Jun 14 18:52:51 osmc kernel: OnAction_back
Jun 14 18:52:51 osmc kernel: OnAction_back, action=0
Jun 14 18:52:51 osmc kernel: issue_action_BA, category=3, action=1, status=0
Jun 14 18:52:51 osmc kernel: update raid entry, mask=0xfffffff, arg=0xa0
Jun 14 18:52:51 osmc kernel: rtl8192c_set_FwJoinBssReport_cmd mstatus(1)
Jun 14 18:52:51 osmc kernel: SetFwRsvdPagePkt
Jun 14 18:52:51 osmc kernel: Set RSVD page location to Fw.
Jun 14 18:52:51 osmc kernel: =>mlmeext_joinbss_event_callback
Jun 14 18:52:51 osmc wpa_supplicant[593]: wlan0: WPA: Key negotiation completed with 4c:09:d4:60:3d:e8 [PTK=CCMP GTK=CCMP]
Jun 14 18:52:51 osmc wpa_supplicant[593]: wlan0: CTRL-EVENT-CONNECTED - Connection to 4c:09:d4:60:3d:e8 completed [id=1 id_str=]
Jun 14 18:52:51 osmc connmand[336]: wlan0 {RX} 46947 packets 17532227 bytes
Jun 14 18:52:51 osmc connmand[336]: wlan0 {TX} 33175 packets 6905677 bytes
Jun 14 18:52:51 osmc connmand[336]: wlan0 {update} flags 102467 <UP,RUNNING,LOWER_UP>
Jun 14 18:52:51 osmc connmand[336]: wlan0 {newlink} index 3 address C4:E9:84:1B:F9:50 mtu 1500
Jun 14 18:52:51 osmc connmand[336]: wlan0 {newlink} index 3 operstate 6
Jun 14 18:52:51 osmc wpa_supplicant[593]: bgscan simple: Failed to enable signal strength monitoring
Jun 14 18:52:51 osmc kernel:
~~~~stastakey:unicastkey
Jun 14 18:52:51 osmc kernel: ~~~~set sta key:groupkey
Jun 14 18:52:51 osmc kernel: ==> rtw_set_key algorithm(4),keyid(1),key_mask(0)
Jun 14 18:52:51 osmc kernel: SetHwReg8192CU, 5128, RCR= 700060ce
Jun 14 18:52:51 osmc connmand[336]: ipconfig state 3 ipconfig method 1
Jun 14 18:52:51 osmc avahi-daemon[328]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.2.11.
Jun 14 18:52:51 osmc avahi-daemon[328]: New relevant interface wlan0.IPv4 for mDNS.
Jun 14 18:52:51 osmc avahi-daemon[328]: Registering new address record for 192.168.2.11 on wlan0.IPv4.
Jun 14 18:52:51 osmc connmand[336]: Setting domainname to home
Jun 14 18:52:51 osmc connmand[336]: wlan0 {add} address 192.168.2.11/24 label wlan0 family 2
Jun 14 18:52:51 osmc connmand[336]: wlan0 {add} route 192.168.2.0 gw 0.0.0.0 scope 253
Jun 14 18:52:51 osmc connmand[336]: wlan0 {add} route 192.168.2.254 gw 0.0.0.0 scope 253
Jun 14 18:52:51 osmc connmand[336]: wlan0 {add} route 0.0.0.0 gw 192.168.2.254 scope 0
Jun 14 18:52:52 osmc connmand[336]: wlan0 {add} route 159.253.212.250 gw 192.168.2.254 scope 0
Jun 14 18:52:52 osmc connmand[336]: wlan0 {del} route 159.253.212.250 gw 192.168.2.254 scope 0
Jun 14 18:54:11 osmc rc.local[364]: Tue Jun 14 18:54:11 2016 [nl14.nordvpn.com] Inactivity timeout (–ping-restart), restarting
Jun 14 18:54:11 osmc rc.local[364]: Tue Jun 14 18:54:11 2016 SIGUSR1[soft,ping-restart] received, process restarting
Jun 14 18:54:11 osmc rc.local[364]: Tue Jun 14 18:54:11 2016 Restart pause, 2 second(s)
Jun 14 18:54:13 osmc rc.local[364]: Tue Jun 14 18:54:13 2016 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Jun 14 18:54:13 osmc rc.local[364]: Tue Jun 14 18:54:13 2016 Socket Buffers: R=[163840->131072] S=[163840->131072]
Jun 14 18:54:13 osmc rc.local[364]: Tue Jun 14 18:54:13 2016 UDPv4 link local: [undef]
Jun 14 18:54:13 osmc rc.local[364]: Tue Jun 14 18:54:13 2016 UDPv4 link remote: [AF_INET]109.236.84.4:1194
Jun 14 18:54:43 osmc rc.local[364]: Tue Jun 14 18:54:43 2016 [UNDEF] Inactivity timeout (–ping-restart), restarting
Jun 14 18:54:43 osmc rc.local[364]: Tue Jun 14 18:54:43 2016 SIGUSR1[soft,ping-restart] received, process restarting
Jun 14 18:54:43 osmc rc.local[364]: Tue Jun 14 18:54:43 2016 Restart pause, 2 second(s)
Jun 14 18:54:45 osmc rc.local[364]: Tue Jun 14 18:54:45 2016 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Jun 14 18:54:45 osmc rc.local[364]: Tue Jun 14 18:54:45 2016 Socket Buffers: R=[163840->131072] S=[163840->131072]
Jun 14 18:54:45 osmc rc.local[364]: Tue Jun 14 18:54:45 2016 UDPv4 link local: [undef]
Jun 14 18:54:45 osmc rc.local[364]: Tue Jun 14 18:54:45 2016 UDPv4 link remote: [AF_INET]109.236.84.4:1194

Bump