Bluetooth Bad Write Handler - Servegatt

Is this a suitable way of writing a service? I’m writing the table out by hand… I don’t get a specific line error, it’s to the beginning of a function.

bad write handler in servegatt(services) (line 1247)

{
    "uuid": BT.uuids.wifi_clear_trigger_uuid,
    "write": function(conn, v) {
        imp.clearconfiguration(CONFIG_WIFI);
        return 0x0000;
    }
}

You could try adding a .bindenv(this) the function’s closing brace (}). I would also check how you’re adding the characteristic to the service, not treating the characteristic as the service itself. For example, in our Bluetooth BlinkUp sample, we do:

// Define the BlinkUp service
local service = {};
service.uuid <- _uuids.blinkup_service_uuid;
service.chars <- [];

. . .

// Define a dummy setter characteristic to trigger WiFi clearance
local chrx = {};
chrx.uuid <- _uuids.wifi_clear_trigger_uuid;
chrx.write <- function(conn, v) {
    server.log("Device WiFi clearance triggered");
    _blinkup.clear();
    return 0x0000;
}.bindenv(this);
service.chars.append(chrx);

Otherwise that looks OK as a write handler.