Skip to content
This repository was archived by the owner on Jan 27, 2024. It is now read-only.
mike7seven edited this page Jul 6, 2018 · 47 revisions

presence-bot

Presence is a slack bot that tells you who is in the office. Park it on a raspberry pi, hide it in a cupboard.

Setup

Step 1: Install the necessary software first:

sudo apt-get update - update distribution to latest
sudo apt-get upgrade - upgrade distribution to latest
sudo apt-get install arp-scan - install arp-scan package
sudo apt-get install mysql-server - install mysql server
sudo apt-get install php7.0-mysql - install mysql for php7
sudo apt-get install curl - install curl 
sudo apt-get install php7.0-curl - install curl module for php7
sudo apt-get install libapache2-mod-php7.0 - install Module for php7 

Install php7:

sudo su

echo "deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free" >> /etc/apt/sources.list

echo "#deb-src http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free" >> /etc/apt/sources.list

apt-get install php7.0 

apt-get install php7.0-opcache - this may already be installed

type exit and hit enter

Step 2: Create a database and root database user

mysql -uroot -p
now enter a password for the root user for the database
create database presence;
exit

Step 3: Clone repository locally

git clone https://github.com/Denhac/presence-bot
(You may need to install git using the command "sudo apt-get install git")

Step 4: Install mbstring and composer

Install mbstring first

sudo apt-get install php7.0-mbstring

curl -sS https://getcomposer.org/installer | php

sudo mv composer.phar /usr/local/bin/composer

Run composer in the presence-bot directory

composer install

Composer update after installation

composer update

root@raspberrypi:/home/pi/presence-bot# ls
 composer.json  composer.lock  composer.phar  LICENSE  presence	README.md  src	vendor

Step 5: Create a .env file

      cd presence-bot/

      sudo nano .env

      DB_HOST=localhost
      DB_NAME=presence
      DB_USERNAME=
      DB_PASSWORD=
      BOT_TOKEN=
      SUPPORT_EMAIL=

Step 6: Cron Task Setup

Set up a minutely cron task under root that runs php presence scan. sudo crontab -e

Add in this line at the end.

@reboot cd /home/pi/presence-bot/ && php presence bot 1 * * * * /home/pi/presence-bot/ php presence scan

The command php presence bot will start up the bot, it needs root permission to do the arp scan, so either sudo or use root. Make sure you have a valid token from here https://www.slack.com/apps/A0F7YS25R-bots Verify the bot works via @presence help

Step 7: Starting the bot

Run the command **php presence bot** to start the bot

Step 8: Create SystemD and start File

 [Unit]
 Description=Presence Service
 [Service]
 ExecStart=/usr/bin/php /home/pi/presence-bot/presence bot
 Restart=always
 RestartSec=3
 StandardOutput=syslog
 StandardError=syslog
 SyslogIdentifier=Presence Service
 User=root
 Group=root
 [Install]
 WantedBy=multi-user.target

Step 9: Start the bot

 sudo php presence bot will start up the bot

Commands to enable the service

 $ sudo systemctl enable 

 $ sudo systemctl stop  

 $ sudo systemctl disable  

 $ sudo systemctl daemon-reload 

 $ sudo systemctl start 

bot commands

the bot is triggered via presence or @{thbotsusername}

  • register xx:xx:xx:xx:xx:xx to associate yourself with a mac address
  • remove xx:xx:xx:xx:xx:xx to undo previous association
  • who is here, whoishere, who's here I'll let you know who is in the house
  • top x listing of the most active users 1-10
  • whoami tells you what devices are registered to you.

possible things to do

  • A command that tells you when a user was there the last time (e.g: mawk was seen 3 days ago)
  • Bot can see a user connected that wasn't there earlier and send an announcement (mawk arrived!)
  • Assign labels to each device of yours.
  • Register devices so they are ignored (other pis, printers etc...)
  • Suggestions? create an issue!
Clone this wiki locally