Hi, currently im having a problem with bluetooth and wifi code that cause the device to freeze.
the base code taken from this page:
https://developer.electricimp.com/resources/bluetooth_le
the problem is that sometimes when i trigger the bluetooth to input the wrong password and reset the imp. and the imp will freeze without running the code (which is to turn OFF the LED (normally ON))
this is not always happen, 3 out of 10 the device will freeze.
is there any way to solve this or any workaround?
my device is imp004m
and this is my code:
#require “bt_firmware.lib.nut:1.0.0”
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 5);
//======================================
//led setup
//======================================
led_pin ← hardware.pinP
led_pin.configure(DIGITAL_OUT,0) // the program will not turn off the LED after the bluetooth triggered
//======================================
//bt setup
//======================================
bt_uart ← hardware.uartFGJH;
bt_lpo_in ← hardware.pinE;
bt_reg_on ← hardware.pinJ;
// Boot up Bluetooth: ground LPO_IN and set BT_REG_ON to High
bt_lpo_in.configure(DIGITAL_OUT, 0);
bt_reg_on.configure(DIGITAL_OUT, 1);
imp.sleep(0.1);
bt ← null;
bt = hardware.bluetooth.open(bt_uart, BT_FIRMWARE.CYW_43438);
//======================================
//gatt setup
//======================================
connection ← null;
local service = {};
// WiFi Credential Refresh Service
service.uuid ← “FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF”;
service.chars ← [];
local chara = {};
// Set dummy characteristic
chara = {};
chara.uuid ← “FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0”;
chara.write ← function(conn, v) {
imp.clearconfiguration(CONFIG_WIFI)
imp.setwificonfiguration(“correct ssid”,“incorrect pw”)
imp.onidle(function() {
imp.reset()
});
};
service.chars.append(chara);
bt.setsecurity(1);
bt.servegatt([service]);
server.log(“Serving GATT…”);
bt.onconnect(function(conn) {
connection = conn;
server.log(conn.address() + " connected");
conn.onclose(function() {
server.log(connection.address() + " disconnected");
});
});
//======================================
//advertise setup
//======================================
local unit_model = “TESTXX_”
unit_model = unit_model + hardware.getdeviceid()
unit_model = “\x09”+unit_model
local len=unit_model.len()
bt.startadvertise(len.tochar()+unit_model, 100, 100);
server.log(“Advertising…”);