I have following code to check the presence/absence of an LE bluetooth device.
I keep on getting following error:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "check_beacon_presence.py", line 48, in SendUdp
sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))
TypeError: function takes exactly 1 argument (2 given)
So what I did was: placind message between []. An other solution would be placing a "," after message without [], but also this does not work.
threadReqAway = threading.Thread(target=SendUdp, args=([message]))
## function for sending udp to loxone miniserver
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def SendUdp(sent_data):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))
## end function udp sending
message = "0"
class CheckAbsenceThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
time.sleep(ABSENCE_FREQUENCY)
for tag in TAG_DATA:
elapsed_time_absence=time.time()-tag[3]
if elapsed_time_absence>=tag[2] : # sleep execute after the first Home check.
#logging.warning('Tag %s not seen since %i sec => update absence',tag[0],elapsed_time_absence)
message = "AFWEZIG_"+tag[0]
#print message
#SendUdp(message)
threadReqAway = threading.Thread(target=SendUdp, args=([message]))
threadReqAway.start()
#sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
#sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))
Kommentar