def receiveCoinsBT(self,transport):
        if sys.platform == 'symbian_s60':
            import btsocket
            server_socket = btsocket.socket(btsocket.AF_BT, btsocket.SOCK_STREAM)
            #port = btsocket.bt_rfcomm_get_available_server_channel(server_socket)
            #server_socket.bind(("", port))
            server_socket.bind(("", 3))
            server_socket.listen(1)
            btsocket.bt_advertise_service( u"opencoin", server_socket, True, btsocket.RFCOMM)
            btsocket.set_security(server_socket, btsocket.AUTH)
            self.feedback(u'Receive coins: ready to receive...')
            (sock,peer_addr) = server_socket.accept()

        else:
            import bluetooth as bt
            server_sock=bt.BluetoothSocket(bt.RFCOMM)
            #server_sock.bind(("",bt.PORT_ANY))
            server_sock.bind(("",3))
            server_sock.listen(1)
            port = server_sock.getsockname()[1]

            uuid = "9e72d9d8-e06d-41cb-bbd4-89cd052cccb8"
            bt.advertise_service( server_sock, u"opencoin",
                   service_id = uuid,
                   service_classes = [ uuid, bt.SERIAL_PORT_CLASS ],
                   profiles = [ bt.SERIAL_PORT_PROFILE ] )
 
            #bt.advertise_service( server_sock, u"opencoin",)
                               
            self.feedback(u'Receive coins: ready to receive...')
            sock, client_info = server_sock.accept()

        bt = transports.BTTransport(sock)
        self.wallet.getApproval = self.getApproval 
        bt.send(self.wallet.listenSum(bt.receive()))
        self.feedback(u'Receive coins: receiving...')
        bt.send(self.wallet.listenSpend(transport,bt.receive()))
        import e32
        e32.ao_sleep(1)    
Beispiel #2
0
	def run(self):
		while(True):
			try:
				bluetooth.connect()
				while(True):
					logging.log(5,'receiving from bluetooth')
					receive_string = bluetooth.receive()
					while(receive_string == ''):
						logging.log(5,'give up receiving from bluetooth')
						time.sleep(0.5)
						receive_string = bluetooth.receive()
					logging.log(5,'receiving from bluetooth end')

					# here, I will receive a dictionary
					# format: {"message":"A"}
					receiveDict = jsonpickle.decode(receive_string)

					messageDict = {"to":"arduino","message":receiveDict['message']}

					#put with blocking=True
					incomingMessageQueue.put(messageDict, True)
			except ValueError as msg:
				logging.error(msg)