150 lines
5.1 KiB
Markdown
150 lines
5.1 KiB
Markdown
# Tfm Controller - little thingy that reads sensors, runs motors and communicates with the cloud
|
|
|
|
## Installation
|
|
|
|
0.
|
|
```
|
|
mkdir projects
|
|
git clone https://github.com/senaduka/tfm
|
|
```
|
|
1. Go to every subdirectory in drivers directory and follow instructions about installation of drivers
|
|
```
|
|
/home/pi/projects/tfm/controller/drivers/adafruit# cat README.md
|
|
```
|
|
2. edit controller/config/__init__.py and set your controller ID to unique number
|
|
3. configure cron to run controller.py every 15 minutes as a superuser:
|
|
|
|
```
|
|
crontab -e -u root
|
|
#enter these lines
|
|
*/5 * * * * cd /home/pi/projects/tfm/controller && sh activity.sh
|
|
*/30 * * * * /usr/bin/python /home/pi/projects/tfm/controller/network_check.py
|
|
*/1 * * * * /usr/bin/python /home/pi/projects/tfm/controller/camera_capture.py
|
|
```
|
|
|
|
4. add following lines at the end of /etc/rc.local before "exit 0"
|
|
|
|
```
|
|
python /home/pi/projects/tfm/controller/lockdown.py
|
|
python /home/pi/projects/tfm/controller/dweet.py
|
|
```
|
|
|
|
5. create directory
|
|
```
|
|
mkdir -p /mnt/zoblakdata
|
|
```
|
|
|
|
6. add following line to /etc/fstab for ramdisk
|
|
```
|
|
tmpfs /mnt/zoblakdata tmpfs nodev,nosuid,size=100M 0 0
|
|
```
|
|
|
|
7. install packages
|
|
|
|
```
|
|
sudo apt-get update
|
|
sudo apt-get install libav-tools
|
|
```
|
|
|
|
8. set timezone
|
|
|
|
```
|
|
sudo cp /usr/share/zoneinfo/Europe/Sarajevo /etc/localtime
|
|
sudo ntpd -gq
|
|
```
|
|
|
|
9. to set 3g mode
|
|
|
|
```
|
|
sudo apt-get install usb-modeswitch ppp
|
|
|
|
cd
|
|
mkdir umtskeeper
|
|
cd umtskeeper
|
|
wget "http://mintakaconciencia.net/squares/umtskeeper/src/umtskeeper.tar.gz"
|
|
tar -xzvf umtskeeper.tar.gz
|
|
chmod +x sakis3g umtskeeper
|
|
|
|
#add following line at the end of /etc/rc.local before "exit 0" (USBMODEM='12d1:1506' is a VARIABLE visible by issuing the command: lsusb):
|
|
sudo /home/pi/umtskeeper/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1506' SIM_PIN='0000' APN='CUSTOM_APN' CUSTOM_APN='active.bhmobile.ba' APN_USER='0' APN_PASS='0'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 1 --nat 'no' --sakismaxfails 20 --httpserver &>> /home/pi/umtskeeper/error.log
|
|
```
|
|
|
|
10. to set up vpn
|
|
|
|
```
|
|
install openVPN on the client
|
|
|
|
generate vpn certificate, key and config (ovpn) files on server (see STEP 3: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04)
|
|
|
|
unify the OpenVPN profile (see STEP 4: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04)
|
|
|
|
transfer them to the client (WinSCP or a similar tool, maybe need to copy the key files to another directory, "chmod 644 [filename]" for the .key file in order to transfer it - see STEP 4: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04)
|
|
|
|
edit /etc/rc.local add the line
|
|
openvpn --daemon --cd /etc/openvpn --config zoblakFarmAlarmAmirZepce01.ovpn
|
|
before "exit 0" in order to start the vpn daemon on startup, where zoblakFarmAlarmAmirZepce01.ovpn is the generated conf file
|
|
|
|
p.s. just for reference, the setting whether the client is using local or remote gw for internet access is being set for all clients in the /etc/openvpn/server.conf file on the server - comment or uncomment line ;push "redirect-gateway def1 bypass-dhcp"
|
|
```
|
|
|
|
|
|
11. to set up the hardware watchdog
|
|
```
|
|
please follow this guide (it is valid for RPI3!):
|
|
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=147501
|
|
|
|
please note that in the /etc/watchdog.conf it is sufficient to uncomment these lines:
|
|
max-load-1 = 24
|
|
watchdog-device = /dev/watchdog
|
|
|
|
furthermore, this can be added at the end o the file:
|
|
# I added the following command to get rid of a pesky error message
|
|
watchdog-timeout=15
|
|
|
|
```
|
|
|
|
12. multiple cameras support
|
|
```
|
|
as multiple cameras need to be combined and avconv does not support the appropriate functionality an additional tool must be installed
|
|
|
|
1. apt-get update
|
|
2. sudo apt-get install imagemagick
|
|
|
|
this is being used in /controller/config/__init__.py PICTURE_COMMAND when executing the "convert" command while combining multiple images
|
|
```
|
|
|
|
13. set up fixed IP addresses (rpi3):
|
|
```
|
|
Edit /etc/dhcpcd.conf as follows:-
|
|
|
|
Here is an example which configures a static address, routes and dns.
|
|
interface eth0
|
|
static ip_address=192.168.1.6/24
|
|
static routers=192.168.1.1
|
|
static domain_name_servers=192.168.1.1
|
|
|
|
interface wlan0
|
|
static ip_address=192.168.1.7/24
|
|
static routers=192.168.1.1
|
|
static domain_name_servers=192.168.1.1
|
|
```
|
|
|
|
14. set up w1 thermometer sensing
|
|
```
|
|
DS18B20
|
|
W1-thermometer sensing on RPI3
|
|
|
|
wiring schema: https://cdn-learn.adafruit.com/downloads/pdf/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.pdf (firrt schema - I used GPIO BCN #17)
|
|
edit /boot/config.txt - at the end insert (rpi2 doesn't need the gpiopin, but rpi3 does! see for more info: http://raspberrypi.stackexchange.com/questions/37157/ds18b20-no-longer-working, rpi would need only: dtoverlay=w1-gpio):
|
|
dtoverlay=w1-gpio-pullup,gpiopin=17
|
|
|
|
reboot
|
|
issue the following commands, the last directory has a variable name, based on the sensor's serial number!
|
|
sudo modprobe w1-gpio
|
|
sudo modprobe w1-therm
|
|
cd /sys/bus/w1/devices
|
|
ls
|
|
cd 28-xxxx (change this to match what serial number pops up)
|
|
cat w1_slave
|
|
```
|