Skip to content

Commit

Permalink
Full RaspiControl bot
Browse files Browse the repository at this point in the history
  • Loading branch information
T1mS22 committed Jun 3, 2022
0 parents commit 907e3fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
token.txt
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RaspiControl-Bot
Recieve status data from your RaspberryPi via a Telegram Bot.

## How to use:

Create a now bot via the @BotFather on Telegram and copy the token.

Clone this repository onto your RaspberryPi.
In this folder, create a file named "token.txt" and paste your bot token into it.
You also have to open your terminal and install:
`pip install gpiozero` and `pip install python-telegram-bot`
Now run the `raspicontrol.py` script.
37 changes: 37 additions & 0 deletions raspicontrol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import telegram.ext
from gpiozero import CPUTemperature

with open('token.txt', 'r') as f:
TOKEN = f.read()

cpu = CPUTemperature()

def start(update):
update.message.replay_text("Hey! Welcome to RaspiControl. I'm a bot that can send you status data about your Raspberry Pi.")

def help(update):
update.message.replay_text("""
The following commands are avaiable:
/start -> Welcome Message
/help -> This Message
/temp -> Current CPU temperature
/contact -> Information about the developer
""")

def temp(update):
update.message.replay_text("The current CPU temperature is: " + cpu.temperature)

def contact(update):
update.message.replay_text("More about Tim: https://t1ms22.github.io")

updater = telegram.ext.updater(TOKEN)
disp = updater.dispatcher

disp.add_handler(telegram.ext.CommandHandler("start", start))
disp.add_handler(telegram.ext.CommandHandler("help ", help))
disp.add_handler(telegram.ext.CommandHandler("temp", temp))
disp.add_handler(telegram.ext.CommandHandler("contact", contact))

updater.start_polling()
updater.idle()

0 comments on commit 907e3fb

Please sign in to comment.