Creating a Factory Reset Daemon for SUSI.AI Smart Speaker

In our constantly evolving SUSI.AI Smart Speaker project, we require regular updates for our devices. And imagine a scenario that during a crucial update, there is a crash or an internet disconnection which stops the SUSI.AI Linux program from booting up. We’ll require a reset method for that. So, we have added a button in SUSI smart speaker that works as a factory reset switch. This daemon was accomplished by using python scripting, bash scripting, and Raspbian’s systemd rules.

Approach followed

We have created a python script that detects the button presses on GPIO port 17. The script is run as soon as the Raspberry Pi is booted using the systemd rules and checks for the device inputs. And if the button press is for more than 7 seconds, the factory_reset.sh script is run which deletes all the contents of the repo and clones it again.

 

#! /bin/bash
# To be executed using a physical button

SCRIPT_PATH=$(realpath $0)
DIR_PATH=$(dirname $SCRIPT_PATH)

cd $DIR_PATH/../..
pwd
mv susi_linux/ susi_temp
git clone https://github.com/fossasia/susi_linux #while testing change to personal repo
pwd
ls
cd susi_linux

rm -rf ../susi_temp

./install.sh

 

Detecting the Button Press

We have Used the library RPi.GPIO to detect button click on raspberry Pi.

while True:
       if GPIO.input(17) == 1:
           pass
       elif GPIO.input(17) == 0 :
           start = time.time()
          while GPIO.input(17) == 0 :
               print(“on”)
               time.sleep(0.1)
          end = time.time()
           total = end – start
           if total >= 7 :
              subprocess.call([‘bash’,‘factory_reset.sh’])
          else :
               mixer = alsaaudio.Mixer()
               value = mixer.getvolume()[0]
              if value != 0:
                  mixer.setvolume(0)
               else:
                   mixer.setvolume(50)
           print(total)
           time.sleep(0.1)

 

If the button press is greater than 7 seconds, factory reset process will start and if the press is less than 7 seconds, the button will function as mute button

 

Auto Booting The program

 

For the script to autorun everytime the raspberry pi started. We create systemd file which will allow the program to start as soon as the device has started

 

[Unit]
Description=SUSI Linux Factory Daemon
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/SUSI.AI/susi_linux/factory_reset/factory_reset.py

[Install]
WantedBy=multi-user.target

 

This runs the factory reset script to boot up as soon as the Raspberry Pi starts

References

Tags

susi, factory_daemon, factory_reset, gsoc, gsoc’18,susi_linux , fossasia

Continue ReadingCreating a Factory Reset Daemon for SUSI.AI Smart Speaker