def main_loop(self): while (True): print lightblue.gethostaddr() # Only for debug print(time.ctime()) os.system("date >> /tmp/bt_log") self.cfg = Config.Config() self.filename = self.cfg.get_the_file_to_send() self.TIME_TO_NEXT_SEND = self.cfg.get_the_time() random_number = random.randint(1, 100) edit_is_possible = False # We can only edit the jpg and png images if (re.search("^.*(jpg|png|jpeg)$", self.filename.lower())): edit_is_possible = True # Make the contest if random_number <= self.cfg.get_the_probability() and edit_is_possible: # Create a new Writer to reload her conf self.writer = Writer.Writer(self.cfg.get_the_background_color()) index = self.send_to_all_new(True) else: index = self.send_to_all_new(False) # Wait 5s to resend the content to the new found devices time.sleep(5) if index != 0: # THIS IS ONLY FOR DEBUG, WE MMMMMUUUUSSSSTTTTT FIX IT print 'Esperando...' time.sleep(15) print 'Matando...' subprocess.Popen('killall obexftp', shell = True, stdout = open('/dev/null', 'w'), stderr = subprocess.STDOUT)
def bind(self, address): _checkaddrpair(address, False) if self.__isbound(): raise _socket.error('Socket is already bound') elif self.__isconnected(): raise _socket.error("Socket is already connected, cannot be bound") if self.__conn.proto == _lightbluecommon.L2CAP: raise NotImplementedError( "L2CAP server sockets not currently supported") if address[1] != 0: raise _socket.error( "must bind to port 0, other ports not supported on Mac OS X") address = (address[0], _getavailableport(self.__conn.proto)) # address must be either empty string or local device address if address[0] != "": try: import lightblue localaddr = lightblue.gethostaddr() except: localaddr = None if localaddr is None or address[0] != localaddr: raise _socket.error(errno.EADDRNOTAVAIL, os.strerror(errno.EADDRNOTAVAIL)) # is this port already in use? if address[1] in self._boundports[self.__conn.proto]: raise _socket.error(errno.EADDRINUSE, os.strerror(errno.EADDRINUSE)) self._boundports[self.__conn.proto].add(address[1]) self.__port = address[1]
def bind(self, address): _checkaddrpair(address, False) if self.__isbound(): raise _socket.error('Socket is already bound') elif self.__isconnected(): raise _socket.error("Socket is already connected, cannot be bound") if self.__conn.proto == _lightbluecommon.L2CAP: raise NotImplementedError("L2CAP server sockets not currently supported") if address[1] != 0: raise _socket.error("must bind to port 0, other ports not supported on Mac OS X") address = (address[0], _getavailableport(self.__conn.proto)) # address must be either empty string or local device address if address[0] != "": try: import lightblue localaddr = lightblue.gethostaddr() except: localaddr = None if localaddr is None or address[0] != localaddr: raise _socket.error( errno.EADDRNOTAVAIL, os.strerror(errno.EADDRNOTAVAIL)) # is this port already in use? if address[1] in self._boundports[self.__conn.proto]: raise _socket.error(errno.EADDRINUSE, os.strerror(errno.EADDRINUSE)) self._boundports[self.__conn.proto].add(address[1]) self.__port = address[1]
def getaddrs(): devices = lightblue.finddevices() addrs = [] for d in devices: addrs.append(d[0]) addrs.append(lightblue.gethostaddr()) return json.dumps(addrs)
def finddevices(): addrs = [] devices = lightblue.finddevices() mydevice = lightblue.gethostaddr() for d in devices: addrs.append(d) addrs.append(mydevice) return addrs
def getsockname(self): if self.__isbound() or self.__isconnected(): import lightblue return (lightblue.gethostaddr(), self._getport()) else: return ("00:00:00:00:00:00", 0)
def read_local_bdaddr(): return [lightblue.gethostaddr()]
# Copyright (c) 2009 Bea Lam. All rights reserved.
import sys import lightblue import urllib import urllib2 a = sys.argv addr = lightblue.gethostaddr() echo = a[1] q = {"deviceaddr": addr, "echo": echo} q = urllib.urlencode(q) req = urllib2.Request('http://sokonashi.nekobato.net/echo.php') req.add_header('Content-Type', 'application/x-www-form-urlencoded') req.add_data(q) res = urllib2.urlopen(req) print res.read()
def read_local_bdaddr(): import lightblue return [lightblue.gethostaddr()]