Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PiTooth.py program after pairing from a second terminal, the program in the other terminal is still "waiting for connection"

I followed this tutorial for emulating my Raspberry pi model B as a bluetooth Keyboard. I am able to identify the pi as a keyboard when searching for connection. The pairing part is working fine also, I am using the following command for pairing:

sudo blue-simple-agent hci0 <mac address>

The tutorial asks to run the PiTooth code in one terminal and it will initialise the required ports (control and interrupt ports), read the SDP record, advertise the sdp record and it will listen for connection in the control and interrupt port. Then open another terminal and use the above command to pair with the client. It is getting paired but it not reflected in the other terminal, which is still like "waiting for connection. The following is the part of the python code where it is listening for connection and connecting:

class Bluetooth:
 HOST = 0 # BT Mac address
 PORT = 1 # Bluetooth Port Number...
 def listen(self):
      # Advertise our service record
      self.service_handle = self. service.AddRecord(self.service_record)
      print “Service record added”
      # Start listening on the server sockets
      self.scontrol.listen(1) # Limit of 1 connection
      self.sinterrupt.listen(1)
      print “Waiting for a connection”
      self.ccontrol, self.cinfo = self.scontrol.accept()
      print “Got a connection on the control channel from “ + self.cinfo[Bluetooth.HOST]
      self.cinterrupt, self.cinfo = self.sinterrupt.accept()
      print “Got a connection on the interrupt channel from “ + self.cinfo[Bluetooth.HOST]

The whole code is really big and I don't like to enlarge the question. Please view this google doc for the code: https://docs.google.com/document/d/1hEyprvN1MyFqyczL9Qh07_-pJjRvBIEkomiJhLHcXiQ/edit?usp=sharing

Can anyone help me solve this issue. Or is there any problem with the code. Is there any alternative ways to listen for connection.

like image 710
Shameel Mohamed Avatar asked Feb 03 '26 21:02

Shameel Mohamed


1 Answers

The issue is resolved. It was an out-of-box solution actually. The problem was with the operating power of the pi. The pi was powered from my laptop's USB port and it's voltage was about 4.4V. USB ports usually provide only 500 mA, 5 V. Raspberry pi need a voltage source of about 4.75 to 5.25V and current in range of 700 to 1000 mA for optimum performance. Exactly how much current (mA) the Raspberry Pi requires is dependent on what you connect to it. For reference about power supply. I just changed the source, I fetched power via a 1000 mA 5v adapter and checked the voltage in the pi, it was about 4.64V and it worked fine.

like image 119
Shameel Mohamed Avatar answered Feb 06 '26 12:02

Shameel Mohamed