My (python) program (on Raspberry Pi zero W) turns on/off a GPIO pin (connected to a relay module) depending on the RSSI signal of my phone (connected via bluetooth) and the status of one more GPIO pin (a button). The relay should be turned ON If the button is ON and the if RSSI reads zero or above.
[for most of the time of the day, the phone will be connected and button will be OFF]

button connection

Here is a PART of the code (I have the complete code which works correctly)

    def get_connected_devices(check_dev = False):
        devs =  subprocess.check_output(["sudo", "hcitool", "con"]).split('ACL')
        if len(devs) is 1:
            return False
            del devs[0] #removes the first element
            device_list = []

            for dev in devs:

            if check_dev:
                if check_dev in device_list:
                    return True
                    return False
                return device_list

    while get_connected_devices(phone.mac):
        if button.is_pressed and phone.read_rssi():
            while True:
                if phone.rssi >= 0:

                #conditions to turn off the relay
                elif phone.n_signal >= true_max_n_count or phone.rssi < phone.away_threshold:

                if not phone.read_rssi():
                    if not get_connected_devices(phone.mac):
                        print "phone disconnected"

This code keeps checking if the phone is connected (using my own function) and the status of the button (using gpioZero) every 1.7 seconds and if it is pressed it starts reading the RSSI

My questions:

a) Does reading the status of the button continuously uses more energy than reading the RSSI continuously. If so I can make it keep reading the RSSI and when it reads 0 dhn it can check the button status.
I am asking this because my previous version of the program does not check the button status and works only depending on the RSSI and the current version with the button seems to discharge my battery too quickly. Please tell me how to make it more power efficient.

b) any better way to check if the phone is connected?, so to pause the program while connected AND button is not pressed. maybe using threads?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.