Jump to content

Question

Posted

Серверу умного дома поелзно знать о наличии определённых устройств в сети в данный момент времени. На основании этих данных можно настроить события в доме,  например выключить свет, запустить пылесос и тд 

Лучше всех о том кто сейчас в сети знает роутер, и было бы не плохо еслиб он мог отдавать текущих активных клиентов сети. Желательно в формате который будет удобно читать кодом нопример (JSON, или XML).  Отдавать можно по SSH либо по HTTP GET. 

Сейчас состояние устройств можно получить в SSH по командам 

1) "show ip arp", на на последней 3.00.B.1.0-0б она работает не коректно, показывает девайсы которых реально нет. + формат не очень удобен для чтения его из кода. 
2) "show ip hotspot", работает лучше но возвращяет огромное количество не нужной информации. Что бы выбрать только активные хосты, нужно парсить всесь респонз который просто plain text. 

Может быть есть лучший вариант и я его просто не знаю.
 

3 answers to this question

Recommended Posts

  • 0
Posted

Возможно поможет поиск - "xmlstarlet/ndmq"

mac_client=`ndmq -p 'show associations' -x | xml sel -t -m '//station[authenticated="yes"][mac="xx:xx:xx:xx:xx:be"]' -v 'mac' 

ndmq -p 'show ip hotspot' -x | xml sel -t -m '//host[link="up"][active="yes"]' -v 'name' -o ' : ' -v 'ip' -o ' : ' -v 'rxbytes' -o ' : ' -v 'txbytes'

ndmq -p 'show associations' -x | xml sel -t -m '//station[ap="WifiMaster1/AccessPoint0"][authenticated="yes"]' -v 'mac' -o '

ndmq -p 'show interface' -x | xml sel -t -m '//interface[link="up"][state="up"][connected="yes"]' -v '@name' -o ': ' -v 'address' -o '/' -v 'mask' -n

так же поиск по форуму

  • 0
Posted

Всем Спасибо! 

Вот такой скрипт получился для интерграции keenetic с domoticz : 

#!/bin/sh

#actions 
#1 replace mac1 mac2 to actual macs 
#2 update domoticz idxs actual idxs
#3 update domoticz or MQTT IP IP address

#list of phones macs 
Phone1="mac1"
Phone2="mac2"
Phone3="mac3"
Phone4="mac4"

#map macs to domoticz switch idx  
replacement() {
    case "$1" in
        *$Phone1* ) echo "248";;
        *$Phone2* ) echo "249";;
        *$Phone3* ) echo "250";;
        *$Phone4* ) echo "251";;
    esac
}

#map del to 0 and new to 1 
replacement2() {
    case "$1" in
        *new* ) echo "1";;
        *del* ) echo "0";;
    esac
}

if [[ "$address" = "ipv4" && "$update" = "none" ]]; then
  #get device mac by ID
  mac=$(wget -qO - http://127.0.0.1:79/rci/show/ip/neighbour | jq --arg num "$id" '.[$num].mac')
  #replace mac to inx
  who=$(replacement "$mac")
  [ -z "$who" ] && exit 0
  #replace mac to idx
  action2=$(replacement2 "$action")
  #send to domoticz by http
  #curl -sS "http://192.168.1.25:8080/json.htm?type=command&param=udevice&idx=$who&nvalue=$action2"
  #send to domoticz by MQTT
  mosquitto_pub -d -t domoticz/in  -m "{\"idx\": $who, \"nvalue\": $action2}" -h 192.168.1.25 -p 1883
fi

скрипт почти полностью взять отсюда 

 

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

This site uses cookies. By clicking "I accept" or continuing to browse the site, you authorize their use in accordance with the Privacy Policy.