Coder Social home page Coder Social logo

societa-astronomica-g-v-schiaparelli / dew_heater_bands_controller Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 13 KB

DIY dew heater bands controller

License: MIT License

Python 47.45% JavaScript 21.06% HTML 6.10% CSS 25.39%
astronomical-algorithms astronomy astronomy-instrumentation astronomy-software python python3 raspberry-pi

dew_heater_bands_controller's Introduction

dew_heater_bands_controller

DIY dew heater bands controller.

Project description

The controller is a python script meant to run on an RPi and use GPIOs to control a relay board with two outputs. The two relays are connected to two custom dew heater bands (DIY, see here, one for the main telescope and one for the guide telescope) and control their powering.

The relays can be controlled in two ways:

  • Automatic (default): bands are controlled automatically, based on the time of sunrise/sunset and on the weather conditions.

  • Manual: bands are manually controlled by the operator through network requests or using the appropriate web page.

You can interact using:

  • Web page, route /.
  • API, route /api.

Code structure

The code is completely asynchronous and consists of two parts:

  • Web server, developed with the aiohttp library, by default active on port 8001; server-sent events implemented with the aiohttp-sse library.

  • Updater for the management of the bands, executed every five minutes. The behavior is based both on the time of sunrise and sunset of the Sun (through the skyfield library) and on the weather conditions (through the usage of data from the weather station at the observatory). Thresholds are set to better manage the switches. The bands management is done with the gpiozero library.

API description

The APIs are accessible through http GET requests such as:

/api?json={"cmd":"command"}

Changing the setting of the bands

/api?json={"cmd":"set","params":{"auto":value,"telescope":{"main":value,"guide":value}}}

Replace value with true or false, depending on the desired configuration. All parameters and subparameters of the params key are optional.

Reply:

  • done in case of successful request;
  • a message indicating the type of error encountered.

Examples:

  • Deactivate automatic mode and activate both bands:

    /api?json={"cmd":"set","params":{"auto":false,"telescope":{"main":true,"guide":true}}}
    
    {"rsp": "done"}
    

    or only one band:

    /api?json={"cmd":"set","params":{"auto":false,"telescope":{"main":true}}}
    
    {"rsp": "done"}
    
  • Attempt to manually activate a band while automatic mode is active:

    /api?json={"cmd":"set","params":{"telescope":{"main":true}}}
    
    {"rsp": "Error: controller in automatic mode"}
    

Status of the bands

/api?json={"cmd":"status"}
{
  "rsp": {
    "auto": false | true,
    "telescope": {
      "main": false | true,
      "guide": false | true
    }
  }
}

SSE API description

For periodic status fetching, it's recommended to use the server-sent events (SSE) API. It's way more efficient, since the server will push an update to the client only if there is a change in the status.

/status-sse

Each message sent by this API is the same as the response of the normal status API.

Personalization

Get meteo data for the dew point value

The code uses the dew point to automatically manage the bands; however, the dew point depends on the observing site location. The controller uses the data from the weather station at our observatory, but if you want to use your own data, fill the following template and replace the original code in the DewHeaterHandler class.

async def _get_meteo_data(self) -> tuple[float]:
    """ Function to get temperature and humidity at the telescope location. """
    # implement here your code to retrive weather parameters
    ...
    # then return temperature and humidity
    return temperature, humidity

Site location

Change also your site location in the DewHeaterHandler instantiation.

updater = DewHeaterHandler(relays, site_latitude, site_longitude, site_altitude)

Prerequisites, installation and detail of the implementation in Mascioni dome

Tested on Raspberry Pi 4 with Ubuntu Server 20.04 and Ubuntu Server 22.04.

Install the following packages:

sudo apt install python3.11 python3.11-venv python3.11-dev

Create a virtual environment in the dew_heater_bands_controller folder and install the necessary packages:

python3.11 -m venv venv
source venv/bin/activate
pip3 install wheel
pip3 install -r requirements.txt

Service to automatically start the code (modify the paths and user according to what you need) to put in the path /etc/systemd/system/dew_heater.service:

[Unit]
Description=DIY dew heater bands controller

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/dew_heater_bands_controller
ExecStart=/home/ubuntu/dew_heater_bands_controller/venv/bin/python3 /home/ubuntu/dew_heater_bands_controller/dew_heater.py
Restart=always
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

Enable with:

sudo systemctl enable --now dew_heater.service

dew_heater_bands_controller's People

Contributors

paolo97gll avatar

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.