Monthly Archives: February 2023

Python with decoupled variables

Sometimes a need to get variables into your Python code, without hard-coding them into the program itself will arise.

Here is how it can handled.

    sudo apt install python3-decouple -y

Add this into your py program’s import lines:

from decouple import config

Next, you need to create .env file and insert variables into it.

touch .env

nano .env

SOME_VAR=some_value

Then in your code, you would refer to your variable like this:

some_var=config(“SOME_VAR”)

Linux bluetooth connection setup from the system’s start

  1. Multichannel keyboard that needed a pin entered (Logitech K480).
  2. JBL Flip Essential 2 bluetooth speaker.

With the keyboard, scan and connect via cli:

bluetoothctl

From the [bluetooth], turn on power, turn on agent and start scanning for devices.

[bluetooth] power on
[bluetooth] agent on
[bluetooth] scan on

Next, pair your keyboard:

pair <mac_address_of_the_keyboard>

When you get prompted a code type it with the keyboard that you are pairing and press enter with it.

At this point, I got a pairing success message. This pairing process also worked with the Blueman applet. But for some reason it was not permanent with my Logitech K480 keyboard. When pairing was done via cli it was permanent and survived a computer reboot. I suspect this being because the gui never asked for any pin, whereas the cli did.

Finally from the cli, I connected my keyboard with:

connect <mac_address_of_the_keyboard>

In the end the cli process was so stable and nice, that I ended up pairing and connecting all my devices via it. Blueman that I had used previously, got removed.

When pairing and connecting was done, I needed to get my bluetooth devices connecting from the system’s startup(automatically). Here is a bash script together with a systemd file to accomplish that:

sudo nano /opt/bluetooth.sh

Script content example:

Continue reading