Can't use Bluetooth.BLE_Mesh on Wipy 3 board. Why?
-
Hi!
I have some Wipy 3 boards that I want to create a Bluetooth mesh with by using Pymesh BLE. I have started off by following the sensor example in this link.
Here is my code for creating a Pymesh BLE server:
from network import Bluetooth from hardware.rgb_led import RGBLed import time from machine import Timer class BluetoothMeshServer: bluetooth = None model_server = None ble_mesh = None def __init__(self): pass def start(self): BLE_Mesh = Bluetooth.BLE_Mesh # BLE Mesh module # self.ble_mesh = Bluetooth.BLE_Mesh.init(name="PYCOM-ESP-BLE-MESH", *, auth=0, callback=None) self.ble_mesh = Bluetooth.BLE_Mesh.init(name="xxx", auth=0, callback=None) # Need to turn ON Bluetooth before using BLE Mesh self.bluetooth = Bluetooth() # Create a Primary Element with GATT Proxy feature and add a Server model to the Element element = self.ble_mesh.create_element(primary=True, feature=self.ble_mesh.GATT_PROXY) self.model_server = element.add_model(self.ble_mesh.SENSOR, self.ble_mesh.SERVER, sen_min = 0, sen_max = 59, sen_res = 1) # Initialize self.ble_mesh self.ble_mesh.init("Pycom Sensor Server", callback=self.prov_callback) # Turn on Provisioning Advertisement self.ble_mesh.set_node_prov(self.ble_mesh.PROV_ADV|self.ble_mesh.PROV_GATT) # Sensor takes measurement every 1 second Timer.Alarm(self.read_sensor, 1, periodic=True) # Sensor send status every 5 seconds Timer.Alarm(self.status_sensor, 5, periodic=True) def read_sensor(self, alarm): # In this example sensor reads local seconds if(device_provisioned): self.model_server.set_state(time.localtime()[5]) print("SENSOR | State: ", self.model_server.get_state()) def status_sensor(self, alarm): if (device_provisioned): self.model_server.status_state() def prov_callback(self, event, oob_pass): global device_provisioned if(event == self.ble_mesh.PROV_REGISTER_EVT or event == self.ble_mesh.PROV_RESET_EVT): # Yellow if not Provision yet or Reset RGBLed.turn_yellow() device_provisioned = False if(event == self.ble_mesh.PROV_COMPLETE_EVT): # Green if Provisioned RGBLed.turn_green device_provisioned = True
The trouble I'm having is that the line:
BLE_Mesh = Bluetooth.BLE_Mesh
throws an exception in the terminal. Here is the error output from the terminal:
Traceback (most recent call last): File "main.py", line 11, in <module> File "lib/bluetooth_mesh_server.py", line 16, in start AttributeError: type object 'Bluetooth' has no attribute 'BLE_Mesh' Pycom MicroPython 1.20.2.r6 [v1.11-c5a0a97] on 2021-10-28; WiPy with ESP32 Pybytes Version: 1.7.1 Type "help()" for more information.
As you can see, the error says "AttributeError: type object 'Bluetooth' has no attribute 'BLE_Mesh'". Why? How do I use BLE_Mesh with Wipy 3 boards to create a Bluetooth mesh?
Thanks!
-
@Tobias-Eliasson I believe you need to enable Pymesh via Pybytes (and accept the associated license) before you can use it. See https://docs.pycom.io/pybytes/pymeshintegration/provisioning/ for info.