Skip to content

ModnarUser/MyAussenlicht

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyAussenlicht

Compile Firmware with Arduino CLI Python application Generate TOC

MyAussenlicht is an ESP2866 based remote control for an outdoor light. A simple server running on the ESP2866, that can be accessed via your local network, is utilized. Two use cases are supported:

  • Manual Remote Control
  • Automated Remote Control with Sunrise and Sunset

Table of Contents


1. Requirements

  • Arduino IDE
  • WROOM-32 ESP2866 Dev kit
  • ESP-Arduino Lib
  • ESP Board Files

2. Build and Run

Start the Arduino IDE and make sure you have the latest ESP-Lib installed:

ESP-Lib

Next, navigate to the board manager in the Arduino IDE and install the esp8266 library:

ESP-Lib

Open the MyAussenlicht.ino-file in the Embedded directory and replace the SSID and password in the following lines with your SSID and password:

#ifndef STASSID
#define STASSID "YOUR_SSID"
#define STAPSK  "YOUR_PW"
#endif

Choose the LOLIN(WEMOS) D1 R2 & mini board, connect your board via USB, select the correct COM-port, and press upload to board.

Upon bootup the ESP-module will attempt to connect to the specified WiFi network:

Connecting to 
YOUR_WIFI_NAME
Connecting to WiFi
Sent SSID and PW...
................
WiFi connected
Server started
192.168.178.XX

3. Manual Remote Control

Grab a device already connected to your local network and access the IP address from above (192.168.178.XX).

Landing Page For Remote Control

Now you can toggle the Aussenlicht by simply pressing the ON or OFF button.

4. Automated Remote Control

With the python file MyAussenlichtTimer.py in the Python directory you can automatically switch the Aussenlicht with sunrise and sunset. By default, the outdoor light will be switched on upon sunset and switched off at midnight.

4.1 Requirements

  • Machine that is permanently connected to your local Network (e.g. Raspberry Pi, NAS, etc.)
  • At least Python 3.6

4.2 Running It

Before using it with your Aussenlicht you will have to edit the properties of the AussenlichtConfig in the MyAussenlichtTimer.py file.

class AussenlichtConfig():
    AUSSENLICHT_URL = "http://192.168.178.XX" # Enter the URL of your ESP server 
    LATITUDE = 50.0212981 # Enter the latitude of your geo-location
    LONGITUDE = 9.2554408 # Enter the longitude of your geo-location

Next, you can execute it.

cd Python
python MyAussenlichtTimer.py

The plot below shows the output of running MyAussenlichtTimer.py concurrently every 5 minutes. Automated Switching of the Aussenlicht with Sunrise and Sunset

4.3 Example Setup using a QNAP2

4.3.1 Container Setup

Log into your qnap2 via a browser of your choice.

qnap url

Install the Container Station from the AppCenter and setup a Ubuntu 18.0 container according to these instructions. Once the container is setup, launch a shell inside it and set a password for the ubuntu user.

passwd ubuntu

Next, install the following packages.

sudo apt update && sudo apt upgrade
sudo apt install wget unzip python3-pip nano python3

4.3.2 Pull Source Code

Pull this repo from GitHub and unzip it.

cd /home/ubuntu
mkdir myapps && cd myapps
wget https://github.com/ModnarUser/MyAussenlicht/archive/refs/heads/master.zip
unzip master.zip
sudo rm -rf master.zip
cd MyAussenlicht-master/Python

Install the utilized Python libraries and make MyAussenlichtTimer.py executable.

python3 -m pip install -r requirements.txt
chmod +x MyAussenlichtTimer.py

4.3.3 Crontab

Note: depending on your local setup it might be sufficient to edit the user crontab. If this does not work however, you have to additionally edit the system wide crontab.

A) User Crontab

Write the currently running cronjobs to a file.

sudo crontab -l > cronfile

Open the file with nano cronfile and add the following line:

*/4 * * * * /usr/bin/python3 /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.py >> /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.log

Pass the edited cronfile to crontab in order to run the MyAussenlichtTimer.py concurrently.

sudo crontab cronfile

Finally, you can check if the cronjob was successfully added with sudo cronjob -l.

B) System Wide Crontab

Open the system wide crontab at /etc/crontab

sudo nano /etc/crontab

Write the following line to the end of the file.

*/4 * * * * ubuntu /usr/bin/python3 /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.py >> /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.log

4.3.4 Debugging

A) Logfile

The cronjobs will write logging information to the MyAussenlichtTimer.log file. You can check if the MyAussenlichtTimer is running as intended by printing the content of the file to stdout.

cat /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.log

Which will print something like this:

Connection to http://192.168.178.XX successful!                                                                                                                                                                                                                                                        
now: 2021-05-01 10:32:02.210094+00:00    last_midnight: 2021-05-01 00:01:00+00:00        midnight: 2021-05-01 23:59:00+00:00     sunrise: 2021-05-01 04:00:00+00:00                      sunset: 2021-05-01 18:41:00+00:00                                                                             
Außenlicht OFF    

B) Get System Time

date "+%H:%M:%S   %d/%m/%y"

C) Print Syslog

sudo grep CRON /var/log/syslog

4.4 Testing

Install all python requirements via

pip install -r requirements.txt

Modify the TEST_URL in test_MyAussenlichtTimer.py to fit your server URL.

################################################################
# Test Settings
################################################################

TEST_URL = "http://192.168.178.XX"  # Use URL of your Aussenlicht

Navigate into the toplevel Python directory (*/MyAussenlicht/Python) and run the tests.

pytest test_MyAussenlichtTimer.py

When all tests were run successfully you should get the following output:

==================== test session starts =====================
platform linux -- Python 3.8.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /data/data/com.termux/files/home/Documents/gitrepos/MyAussenlicht
collected 7 items

test_MyAussenlichtTimer.py .......                     [100%]

===================== 7 passed in 46.44s =====================

About

An ESP2866 Based Remote Control for an Aussenlicht

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •