GithubHelp home page GithubHelp logo

gt3ch1 / sqlsprinkler-cli Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 250 KB

A command line tool for controlling a simple sprinkler system made out of a raspberry pi and a relay board.

License: MIT License

Rust 95.15% Makefile 4.12% Shell 0.73%
assistant cli home sprinkler system home-assistant homeassistant-integration pi raspberry sprinklersystem

sqlsprinkler-cli's Introduction

sqlsprinkler-cli

v0.1.6

A command line interface for the SQLSprinkler project, made specifically for the raspberry pi.

Authors & Contributors

  • Gavin Pease

Building

  • Dependencies

After installing the build dependencies, you can run make deb to create a .deb package, you can then install it with sudo dpkg -i sqlsprinkler-cli_0.1.6_armhf.deb.

Installing

  • To install, please run # make install. This will install the binary to /usr/bin/sqlsprinkler-cli.
    • Running this command should generate a binary that will work across all raspberry pi's.

Usage

sqlsprinkler-cli allows control over a SQLSprinkler endpoint via a unified program.

  • sqlsprinkler-cli
    • Prints out help & version information
  • sqlsprinkler-cli --daemon, sqlsprinkler -w
    • Starts the SQLSprinkler daemon on port 3030.
  • sqlsprinkler-cli zone <id> <on,off,status>
    • Turn the given zone on or off
  • sqlsprinkler-cli zone add <name> <gpio> <time> <enabled> <auto off>
    • Add a zone to the system.
  • sqlsprinkler-cli zone delete <id>
    • Delete a zone from the system.
  • sqlsprinkler-cli zone modify <id> <name> <gpio> <time> <enabled> <auto off>
    • Modifys a zone in the system.
  • sqlsprinkler-cli sys <on,off,winterize,run,status>
    • Operate on the system.
  • sqlsprinkler-cli -m
    • Starts the SQLSprinkler MQTT listener for home assistant integration.
  • You can set the database username, password, and host in the /etc/sqlsprinkler/sqlsprinkler.conf configuration file.

TODO

  • Create tables and databases if they do not exist.
  • A and B days
  • Make sqlsprinkler zone ... call the Web API to control turning zones on and off.
  • Better error messages

Features added

  • A configuration file at /etc/sqlsprinkler/sqlsprinkler.conf
  • sqlsprinkler-cli sys test
  • sqlsprinkler-cli sys run
  • sqlsprinkler-cli zone <id> <on,off,status>
  • sqlsprinkler-cli sys <on,off>
  • SQLSprinkler web api
    • Please see the API Documentation for more information.
      • Get system schedule status → GET /system/status
      • Update system schedule status → PUT /system/status {"system_status": status}
      • Get all zones status → GET /zone/info
      • Get single zone status → GET /zone/info/<id>
      • Toggle zone → PUT /zone{"id": id, "state": state}
      • Update zone information → PUT /zone/info{ "Name": "Rust-Zone 123", "GPIO": 12, "Time": 10, "Autooff": true, "Enabled": true, "SystemOrder": 1, "id": 4 }
      • Create zone → POST /zone{ "Name": "Rust-Zone", "Gpio": 12, "Time": 10, "Autooff": true, "Enabled": true }
      • Delete zone → DELETE /zone{ "id": 1 }
      • Change zone ordering → PUT /zone/order{"order":[0,0,0]}
      • Home Assistant support can be found in the sqlsprinkler-ha repository, here.

Used libraries

  • rust >= 1.53.0
  • structopt 0.3.13
  • mysql 16.1.0
  • tokio 1.0
  • warp 0.3
  • parking_lot 0.10.0
  • rppal 0.12.0
  • chrono 0.3.0
  • confy 0.4.0
  • lazy_static 1.4.0
  • paho-mqtt 0.11
  • serde 1.0

How-to-use

  • Run the program once, as sudo, you will get a connection error.
  • Set your username, password, host, and database in /etc/sqlsprinkler/sqlsprinkler.conf
    • if you are using mqtt, then please set the mqtt_host, mqtt_pass, and mqtt_user in the configuration.
  • run your wanted sqlsprinkler command, and enjoy!

About the config

  • The settings prefixed with sqlsprinkler_ should be pretty self explanitory.
  • verbose Possible values: true/false → enables verbose logging.
  • mqtt_host The hostname of the mqtt broker.
  • mqtt_user The username of the mqtt broker.
  • mqtt_pass The password of the mqtt broker.

Issues and bugs

  • Please report any issues or bugs here

License

This project is licensed under the MIT license. Please read the LICENSE file for more information.

Contributing

  • Please feel free to by:
    • Making an issue here
    • Forking the project here
    • Making changes to the project.
    • Opening a pull request here
    • Lastly, please be descriptive and constructive with your contribution.

Code of conduct

API Documentation

Getting the system state

GET /system/state

Response

{
  "system_enabled": true
}

Updating the system state

PUT /system/state

Payload

{
  "system_enabled": false
}

Setting the system state to false will disable the system, where as setting it to true will enable the system.


Getting information for all zones

GET /zone/info

Response

[
    {
        "Name": "Rust-Zone 1",
        "gpio": 12,
        "time": 10,
        "enabled": true,
        "auto_off": true,
        "system_order": 0,
        "state": false,
        "id": 1
    }
    ...
]

This will return a list of all the zones and their information.


Updating the state of a zone

PUT /zone

Payload

{
  "id": 1,
  "state": true
}

This will turn on a zone with the ID of 1.


Adding a zone

POST /zone

Payload

{
  "name": "Rust-Zone",
  "gpio": 12,
  "time": 10,
  "enabled": true,
  "auto_off": true,
}

This will add a zone with the name of "Rust-Zone", GPIO pin 12, time 10 minutes, enabled, and auto off. System order and ID aren't specified. The ID will be automatically assigned, and the system order will be set to the default of 0.


Deleting a zone

DELETE /zone

Payload

{
  "id": 1
}

This will delete the zone with the ID of 1.


Updating zone information

PUT /zone/update

Payload

{
  "id": 1,
  "name": "Rust-Zone",
  "gpio": 12,
  "time": 10,
  "enabled": true,
  "auto_off": true,
  "system_order": 0,
}

This will update the zone with a matching ID with the information provided.


Updating zone order

PUT /zone/order

Payload

{
  "order" : [0,4,3,2]
}

This will update the order of the zones, updating the zones ORDERED BY the current system order. This example would mean the zone that is currently at system order 0, will be moved to system order 0, the zone that is currently at system order 1, will be moved to system order 4, and so on.

sqlsprinkler-cli's People

Contributors

gt3ch1 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.