Giter Club home page Giter Club logo

led's Introduction

#!/bin/bash

POWERON='{"method": "set_power", "param": {"value": true}}'
POWEROFF='{"method": "set_power", "param": {"value": false}}'
GETSTATUS='{"method": "get_status"}'

calc(){ awk "BEGIN { print int(${1}*100/${2}}/100 }";}

function send() {
    local JSON="${1}"
    r=$(curl -X POST http://192.168.1.80/command \
    --connect-timeout 1 \
    --max-time 1 \
    --write-out "%{http_code}\n" -s -o /dev/null \
    -H 'Content-Type: application/json'
    -d "$JSON")
    echo $r
}


function post() {
    local JSON="${1}"
    result=$(send "$JSON");
    echo "$result"
    if [[ "$result" -ne "200" ]]; then
        try=$(send "$POWERON")
        while [[ "$try" -ne "200" ]]; do
            echo "try restart"
            sleep 5
            try=$(send "$POWERON")
        done
    fi
}

function setColor(){
    local r=$(calc ${1} 255)
    echo "r $r"
    local g=$(calc ${2} 255)
    local b=$(calc ${3} 255)
    local w=$(calc ${4} 255)
    post "{'method': 'set_rgbw','param': {'r': "$r",'g':"$g",'b': "$b",'w': "$w", time:0}}"
}

post "$POWEROFF"
sleep 1
setColor 0 0 0 0
sleep 1
post "$POWERON"
for i in {1..50}
do
    setColor $i 0 0 0
    sleep 5
done
for i in {1..20}
do
    setColor 50 $i 0 0
    sleep 5
done
sleep 600
post "$POWEROFF"

led's People

Watchers

 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.