Git Product home page Git Product logo

sunnesiite's Introduction

sunnesiite

A Python flask and Arduino project for receiving SolarAPI current data in the flask app, saving it into VictoriaMetrics, and then generating a PNG graph from a VictoriaMetrics query showing the daily solar production, and a Inkplate 6COLOR Arduino sketch to fetch and display this PNG periodically

Usage

ESP32

Drop a config.h with contents like this next to the .ino, replace the values with whatever is the case for you:

#define WIFI_SSID "YourSSID"
#define WIFI_PASSWORD "hunter2"
#define EINK_URL "http://example.example/eink.png"
#define API_URL "http://example.example/untildaytime"
#define TIMEZONE "Europe/Zurich"

The default refresh interval is every 4 minutes between 6:00 and 22:00.

You'll need to install ArduinoJson (not Arduino_Json!) from the libraries manager.

Flask

You'll need Python 3.9 or later.

Create a virtualenv and activate it:

$ cd flask
$ virtualenv venv
$ source venv/bin/activate

Then install the package in editable mode:

$ pip install -e .

Next, you'll want to create an instance/config.toml in your flask directory, with contents like:

# Keep this secret, keep this safe. Auto-generate it from a cryptographically
# secure random source, e.g. pwgen -s 64 1
SECRET_KEY = "hunter2"
# Prefix for all the endpoint URLs
SUNNESIITE_PREFIX = ""
# This one needs to be the API key your solarapi push service on the inverter
# uses, make it long, random and secret as well. Anyone who has it can fill
# your time series database with data!
SUNNESIITE_API_KEY = "hunter2"
# URI for your VictoriaMetrics server, as-is if running locally with default
# port
SUNNESIITE_VM_URI = "http://127.0.0.1:8428"
# Change for deployments to something better, see Flask-Caching documentation
CACHE_TYPE = "SimpleCache"
CACHE_DEFAULT_TIMEOUT = 120

You can now run the app in development mode:

$ flask --app sunnesiite run --port yourport -h yourip

If you don't specify yourip here, the development server will only listen to local connections, which means your Inkplate 6COLOR won't be able to fetch from it.

Deploying To Production

If you want to deploy this in production, you'll need something like uwsgi.

You'll want to pip install --no-binary pyuwsgi pyuwsgi (see Flask's documentation for oher ways) and then use the wsgi stub script to launch the app, like this:

$ uwsgi --http-socket 127.0.0.1:8000 --master -p $(nproc) -w wsgi:app

It's a good idea to make your services actual systemd services, so use an unit file like this (adjust as appropriate):

[Unit]
Description=Sunnesiite Flask Component
After=network.target

[Service]
DynamicUser=true
LogsDirectory=sunnesiite-flask
StateDirectory=sunnesiite-flask

AmbientCapabilities=
CapabilityBoundingSet=
LockPersonality=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true

User=sunnesiite-flask
Group=sunnesiite-flask
ExecStart=/path/to/your/venv/bin/uwsgi --http-socket 127.0.0.1:8000 --master -p 8 -w wsgi:app -H /path/to/your/venv/
WorkingDirectory=/path/to/sunnesiite/flask/
Environment="PATH=/path/to/your/venv/bin"

[Install]
WantedBy=multi-user.target

Then throw this behind e.g. an nginx reverse proxy.

For VictoriaMetrics, I'd make doubly sure it only listens to connections from localhost, unless you are explicitly trying to use a remote VictoriaMetrics server and have auth stuff figured out (I don't).

Please note that Fronius inverters seemingly only support pushing through plain text HTTP, not HTTPS. This will mean that your reverse proxy should accept connections on plain text HTTP and serve the web app there, not try to redirect to HTTPS.

sunnesiite's People

Contributors

counterpillow avatar

Watchers

 avatar  avatar

sunnesiite's Issues

ESP32: Handle error conditions

The ESP32 code should handle the following error conditions:

  • Connecting to Wi-Fi failed
  • HTTP request for eink.png returned an error code, or otherwise failed

Use sunrise/sunset times for untildaytime calculations

Right now, the untildaytime endpoint uses a fixed 6:00 to 22:00 interval in the supplied timezone for daytime. We could save a lot more energy outside of summer if we used actual sunrise and sunset times.

This is best done using a library for these calculations and having the esp32 client submit lat/lng coordinates to aid with it.

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.