Control a greenhouse by using Telegram app and a Raspberry Pi. I did not reinvent the wheel.
Thank you for inspiring me, Stefan Weigert and Felix Stern
This repository is used to gather and show information and experiences during the building of a smart control possibility. All code is written or adapted by myself and w/o any copyrights. I have tried to use no copyright protected stuff. Almost everything published already exists, to be found on the net, and was adapted and used only by me accordingly.
And please excuse the mistakes made and violations of any conventions, I am new to this matter. Do not be afraid to correct or improve me and inform me accordingly. Consider and refer Contributor Covenant Code of Conduct!
- Installation and usage
- Telegram app
- Raspberry Pi requirements
- Router port forwarding
- Required packages
- Add/create scripts
- Autostart
- Additional
- Hardware
- License
Currently no installation routine is planned. Feel free to use, adapt, download or copy all the published stuff. Main programming language is Python and shell scripting is used also.
Name: ThK1220RealGreenhouse
TOKEN: <api_token>
ChatID: <chat_id>
- download latest stretch lite w/o desktop
- prepare sd card / flash image, e.g. use Etcher
- enable SSH access
- As of the November 2016 release, Raspbian has the SSH server disabled by default. You will have to enable it manually.
- For headless setup, SSH can be enabled by placing a file named "ssh", without any extension, onto the boot partition of the SD card.
adapt /etc/dhcpcd.conf
sudo service dhcpcd status
sudo service dhcpcd start // if not yet started
sudo systemctl enable dhcpcd
sudo nano /etc/dhcpcd.conf
sudo reboot
- how-to at elektronik-kompendium (I recommend variant 2)
- also helpful, how-to for wlan
- another how-to at elektronik-kompendium
Retest and doublecheck network conection and settings before executing next steps!!!!!
sudo apt-get update --yes && sudo apt-get upgrade --yes
sudo raspi-config
Hostname: greenhouse
User: pi
Password: ******************
sudo rpi-update //update firmware
sudo reboot
sudo apt-get update
sudo apt-get install libio-socket-ssl-perl
sudo apt-get install ddclient
use e.g. FreeDNS and update ddclient.conf accordingly the dns provider
sudo nano /etc/ddclient.conf
0,5,10,15,20,25,30,35,40,45,50,55 * * * * sleep 31 ; wget -O - http://freedns.afraid.org/dynamic/update.php?******************************************** >> /tmp/freedns_greenhouse_my_to.log 2>&1 &
3,8,13,18,23,28,33,38,43,48,53,58 * * * * sleep 44 ; wget -O - http://freedns.afraid.org/dynamic/update.php?******************************************** >> /tmp/freedns_greenhouse_chickenkiller_com.log 2>&1 &
sudo apt-get install pure-ftpd
sudo groupadd ftpgroup
sudo useradd ftpuser -g ftpgroup -s /sbin/nologin -d /dev/null
sudo mkdir /home/pi/FTP
sudo chown -R ftpuser:ftpgroup /home/pi/FTP
sudo pure-pw useradd upload -u ftpuser -g ftpgroup -d /home/pi/FTP -m
sudo pure-pw mkdb
sudo ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb
sudo service pure-ftpd restart
install motion and update /etc/motion/motion.conf
sudo apt-get install motion -y
sudo nano /etc/motion/motion.conf //additional: output_pictures off
sudo nano /etc/default/motion
mkdir /home/pi/Monitor
sudo chgrp motion /home/pi/Monitor
chmod g+rwx /home/pi/Monitor
sudo service motion start
sudo apt-get install build-essential python-dev python-pip python-smbus python-openssl git --yes //python
sudo pip install python-telegram-bot
sudo pip install telepot
gpio -v
If you get something, then you have it already installed. The next step is to work out if it’s installed via a standard package or from source. If you installed it from source, then you know what you’re doing – carry on – but if it’s installed as a package, you will need to remove the package first. To do this:
sudo apt-get purge wiringpi
hash -r
WiringPi is maintained under GIT for ease of change tracking. If required to install do it like described as followed.
sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
cd git
git clone git://git.drogon.net/wiringPi
cd ~/wiringPi
git pull origin
cd ~/wiringPi
./build
Make them executable and chown root:root!
- access.py - external file, content will not provided, contains api token, chat IDs and other sensitive data
- greenhouse_config.py - settings and properties
- greenhouse.py - main bot
- lib_global.py - global constants and settings
- lib_german.py - constants, strings for descriptions and messages
- ext_greenhouse.py - extended bot
- lib_ext_greenhouse.py - constants, strings for commands and texts
- lib_english.py - English translation of German version, is set in global lib
- gpio_check.py - to check state of GPIOs and logs state, in case it is wished
- update_bot.sh - to updates all scripts from this repository by using last commit and branch
Add the program as service. To enable autostart add it to the init.d directory, insert telegrambot.sh in /etc/init.d as root and execute commands as followed.
sudo chmod +x telegrambot.sh
sudo update-rc.d telegrambot.sh defaults
sudo reboot
# update check every 10 minutes
0,10,20,30,40,50 * * * * bash /home/pi/scripts/TelegramBot/update_bot.sh <access token repository> <chat id> <api token>
# update check every hour
0 * * * * bash /home/pi/scripts/TelegramBot/update_bot.sh <access token repository> <chat id> <api token>
# backup bot every day at 1:30AM
30 1 * * * tar -zcf /home/pi/backups/greenhouse.tgz --exclude='*.pyc' /home/pi/scripts/TelegramBot/
# also move log backups to backup folder
31 1 * * * mv -v /*.gz /home/pi/backups/
sudo nano /etc/logrotate.conf
/update_bot.log {
missingok
daily
rotate 1
compress
dateext
create 644 root root
}
/greenhouse.log {
missingok
daily
rotate 1
compress
dateext
create 644 root root
}