https://github.com/antoniond/led-bot
Scripts to control a Unicorn HAT remotely with Telegram or from a website
https://github.com/antoniond/led-bot
Last synced: about 1 month ago
JSON representation
Scripts to control a Unicorn HAT remotely with Telegram or from a website
- Host: GitHub
- URL: https://github.com/antoniond/led-bot
- Owner: AntonioND
- License: mit
- Created: 2020-05-13T23:31:38.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-14T23:42:03.000Z (almost 5 years ago)
- Last Synced: 2025-04-03T19:16:06.540Z (about 1 month ago)
- Language: Python
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Smart LED lamp (Raspberry Pi + Unicorn HAT)
===========================================This repository contains a Telegram bot and a HTML server that can be used to
remotely control the lights of a `Unicorn HAT`_ connected to a Raspberry Pi.This is a video that shows it in action:
https://www.youtube.com/watch?v=xjQCvFdkGJw
Both the Telegram bot and the HTML server can control the lights and don't need
the other one. If you don't want one of them, edit the file ``restart.sh`` to
remove the one you don't need.In order to run the code in this repository, you need to install the following
dependencies:.. code:: bash
sudo apt install python3-pip python3-dev
sudo pip3 install unicornhatThere are 3 main parts:
- **LED server**: Script that has to be run with root permissions. It listens to
connections to a specific port and affects the LEDs. It can also reboot or
shutdown your Raspberry Pi.- **Telegram bot**: Telegram bot that runs with regular user permissions. It can
send commands to the LED server.- **HTML server**: HTML server that sets up a website with some buttons that can
be used to control the LEDs. It sends commands to the LED server.Note that you don't need the Telegram bot and HTML server at the same time. Just
one is enough. Also, any program that connects to the right port can send the
same commands to the LED server.Start scripts
-------------Open ``restart.sh`` and edit as needed following the instructions. You can
choose to disable specific modules, and you have to set the right path to the
code in your case. Note that this script must run as root.HTML server
-----------The dependency needed for the server is `Flask`_:
.. code:: bash
pip3 install flask
The server runs on port 5000. All you need to do to open the website is to know
the IP address of your Raspberry Pi (with ``hostname -I``, for example). Then,
supposing that your IP address is 192.168.1.42, open your web browser and go to
``http://192.168.1.42:5000``.Telegram bot
------------The dependency needed for the server is `Telepot`_. Unfortunately, this library
is now discontinued, but I created this bot back when it was being maintained.
Eventually it will probably stop working... code:: bash
pip3 install telepot
You need to follow the instructions here to create your own Telegram bot and
`get a token`_.You also need to edit the file ``telegram/secrets.py``:
.. code:: python
MY_USERNAME = 'sampleroot'
MY_USER_ID = 12345678
TOKEN = '123456789:ABCDEFGHIJ-abcdefghijklmnopqrstuvwx'The values are:
- ``MY_USERNAME``: Name of the username that acts as owner of the bot
- ``MY_USER_ID``: Telegram user ID. You can use the bot @userinfobot to get it.
- ``TOKEN``: Token obtained in the link above.Rename the folder ``telegram/users/sampleroot`` to your chosen user name. Then,
edit the file ``pass`` inside it. Yes, it is plain text.Now, open a chat window with your bot, and do ``/user login sampleroot pass``.
You can send commands to the LED server with commands such ``/led rainbow``. You
can try ``/led help`` for more information.Start at boot
-------------You can also edit your ``/etc/crontab`` file (you need root permissions) if
you want to run the scripts at boot automatically. Just add the following
lines at the end (replacing the path by the right one in your case):.. code:: bash
# Restart LED scripts every day at 11:00 A.M.
0 11 * * * root /home/pi/led-bot/restart.sh# Start LED scripts at boot
@reboot root /home/pi/led-bot/restart.shContact
-------You can contact me at antonio_nd at outlook com.
Website: http://www.skylyrac.net/
GitHub: https://github.com/AntonioND
Copyright (c) 2020, Antonio Niño Díaz
.. _Unicorn HAT: https://github.com/pimoroni/unicorn-hat
.. _Flask: https://flask.palletsprojects.com/
.. _Telepot: https://github.com/nickoala/telepot
.. _get a token: https://telepot.readthedocs.io/en/latest/#id5