TP-LINK TL-WN722N can't connect on 17.04

I had this TP-LINK TL-WN722N working on previous versions of ubuntu. 17.04 is a clean install and Wifi connection is not kept.

I can click on connect and it tries to connect but then I get a message saying wireless is disconnected.

sudo modprobe ath9k_htc returns nothing

$ iwconfig
bnep0     no wireless extensions.

wlx10feed20305c  IEEE 802.11  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

eno1      no wireless extensions.

lo        no wireless extensions.

$ lsusb
Bus 002 Device 005: ID 0b05:179c ASUSTek Computer, Inc.
Bus 002 Device 004: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 002 Device 003: ID 177f:0250 Sweex
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 004: ID 046d:c05b Logitech, Inc. M-U0004 810-001317 [B110 Optical USB Mouse]
Bus 005 Device 003: ID 413c:2010 Dell Computer Corp. Keyboard
Bus 005 Device 002: ID 413c:1003 Dell Computer Corp. Keyboard Hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 0bda:0136 Realtek Semiconductor Corp.
Bus 001 Device 005: ID 0cf3:9271 Atheros Communications, Inc. AR9271 802.11n
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


$ dmesg |  grep -e wlan -e ath9k
[    8.492093] usb 1-1.1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested
[    8.492104] usbcore: registered new interface driver ath9k_htc
[    8.781521] usb 1-1.1: ath9k_htc: Transferred FW: ath9k_htc/htc_9271-1.4.0.fw, size: 51008
[    9.033804] ath9k_htc 1-1.1:1.0: ath9k_htc: HTC initialized with 33 credits
[    9.303670] ath9k_htc 1-1.1:1.0: ath9k_htc: FW Version: 1.4
[    9.303672] ath9k_htc 1-1.1:1.0: FW RMW support: On
[    9.313272] ath9k_htc 1-1.1:1.0 wlx10feed20305c: renamed from wlan0
[  873.694860] usb 1-1.1: ath9k_htc: USB layer deinitialized
[ 1163.949779] usb 1-1.1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested
[ 1164.236649] usb 1-1.1: ath9k_htc: Transferred FW: ath9k_htc/htc_9271-1.4.0.fw, size: 51008
[ 1164.488920] ath9k_htc 1-1.1:1.0: ath9k_htc: HTC initialized with 33 credits
[ 1164.757511] ath9k_htc 1-1.1:1.0: ath9k_htc: FW Version: 1.4
[ 1164.757514] ath9k_htc 1-1.1:1.0: FW RMW support: On
[ 1164.769568] ath9k_htc 1-1.1:1.0 wlx10feed20305c: renamed from wlan0

[UPDATE]

$ dpkg -l network-manager
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                         Version                     Architecture                Description
+++-============================================-===========================-===========================-==============================================================================================
ii  network-manager                              1.4.4-1ubuntu3              amd64                       network management framework (daemon and userspace tools)

[/UPDATE]


I had a similar problem while updating from 16.10 to 17.04. The problem was solved by adding the following lines to /etc/NetworkManager/NetworkManager.conf and then restarting the computer.

[device]    
wifi.scan-rand-mac-address=0

I was facing similar issue after upgrading from 16.10 to 17.04. It is likely that this is happening because your device's MAC address is being randomised automatically. You can verify that by checking your MAC address using the ifconfig command (if you remembered the original address).

How to fix:

Add the following line to /etc/NetworkManager/NetworkManager.conf:

[device]
...
wifi.scan-rand-mac-address=0

Now save the file and restart network manager using:

sudo systemctl restart network-manager

Now reboot.