How to set the scan response

Hello everyone!

I've been trying without success the setting of the scan response in my MMR+ (firmware 1.4.4), according to the documentation of the SDK that could do it in a similar way like changing the name, because those two functions (mbl_mw_settings_set_device_name and mbl_mw_settings_set_scan_response) have the same type of parameters.

This is my code based on the macro_setup.py example:

from __future__ import print_function
from mbientlab.metawear import MetaWear, libmetawear, parse_value, create_voidp_int, create_voidp
from mbientlab.metawear.cbindings import *
from threading import Event

import platform
import sys

device = MetaWear(sys.argv[1])
device.connect()
print("Connected to " + device.address)

e = Event()

print("Configuring device")

signal= libmetawear.mbl_mw_switch_get_state_data_signal(device.board)

# Start macro recording
libmetawear.mbl_mw_macro_record(device.board, 1)

arr = (c_uint8 * 8)(*([0x42, 0x72, 0x61, 0x63, 0x65, 0x6c, 0x65, 0x74]))
libmetawear.mbl_mw_settings_set_device_name(device.board, arr, 8)

scan = (c_uint8 * 8)(*([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]))
libmetawear.mbl_mw_settings_set_scan_response(device.board, scan, 8)

# Setup comparators - the first when the button is not pressed and the second when it's pressed
not_pressed = create_voidp(lambda fn: libmetawear.mbl_mw_dataprocessor_comparator_create(signal, ComparatorOperation.EQ, 0.0, None, fn), resource = "not_pressed", event = e)
pressed = create_voidp(lambda fn: libmetawear.mbl_mw_dataprocessor_comparator_create(signal, ComparatorOperation.EQ, 1.0, None, fn), resource = "pressed", event = e)

# LED is OFF when the button is not pressed
libmetawear.mbl_mw_event_record_commands(not_pressed)
libmetawear.mbl_mw_led_stop_and_clear(device.board)
create_voidp_int(lambda fn: libmetawear.mbl_mw_event_end_record(not_pressed, None, fn), event = e)

# LED is ON when the button is pressed and the motor runs
pattern= LedPattern(pulse_duration_ms=1000, high_time_ms=500, high_intensity=16, low_intensity=16, repeat_count=Const.LED_REPEAT_INDEFINITELY)
libmetawear.mbl_mw_event_record_commands(pressed)
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.BLUE)
libmetawear.mbl_mw_led_play(device.board)
# Run motor at 50% strength for 500 ms when the button is pressed
libmetawear.mbl_mw_haptic_start_motor(device.board, 50.0, 500);
create_voidp_int(lambda fn: libmetawear.mbl_mw_event_end_record(pressed, None, fn), event = e)

# End macro recording
create_voidp_int(lambda fn: libmetawear.mbl_mw_macro_end_record(device.board, None, fn), event = e)

print("Resetting device")
device.on_disconnect = lambda status: e.set()
libmetawear.mbl_mw_debug_reset(device.board)
e.wait()

Changing the name is working, because it advertises like "Bracelet", but I cannot find the scan response using the nRF connect app.

The goal with this it will be to change the scan response from time to time according some events.

What do you suggest me? Is it really possible what I'm trying to do?

Thanks for your answers!

Comments

  • I can't check this right now, but don't you view scan response under the "More" tab?

    You can also double check this by setting up a log session with metabase and viewing the scan response with nRF connect.

  • The "More" tab doesn't show that, it shows a history of the received packets, like this:

    Maybe the "Raw" tab is more detailed about the content of the packets, but nothing about my scan response.

    @Eric said:
    You can also double check this by setting up a log session with metabase and viewing the scan response with nRF connect.

    I checked, if I set up a log session the scan response is shown in the nRF connect app (look at the two following pictures), I suppose that you use that for indicating the logging state for the device.

    I confirmed that I can get the scan response with the nRF connect app. But I don't know why I cannot modify it with my own code yet?

    Thanks for your help.

  • Try using that scan specific scan response from MetaBase.

  • I went deeper and I found this useful https://github.com/mbientlab/MetaWear-SDK-Cpp/blob/master/test/test_settings.py

    I solved it with these new lines

    At the begining lines I add: from ctypes import *

    I replaced these lines

    arr = (c_uint8 * 8)(*([0x42, 0x72, 0x61, 0x63, 0x65, 0x6c, 0x65, 0x74]))
    libmetawear.mbl_mw_settings_set_device_name(device.board, arr, 8)
    
    scan = (c_uint8 * 8)(*([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]))
    libmetawear.mbl_mw_settings_set_scan_response(device.board, scan, 8)
    

    The new ones are

    device_name = create_string_buffer(b'Bracelet', 8)
    bytes = cast(device_name, POINTER(c_ubyte))
    libmetawear.mbl_mw_settings_set_device_name(device.board, bytes, len(device_name.raw))
    
    scan_response= create_string_buffer(b'\x05\xff\xff\xff\x01\x01', 6)
    bytes_scan = cast(scan_response, POINTER(c_ubyte))
    libmetawear.mbl_mw_settings_set_scan_response(device.board, bytes_scan, len(scan_response.raw))
    

    I set the scan response (0x05 the length of the data, 0xff the type is Manufacturer Specific Data, 0xff 0xff indicates No Company ID and finally my custom two bytes 0x01 0x01) and I can look at it in the nRF connect app, the problem was that I was not configuring the parameters correctly. I think that you could be a little more detailed about it in the next release of the SDK for Python, maybe including a new example with that.

    Thanks Eric! You didn't answer my question directly, but maybe you are the author of the tests where I found the way for solving it. I will post a new thread related with this topic, but it's a different problem, so I appreciate some help from your team with that too.

Sign In or Register to comment.