Wednesday, September 11, 2019

自幹 apc ups不斷電 控制系統 (二) 陽春 status

沒有像

這樣的畫面呢
來寫一個陽春的監測畫面好了node.js~
let express = require('express'); let app = express(); let router = express.Router(); let exec = require('child_process').exec; let port = 9000; //app.use(express.static(__dirname + '/public')); //app.use('/img', express.static(__dirname + '/public/img')); let header = '<!DOCTYPE html><html><head><title>ctrl PHP</title>' + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' + '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">' + '<meta http-equiv="refresh" content="1" >' + '</head><body><pre>'; let footer = "</pre></body></html>"; router.get('/', function (req, res, next) { //預設頁面 console.log('index'); res.sendfile('index.html', {root: __dirname + "/public"}); }); router.get('/ls', function (req, res, next) { //執行 ls -al 指令 exec('sudo upsc mge | grep -E "ups.status|battery"', function (err, stdout, stderr) { console.log('ls'); res.send(header + stdout + footer + stderr + err ); }); }); app.use('/', router); app.listen(port); app.listen(3000, function () { console.log('Example app listening on port 3000!'); });

運行一下

Tuesday, September 10, 2019

自幹 apc ups不斷電 控制系統

身為一個教學文,當然不可以只有開箱


一堆東西都不支援,買個 apc ups 網路介面卡,要一萬多(黑人問號???
我買了的型號太舊還沒網路孔??????,幸好還有一個usb 串列孔
乾脆來用上次開箱的ai 板子 直接寫一個 ups 控制器嘿嘿


流程圖 (小畫家 甲級

安裝 nut ups tool

x213212@x213212-desktop:~$ sudo apt-get install nut-server nut-client nut-monitor s-nail

基礎設定

x213212@x213212-desktop:/etc/nut$ lsusb
Bus 002 Device 002: ID 0bda:0411 Realtek Semiconductor Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0a2b Intel Corp.
Bus 001 Device 006: ID 3938:1034
Bus 001 Device 005: ID 04d9:0161 Holtek Semiconductor, Inc.
Bus 001 Device 004: ID 0eef:0005 D-WAV Scientific Co., Ltd
:bulb: 一定要設置 你的 usb “bus” 和 “device” 如上
確定抓到 American Power Conversion Uninterruptible Power
Bus 001 Device 007: ID 051d:0002 American Power Conversion Uninterruptible Power
Bus 001 Device 002: ID 0bda:5411 Realtek Semiconductor Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
once try these things,
You can use lsusb to find out the bus and device number
Then change permission to the device
chmod 0666 /dev/bus/usb/[bus number]/[device number]
as for details go with rouble starting Network UPS Tools with a Eaton 3S UPS
share
improve this answer
設定完

系統配置

x213212@x213212-desktop:/etc/nut$ sudo upsc mge
就可以順利看到我們的ups 內容囉~

https://www.vediotalk.com/?p=2211
跟著設權限

有囉~
安裝 sshpass

開始寫小東西
apt-get install sshpass
sshpass -p rootx root@192.168.0.105
那個我們只要跟著下
sshpass -p rootx ssh root@192.168.0.105 'shutdown -h now’
我們的nas就關機囉
那我們在 我們上次的ubuntu 來寫script吧~
簡單nut ups tool  設置什麼好亂 乾脆自己來xd寫 script
while :
do
        clear
        sleep 1
        TAROUTPUT=$( upsc mge | grep -E "ups.status")
        TAROUTPUT2=$( upsc mge | grep -E "battery")


        substr=$( echo ${TAROUTPUT/ups.status: /""})
#       echo $substr
#       if [ $substr == "OL" or $substr == "OL CHRG"]; then
           #     echo "good"
          #  else
         #       echo "bad"
        #fi
          case "$substr" in
          "OL CHRG") echo "充電中"
             ;;
          "OL") echo "已經完全充滿"
             ;;
          *) echo "已經拔除電源,通知系統關機。"
                  sshpass -p rootx ssh root@192.168.0.105 'shutdown -h now'                                                                                                                      break;
          esac
#       echo  $substr
#       echo $TAROUTPUT
#       echo "\n"
 #       echo $TAROUTPUT2
done



背景執行
nohup bash ups.sh &> /dev/null &
jobs 可以看到運行中的 任務
這樣 斷電的時候我的 nas 就可以自動關機囉~
立馬省一萬
oops 我要換密碼 不然有心人士要登入我帳號了,不用擔心 群輝 nas 有用 google authenticator 應該是蠻安全的 (?

D218j 軟體安裝與設置

使用 三天 XDD一堆東西, 4T可能還可以用很多年~

D218j 軟體安裝

https://global.download.synology.com/download/Document/HIG/DiskStation/18-year/DS218j/Syno_HIG_DS218j_cht.pdf

下載

安裝


















裝完去 GOOGLE STORE 搜尋群輝 就可以找到相對應的雲端軟體囉~ 比較要注意的是
我買的硬體規格 CPU 很弱 , 再經由 其他地方 傳過來得時候 都要經過 FFMPEG 去轉碼,所以有時候會有 IO的錯誤 , 這個時候 右上角 有一個延遲轉碼的東西把它設遠一點就好了,不然東西都傳不上 去。

手機容量不足了 ,來組一台 NAS



D218j Install + UPS

組裝一波, 4T 組 RAID 1 穩穩
























旁邊那台黑黑 UPS的型號太舊了官方配的 軟體不夠靈活 , 我再來開一篇來自幹 UPS 控制XDD