예제 #1
0
def keepAvahiBrowsing(thread_name, ipaddresses, lock, option):
    print("start keepAvahiBrowsing: threadname=" + thread_name + " option=" + option)
    while( True ):
        (output, err) = runShellCommand("avahi-browse -rtp _coap._udp | grep 'piSenseHat-4'")
        if( (err == None) or (output == None or len(output) == 0) ):
            print("SpotFinderThread: error avahi-browse err=" + str(err) + ",out=" + output)
        else:
            lines = output.splitlines()
            for line in lines:
                arr = line.split(";")
                if( len(arr) >= 8 ):
                    ip = arr[7]
                    #print("SpotFinderThread: testing ip=" + ip + ",isValidIp=" + str(isValidIpv4(ip)) + ",in=" + str(ip in ipaddresses))
                    lock.acquire()
                    if( isValidIpv4(ip) and (ip in ipaddresses) == False ):
                        print("SpotFinderThread: client-ip found ip=" + ip)
                        b = False
                        if(option == "skip"):
                            b = True
                        else:
                             b = sendServerIPtoParkingSpot("sendServerIPtoParkingSpot", ip, getOwnIP())
                        if( b == True ):
                            RequestUtils.createParkingSpot(ip)
                            ipaddresses.append(ip)
                    lock.release()
        time.sleep(5)