Get Informed out of Data

Full width home advertisement

Raspbian

DataScience

Post Page Advertisement [Top]

ESP32 - Raspberry Pi - Telegram - for Home Automation

ESP32 - Raspberry Pi - Telegram - for Home Automation
Getting Started

These steps will take you through getting your own project up and running. This will take you through getting Mosquitto, NodeRED, and ESP32 to control light. 

Prerequisites

The software used is free and mostly open source. All will be explained here!
It would help to have the hardware below.

Mosquitto

The Mosquitto broker will be installed on your Raspberry Pi for the MQTT protocol to work.
Navigate to the terminal and follow these steps

  1. Update your Raspberry Pi
    sudo apt-get update
  2. Install Mosquitto
    sudo apt-get install mosquitto
  3. Install Mosquitto Client
    sudo apt-get install mosquitto-clients

    Find the importance of MQTT Protocol it is very simple and easy to use. 

Node-red

You will need NodeRED to be installed on your Raspberry Pi. To do so follow these steps.
The only flow that is required to start controlling an ESP32 is the ESP32 MQTT flow. 

ESP-IDF

  1. Setup Toolchain
  2. Get ESP-IDF Besides the toolchain (that contains programs to compile and build the application), you also need ESP32 specific API / libraries. cd ~/esp git clone --recursive https://github.com/espressif/esp-idf.git
  3. Setup Path to ESP-IDF The toolchain programs access ESP-IDF using IDF_PATH environment variable. This variable should be set up on your PC, otherwise projects will not build.
  4. Install Required Python Packages python -m pip install --user -r $IDF_PATH/requirements.txt
  5. Export the path export IDF_PATH=~/esp/esp-idf export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin ‡:Check the official site for more info.
  6. Clone my ESP32 MQTT Light Control repository git clone -b --recursive https://github.com/Alextros00/Home-Automation-NodeRED-ESP-Telegram/ESP32

Configuration

Plug in your ESP32 to your laptop. cd into the project directory. If you are having a hard time finding it use ls to list the files and directories within a folder Use make menuconfig in the commmand line. It may take a minute to load. 

Go to Serial flasher config, then Default serial port and set the port in which your ESP32 is connected Your serial port can be found using this guide

One problem I had was that it is not clearly documented that if using windows the port should be configured in the COMX 

for example, COM0 Set the Default baud rate to 115200 baud for the ESP32 Click Save -> Ok -> Exit -> Exit to get back to the main configuration screen Go to Example Configuration - Set WiFI SSID and WiFi password to that of your local 2.4GHz network - Set Broker URL to your mqtt server:port. It will look something like mqtt://@192.168.1.142:1883)

 if you have no username and password configured for Mosquitto - Enter the ESP32-X Number that you are using. This can be left blank and has no impact on the functionality of the code besides messages sent. - Enter the Relay GPIO Number or the GPIO that will control the relay. 

What pin you can use can be found on your device specific pinout. - Select enter 1 or 2 to decide between subscribing to 1 or 2 relay. Default is 1. - Set the MQTT Topic to Subscribe To or recieve messages from - Set the 2nd MQTT Topic to Subscribe To

Can be left alone if not using. - Set the MQTT Topic to Publish To or send messages to Once done configuring the project exit out of the menu by clicking Save -> Ok -> Exit -> Exit -> Exit to go back to the terminal

Flash and Monitor

Use make flash to build and flash the project onto your device. Once the project has been flashed onto your device use make monitor to see logs from the device in real time To exit the monitor us Ctrl + ] or Ctrl and ] at the same time

Telegram

Telegram adds the ability to control the system from your phone but is not required for use. You could stricktly use the NodeRED dashboard to control your system. In this implementation, Telegram does not directly control any devices but rather goes through NodeRED using the node-red-contrib-telegrambot library.

Commands

  • /water - records that I drank a bottle of water
  • /poop - records that I took a poop
  • /piss - records that I took a pee
  • /whoishome - replys with who is on my home wifi
  • /alive - replys with what devices are responding on the system
  • /doorlighton - turns on the light by the door
  • /doorlightoff - turns off the light by the door
  • /bedsidelampon - turns on the light by my bed
  • /bedsidelampoff - turns off the light by my bed
  • /sleepin - delays the auto turn on of my lights by 30 minutes, twice will do an hour, 3 times no effect


No comments:

Post a Comment

Bottom Ad [Post Page]