bluetooth keyboard disconnects after an hour

The bluetooth keyboard ‘Microsoft Bluetooth Mobile Keyboard 5000’ randomly disconnects after an hour of use on a Thinkpad X201.

This only occurs on AC/DC but not on battery and not with other devices. Once disconnected, the following script reconnects it:


/usr/sbin/rfkill   block bluetooth
sleep 1s
/usr/sbin/rfkill unblock bluetooth
sleep 1s
/usr/bin/hciconfig hci0 reset
sleep 1s
/usr/sbin/rfkill unblock bluetooth
sleep 1s
/usr/bin/hciconfig hci0 reset

How to prevent the keyboard from disconnecting?