Code Monkey home page Code Monkey logo

raspy-temperature-bot's Introduction

raspy-temperature-bot

Note: This project is currently not maintained.

This is a telegram bot hosted by a Raspberry Pi equipped with a temperature and humidity sensor. The bot is capable of sending plots and readings.

graph example

Structure

This project is composed of 3 main files:

  • bot.py is used to host the telegram bot.
  • graph.py contains the Graph class, used to make graphs.
  • sensor.py contains the TemperatureSensor class, used to write and read from the sqlite3 database, as well as the function that reads the temperature and humidity values from the sensor.

bot.py will call both the Graph and TemperatureSensor classes.

Installation

Dependencies

Raspberry Pi setup

To make this project i used a Raspberry Pi Zero W with an AM2302 temperature and humidity sensor.

The humidity sensor has 3 pins:

  • DATA, connected to the GPIO 4 port, it sends the readings to the Raspberry Pi.
  • GROUND, connected to one of the ground ports.
  • VCC, connected to one of the 5V ports.

gpio pinout

Once your sensor is connected to your Raspberry Pi, go ahead and proceed to install a clean version of Raspberry Pi OS Lite.

raspy-temperature-bot installation

To install raspy-temperature-bot:

  1. Ssh into your Raspberry Pi
  1. Clone the repository
git clone https://github.com/Kirgnition/raspy-temperature-bot.git
  1. cd into the repository and install the requirements.
cd ./raspy-temperature-bot
pip3 install -r ./requirements.txt
  1. Paste your bot token in the TOKEN.py file.

  2. Create a service for the temperature sensor:

    1. Create a file called temperature_sensor.service:

      sudo nano /etc/systemd/system/temperature_sensor.service
    2. Paste the following:

      [Unit]
      Description=ROT13 demo service
      After=network.target
      StartLimitIntervalSec=0
      
      [Service]
      Type=simple
      Restart=always
      RestartSec=1
      User=username
      ExecStart=python3 /path/to/sensor.py
      
      [Install]
      WantedBy=multi-user.target
      

      Set your username after User= and the path to sensor.py after ExecStart=.

    3. Enable the service by issuing on the terminal:

      systemctl start temperature_sensor.service
      systemctl enable temperature_sensor.service

      From the moment you start the service a reading will be taken by the sensor every 5 minutes and saved in a sqlite3 database.

  3. Create a service for the telegram bot in an analogous way.

Your bot should be now active, in case of restart both the bot and the sensor will start automatically.

Usage

Once the bot is installed and running, send the /start command on telegram to receive the list of available commands.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

raspy-temperature-bot's People

Contributors

kirkbuah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

annihilatorrrr

raspy-temperature-bot's Issues

'generator' object is not subscriptable

Hi, in the log-file I get some TypeErrors, for example:

File "/home/wjmb/raspy-temperature-bot/graph.py", line 50, in make_graph
    datemin = dates[0]
TypeError: 'generator' object is not subscriptable

or:

File "/home/wjmb/raspy-temperature-bot/bot.py", line 53, in last_readings
    timestr = data.dates[0].datetime.strftime('%Y/%m/%d at %H:%M')
TypeError: 'generator' object is not subscriptable

This is on a RPI4, Python version 3.9.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.