hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
 
PROCESS=gmediarender
NAME=rockchip
 
dlna_start()
{
    echo dlna_start
    $PROCESS -f $NAME -d
}
 
dlna_stop()
{
    echo dlna_stop
    killall $PROCESS
}
 
wifiUpAction()
{
    echo wifiUp
    dlna_start
}
wifiDownAction()
{
    echo wifiDown
    dlna_stop
}
wifiChangeAction()
{
    echo wifiChange
    dlna_stop
    dlna_start
}
wifiRequestingIp()
{
    echo wifiRequestingIp
}
 
checkwifistate()
{
    local flag=0
    local last_ip_address=0
    while true
    do
        wpa_state=`wpa_cli -iwlan0 status | grep wpa_state | awk -F '=' '{printf $2}'`
        ip_address=`wpa_cli -iwlan0 status | grep ip_address | awk -F '=' '{printf $2}'`
 
        if [ "${wpa_state}"x = "COMPLETED"x ];then
            if [ "${ip_address}"x != ""x ] && [ "${ip_address}"x != "0.0.0.0"x ];then
                if [ $flag -eq 0 ];then
                    flag=1
                    wifiUpAction
                elif [ "${ip_address}"x != "${last_ip_address}"x ];then
                    flag=1
                    wifiChangeAction
                else
                    flag=1
                fi
            else
               flag=0
               wifiRequestingIp
            fi
        else
            if [ $flag -eq 1 ];then
               flag=0
               wifiDownAction
            fi
        fi
        sleep 3
        last_ip_address="${ip_address}"
    done
}
 
killall $PROCESS
checkwifistate