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]
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 else: del devs #removes the first element device_list =  for dev in devs: device_list.append(dev[1:18]) if check_dev: if check_dev in device_list: return True else: return False else: return device_list while get_connected_devices(phone.mac): if button.is_pressed and phone.read_rssi(): while True: if phone.rssi >= 0: relay.power_on() #conditions to turn off the relay elif phone.n_signal >= true_max_n_count or phone.rssi < phone.away_threshold: relay.power_off() sleep(rssi_interval) break if not phone.read_rssi(): if not get_connected_devices(phone.mac): print "phone disconnected" relay.power_off() break sleep(rssi_interval) continue sleep(button_check_interval)
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
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?