pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
196 stars 167 forks source link

BLE - OSError: connection refused #15

Closed Bucknalla closed 7 years ago

Bucknalla commented 7 years ago
(sysname='LoPy', nodename='LoPy', release='1.6.13.b1', version='v1.8.6-607-g9c8a0e9e on 2017-05-01', machine='LoPy with 
ESP32', lorawan='1.0.0') 

Attempting to connect from one LoPy to another LoPy device:

from network import Bluetooth
import binascii
bluetooth = Bluetooth()

# scan until we can connect to any BLE device around
bluetooth.start_scan(-1)
adv = None
while True:
    adv = bluetooth.get_adv()
    if adv:
        try:
            print(binascii.hexlify(adv.mac))
            bluetooth.connect(adv.mac)
        except:
            # start scanning again
            bluetooth.start_scan(-1)
            continue
        break
print("Connected to device with addr = {}".format(binascii.hexlify(adv.mac)))

Error arises after the connecting LoPy finds the address of the advertising device and attempts to connect.

b'240ac40061fa'
Traceback (most recent call last):                                                                                      
  File "<stdin>", line 50, in <module>                                                                                  
OSError: connection already closed

                                                                          Thanks!

grandcat commented 7 years ago

Maybe try bluetooth.init() after bluetooth = Bluetooth()

danicampora commented 7 years ago

Solved on the latest release.