Bluetooth Bad Write Handler - Servegatt

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.