Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/StackChan/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,23 @@ class AppState: ObservableObject {
}
BlufiUtil.shared.characteristicCallback = { characteristic in
if characteristic.properties.contains(.write) || characteristic.properties.contains(.writeWithoutResponse) {

if characteristic.uuid.uuidString == "E2E5E5E2-1234-5678-1234-56789ABCDEF0" {
BlufiUtil.shared.writeExpressionCharacteristic = characteristic
print("✏️ Expression writable characteristic assigned: \(characteristic.uuid)")
}

if characteristic.uuid.uuidString == "E2E5E5E1-1234-5678-1234-56789ABCDEF0" {
BlufiUtil.shared.writeHeadCharacteristic = characteristic
print("✏️ Head writable characteristic assigned: \(characteristic.uuid)")
}

// Config characteristic — used for Wi-Fi provisioning (SSID + password JSON)
// during pairing. Firmware handler is _handle_ble_config_write in hal_ble.cpp.
if characteristic.uuid.uuidString == "E2E5E5E3-1234-5678-1234-56789ABCDEF0" {
BlufiUtil.shared.writeWifiSetCharacteristic = characteristic
print("✏️ Config/Wifi writable characteristic assigned: \(characteristic.uuid)")
}
}
}
}
Expand Down
23 changes: 19 additions & 4 deletions app/StackChan/View/BindingDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,38 @@ struct ScanningEquipment : View {
}

private func confirmWifi() {

if !BlufiUtil.shared.blueSwitch {
appState.alertTitle = "Please turn on Bluetooth"
appState.showAlert = true
return
}

if wifiName.isEmpty || wifiPassword.isEmpty {
appState.alertTitle = "Please enter Wi-Fi name and password"
appState.showAlert = true
return
}


// Push the Wi-Fi credentials to the StackChan over BLE.
// The firmware expects {"ssid":..., "password":...} on the Config
// characteristic (see hal_ble.cpp:_handle_ble_config_write).
let payload: [String: String] = [
"ssid": wifiName,
"password": wifiPassword,
]
if let data = try? JSONSerialization.data(withJSONObject: payload),
let json = String(data: data, encoding: .utf8) {
BlufiUtil.shared.sendWifiSetData(json)
print("➡️ Wi-Fi credentials sent to device")
} else {
print("⚠️ Failed to serialise Wi-Fi payload")
}

withAnimation{
pairingStatus = .DistributionNetwork
}

DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
withAnimation{
pairingStatus = .ChangeTheName
Expand Down