<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bluetooth BL Client won&#x27;t connect]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I am trying to run a simple Bluetooth LE client program to connect to an RFduino but, like others (<a href="https://forum.pycom.io/topic/791/bluetooth-wipy-client-connecting-to-wipy-peripheral">https://forum.pycom.io/topic/791/bluetooth-wipy-client-connecting-to-wipy-peripheral</a>), I am having problems getting the code to work. The code will scan and find the server but will not connect, reporting a 'connection refused' error. I have tried this with both the RFduino and a Cypress BLE development board (CY8CKIT-042-BLE), both are found during scanning but neither will connect. I can connect to both boards using scanning software on a PC, so I know both devices are working correctly.</p>
<p dir="auto">I am using the latest firmware release (1.7.6.b1), and have also tried and older version (1.4.0.b1), as BLE client code has been reported to work with this, but with no joy.</p>
<p dir="auto">I have included listings of the code, output response and WiPy 2.0 firmware below.</p>
<p dir="auto">Any help in getting this working would be appreciated.</p>
<p dir="auto">Thanks,<br />
Mervyn</p>
<pre><code>from machine import Pin
from network import Bluetooth
import machine
import time
import binascii

# Initalise GP17 in gpio mode (alt=0) as an input with pull-up enabled.
pin_in = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)

# Initalise GP16 in gpio mode (alt=0) as an output.
p_out = Pin('G16', mode=Pin.OUT)

bt = Bluetooth()
bt.start_scan(-1)
print(&quot;Starting BLE device scan.......&quot;)
while True:
    adv = bt.get_adv()
    if adv and bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'RFduino':
        print()
        bt.stop_scan()
        if not bt.isscanning():
            print(&quot;Scanning stopped.&quot;)
            print(&quot;Device {} found at address {}&quot;.format(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL), binascii.hexlify(adv.mac)))
            print(&quot;Connecting....&quot;)
            #conn = bt.connect(&quot;00A0502C6816&quot;) #Cypress BLE
            conn = bt.connect('f8f27d6df919') #RFduino
            print(&quot;Connected....&quot;)
</code></pre>
<p dir="auto">The response to running this code is:</p>
<pre><code>Starting BLE device scan.......                                                                                         
                                                                                                                        
Scanning stopped.                                                                                                       
Device RFduino found at address b'f8f27d6df919'                                                                         
Connecting....                                                                                                          
Traceback (most recent call last):                                                                                      
  File &quot;main.py&quot;, line 27, in &lt;module&gt;                                                                                  
OSError: connection refused                                                                                             
MicroPython v1.8.6-703-g5e80328a on 2017-07-05; WiPy with ESP32                                                         
Type &quot;help()&quot; for more information.                                                                                     
&gt;&gt;&gt;   
</code></pre>
<p dir="auto">The firmware release and version numbers are:</p>
<pre><code>(sysname='WiPy', nodename='WiPy', release='1.7.6.b1', version='v1.8.6-703-g5e80328a on 2017-07-05', machine='WiPy with ESP32')</code></pre>
]]></description><link>https://forum.pycom.io/topic/1469/bluetooth-bl-client-won-t-connect</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 16:31:54 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/1469.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Jul 2017 13:08:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bluetooth BL Client won&#x27;t connect on Sat, 08 Jul 2017 13:08:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I am trying to run a simple Bluetooth LE client program to connect to an RFduino but, like others (<a href="https://forum.pycom.io/topic/791/bluetooth-wipy-client-connecting-to-wipy-peripheral">https://forum.pycom.io/topic/791/bluetooth-wipy-client-connecting-to-wipy-peripheral</a>), I am having problems getting the code to work. The code will scan and find the server but will not connect, reporting a 'connection refused' error. I have tried this with both the RFduino and a Cypress BLE development board (CY8CKIT-042-BLE), both are found during scanning but neither will connect. I can connect to both boards using scanning software on a PC, so I know both devices are working correctly.</p>
<p dir="auto">I am using the latest firmware release (1.7.6.b1), and have also tried and older version (1.4.0.b1), as BLE client code has been reported to work with this, but with no joy.</p>
<p dir="auto">I have included listings of the code, output response and WiPy 2.0 firmware below.</p>
<p dir="auto">Any help in getting this working would be appreciated.</p>
<p dir="auto">Thanks,<br />
Mervyn</p>
<pre><code>from machine import Pin
from network import Bluetooth
import machine
import time
import binascii

# Initalise GP17 in gpio mode (alt=0) as an input with pull-up enabled.
pin_in = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)

# Initalise GP16 in gpio mode (alt=0) as an output.
p_out = Pin('G16', mode=Pin.OUT)

bt = Bluetooth()
bt.start_scan(-1)
print(&quot;Starting BLE device scan.......&quot;)
while True:
    adv = bt.get_adv()
    if adv and bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'RFduino':
        print()
        bt.stop_scan()
        if not bt.isscanning():
            print(&quot;Scanning stopped.&quot;)
            print(&quot;Device {} found at address {}&quot;.format(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL), binascii.hexlify(adv.mac)))
            print(&quot;Connecting....&quot;)
            #conn = bt.connect(&quot;00A0502C6816&quot;) #Cypress BLE
            conn = bt.connect('f8f27d6df919') #RFduino
            print(&quot;Connected....&quot;)
</code></pre>
<p dir="auto">The response to running this code is:</p>
<pre><code>Starting BLE device scan.......                                                                                         
                                                                                                                        
Scanning stopped.                                                                                                       
Device RFduino found at address b'f8f27d6df919'                                                                         
Connecting....                                                                                                          
Traceback (most recent call last):                                                                                      
  File &quot;main.py&quot;, line 27, in &lt;module&gt;                                                                                  
OSError: connection refused                                                                                             
MicroPython v1.8.6-703-g5e80328a on 2017-07-05; WiPy with ESP32                                                         
Type &quot;help()&quot; for more information.                                                                                     
&gt;&gt;&gt;   
</code></pre>
<p dir="auto">The firmware release and version numbers are:</p>
<pre><code>(sysname='WiPy', nodename='WiPy', release='1.7.6.b1', version='v1.8.6-703-g5e80328a on 2017-07-05', machine='WiPy with ESP32')</code></pre>
]]></description><link>https://forum.pycom.io/post/9189</link><guid isPermaLink="true">https://forum.pycom.io/post/9189</guid><dc:creator><![CDATA[tenspot]]></dc:creator><pubDate>Sat, 08 Jul 2017 13:08:39 GMT</pubDate></item><item><title><![CDATA[Reply to Bluetooth BL Client won&#x27;t connect on Sun, 09 Jul 2017 11:04:57 GMT]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/1469/bluetooth-bl-client-won-t-connect">Bluetooth BL Client won't connect</a><br />
I have now sorted the problem. I was trying to connect using what I thought was a hard coded mac address (i.e. 'f8f27d6df919') as described in the docs:<br />
<code>bluetooth.connect('112233eeddff') # mac address is accepted as a string</code><br />
It seems this is not the right format so I am now using <code>conn = bt.connect(adv.mac)</code> and the code is working.</p>
<p dir="auto">Update 9/7/2017:<br />
The correct format for a hard coded mac address is: <code>b'\xF8\xF2\x7D\x6D\xF9\x19'</code> , so <code>bt.connect(b'\xF8\xF2\x7D\x6D\xF9\x19')</code> works in the above example.</p>
]]></description><link>https://forum.pycom.io/post/9190</link><guid isPermaLink="true">https://forum.pycom.io/post/9190</guid><dc:creator><![CDATA[tenspot]]></dc:creator><pubDate>Sun, 09 Jul 2017 11:04:57 GMT</pubDate></item><item><title><![CDATA[Reply to Bluetooth BL Client won&#x27;t connect on Thu, 01 Feb 2018 12:14:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/553">@tenspot</a> said in <a href="/post/9190">Bluetooth BL Client won't connect</a>:</p>
<blockquote>
<p dir="auto">bt.connect</p>
</blockquote>
<p dir="auto">from network import LoRa<br />
from network import Bluetooth</p>
<p dir="auto">import machine<br />
import socket<br />
import pycom<br />
import binascii</p>
<p dir="auto">bluetooth = Bluetooth()</p>
<p dir="auto">bluetooth.start_scan(10)<br />
adv = None</p>
<p dir="auto">while True:</p>
<pre><code>adv = bluetooth.get_adv()
#if adv and bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'JonathanBLE':

    try:
        #print(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_APPEARANCE))
        bluetooth.connect (b'\xe0\x00\xc3\xca\x16\xf9') #JonathanBLE mac adress?
</code></pre>
<p dir="auto">Is this the wrong way to connect using the mac adress.. ? I connect to the BLE with the name and it connect in seconds... but I want to be able to connect to devices using there mac adress instead... Im using LOPY btw ... and I want to try send data between 2 LOPY decies with BLE...</p>
]]></description><link>https://forum.pycom.io/post/15255</link><guid isPermaLink="true">https://forum.pycom.io/post/15255</guid><dc:creator><![CDATA[stefan85e]]></dc:creator><pubDate>Thu, 01 Feb 2018 12:14:04 GMT</pubDate></item></channel></rss>