diff --git a/__tests__/screens/profile-logout.test.tsx b/__tests__/screens/profile-logout.test.tsx
index 9a2f26c..90f6f97 100644
--- a/__tests__/screens/profile-logout.test.tsx
+++ b/__tests__/screens/profile-logout.test.tsx
@@ -210,7 +210,6 @@ describe('Logout Flow BLE Integration', () => {
try {
await mockCleanupBLE();
} catch (error) {
- console.log('BLE cleanup failed, continuing with logout');
}
await mockLogout();
};
diff --git a/app/(tabs)/beneficiaries/[id]/add-sensor.tsx b/app/(tabs)/beneficiaries/[id]/add-sensor.tsx
index 368393b..046ee0d 100644
--- a/app/(tabs)/beneficiaries/[id]/add-sensor.tsx
+++ b/app/(tabs)/beneficiaries/[id]/add-sensor.tsx
@@ -46,13 +46,10 @@ export default function AddSensorScreen() {
// Cleanup: Stop scan when screen loses focus or component unmounts
useFocusEffect(
useCallback(() => {
- console.log('[AddSensor] Screen focused');
// Cleanup function - called when screen loses focus
return () => {
- console.log('[AddSensor] Screen blur - cleaning up BLE scan');
if (isScanning) {
- console.log('[AddSensor] Stopping active scan');
stopScan();
}
};
diff --git a/app/(tabs)/beneficiaries/[id]/index.tsx b/app/(tabs)/beneficiaries/[id]/index.tsx
index 73cf757..68184af 100644
--- a/app/(tabs)/beneficiaries/[id]/index.tsx
+++ b/app/(tabs)/beneficiaries/[id]/index.tsx
@@ -137,7 +137,6 @@ export default function BeneficiaryDetailScreen() {
user_id: ${credentials.userId}
};
localStorage.setItem('auth2', JSON.stringify(authData));
- console.log('Token auto-refreshed');
})();
true;
`;
@@ -401,9 +400,7 @@ export default function BeneficiaryDetailScreen() {
user_id: ${legacyCredentials.userId}
};
localStorage.setItem('auth2', JSON.stringify(authData));
- console.log('Auth data injected:', authData.username);
} catch(e) {
- console.error('Failed to inject token:', e);
}
})();
true;
@@ -474,7 +471,6 @@ export default function BeneficiaryDetailScreen() {
deviceId: beneficiary.device_id,
devices: beneficiary.devices,
}, null, 2);
- console.log('DEBUG DATA:', debugData);
}}>
hasDevices: {String(hasBeneficiaryDevices(beneficiary))}
equipmentStatus: {beneficiary.equipmentStatus || 'none'}
diff --git a/app/(tabs)/beneficiaries/[id]/setup-wifi.tsx b/app/(tabs)/beneficiaries/[id]/setup-wifi.tsx
index 00a96ba..369e0cb 100644
--- a/app/(tabs)/beneficiaries/[id]/setup-wifi.tsx
+++ b/app/(tabs)/beneficiaries/[id]/setup-wifi.tsx
@@ -131,9 +131,7 @@ export default function SetupWiFiScreen() {
const passwords = await wifiPasswordStore.getAllWiFiPasswords();
savedPasswordsRef.current = passwords;
setSavedPasswords(passwords);
- console.log('[SetupWiFi] Loaded saved passwords for', Object.keys(passwords).length, 'networks');
} catch (error) {
- console.log('[SetupWiFi] Failed to load saved passwords:', error);
} finally {
setPasswordsLoaded(true);
}
@@ -143,32 +141,22 @@ export default function SetupWiFiScreen() {
}, []);
const loadWiFiNetworks = async () => {
- console.log('[SetupWiFi] loadWiFiNetworks started, deviceId:', deviceId);
if (!deviceId) {
- console.error('[SetupWiFi] No deviceId available!');
return;
}
setIsLoadingNetworks(true);
try {
// First connect to the device before requesting WiFi list
- console.log('[SetupWiFi] Step 1: Connecting to device...');
const connected = await connectDevice(deviceId);
- console.log('[SetupWiFi] Connection result:', connected);
if (!connected) {
throw new Error('Could not connect to sensor. Please move closer and try again.');
}
- console.log('[SetupWiFi] Step 2: Getting WiFi list...');
const wifiList = await getWiFiList(deviceId);
- console.log('[SetupWiFi] WiFi networks found:', wifiList.length);
setNetworks(wifiList);
} catch (error: any) {
- console.error('[SetupWiFi] loadWiFiNetworks FAILED:', {
- message: error?.message,
- stack: error?.stack?.substring(0, 300),
- });
Alert.alert('Error', error.message || 'Failed to get WiFi networks. Please try again.');
} finally {
setIsLoadingNetworks(false);
@@ -181,7 +169,6 @@ export default function SetupWiFiScreen() {
const savedPwd = savedPasswords[network.ssid];
if (savedPwd) {
setPassword(savedPwd);
- console.log('[SetupWiFi] Auto-filled password for network:', network.ssid);
} else {
setPassword('');
}
@@ -193,7 +180,6 @@ export default function SetupWiFiScreen() {
const savedPwd = savedPasswords[selectedNetwork.ssid];
if (savedPwd) {
setPassword(savedPwd);
- console.log('[SetupWiFi] Auto-filled password after load for network:', selectedNetwork.ssid);
}
}
}, [passwordsLoaded, savedPasswords, selectedNetwork]);
@@ -279,21 +265,14 @@ export default function SetupWiFiScreen() {
updateSensorStatus(deviceId, 'attaching');
if (!isSimulator && wellId) {
- console.log('[SetupWiFi] Attaching device to beneficiary:', {
- beneficiaryId: id,
- wellId,
- ssid,
- });
const attachResponse = await api.attachDeviceToBeneficiary(
id!,
wellId,
ssid,
pwd
);
- console.log('[SetupWiFi] Attach response:', attachResponse);
if (!attachResponse.ok) {
const errorDetail = attachResponse.error || 'Unknown API error';
- console.error('[SetupWiFi] Attach FAILED:', errorDetail);
throw new Error(`Failed to register sensor: ${errorDetail}`);
}
}
@@ -311,7 +290,6 @@ export default function SetupWiFiScreen() {
await rebootDevice(deviceId);
} catch (rebootError: any) {
// Ignore BLE errors during reboot - the device disconnects on purpose
- console.log('[SetupWiFi] Reboot command sent (device will disconnect):', rebootError?.message);
}
updateSensorStep(deviceId, 'reboot', 'completed');
@@ -322,12 +300,6 @@ export default function SetupWiFiScreen() {
} catch (error: any) {
const errorMsg = error.message || 'Unknown error';
- console.error('[SetupWiFi] processSensor FAILED:', {
- deviceId,
- deviceName,
- errorMsg,
- stack: error?.stack?.substring(0, 200),
- });
// Find current step and mark as failed
setSensors(prev => prev.map(s => {
@@ -446,9 +418,7 @@ export default function SetupWiFiScreen() {
savedPasswordsRef.current = updatedPasswords;
setSavedPasswords(updatedPasswords);
- console.log('[SetupWiFi] Password saved securely for network:', selectedNetwork.ssid);
} catch (error) {
- console.log('[SetupWiFi] Failed to save password:', error);
// Continue with setup even if save fails
}
diff --git a/contexts/BLEContext.tsx b/contexts/BLEContext.tsx
index 0d6aeae..7f1d325 100644
--- a/contexts/BLEContext.tsx
+++ b/contexts/BLEContext.tsx
@@ -54,11 +54,9 @@ export function BLEProvider({ children }: { children: ReactNode }) {
}, []);
const connectDevice = useCallback(async (deviceId: string): Promise => {
- console.log('[BLEContext] connectDevice called:', deviceId);
try {
setError(null);
const success = await bleManager.connectDevice(deviceId);
- console.log('[BLEContext] connectDevice result:', success);
if (success) {
setConnectedDevices(prev => new Set(prev).add(deviceId));
} else {
@@ -67,7 +65,6 @@ export function BLEProvider({ children }: { children: ReactNode }) {
}
return success;
} catch (err: any) {
- console.error('[BLEContext] connectDevice exception:', err);
setError(err.message || 'Failed to connect to device');
return false;
}
@@ -87,14 +84,11 @@ export function BLEProvider({ children }: { children: ReactNode }) {
}, []);
const getWiFiList = useCallback(async (deviceId: string): Promise => {
- console.log('[BLEContext] getWiFiList called:', deviceId);
try {
setError(null);
const networks = await bleManager.getWiFiList(deviceId);
- console.log('[BLEContext] getWiFiList success, found networks:', networks.length);
return networks;
} catch (err: any) {
- console.error('[BLEContext] getWiFiList failed:', err);
setError(err.message || 'Failed to get WiFi networks');
throw err;
}
@@ -148,7 +142,6 @@ export function BLEProvider({ children }: { children: ReactNode }) {
const cleanupBLE = useCallback(async () => {
try {
- console.log('[BLEContext] Cleanup called - cleaning up all BLE connections');
// Stop any ongoing scan
if (isScanning) {
@@ -163,9 +156,7 @@ export function BLEProvider({ children }: { children: ReactNode }) {
setConnectedDevices(new Set());
setError(null);
- console.log('[BLEContext] Cleanup complete');
} catch (err: any) {
- console.error('[BLEContext] Cleanup error:', err);
// Don't throw - we want to allow logout to proceed even if BLE cleanup fails
}
}, [isScanning, stopScan]);
diff --git a/hooks/useNavigationFlow.ts b/hooks/useNavigationFlow.ts
index 50dae5e..44fe037 100644
--- a/hooks/useNavigationFlow.ts
+++ b/hooks/useNavigationFlow.ts
@@ -24,7 +24,6 @@ export function useNavigationFlow() {
const navigate = useCallback((result: NavigationResult | null | undefined, replace = false) => {
// Null safety: validate navigation result
if (!result || !result.path) {
- console.warn('[useNavigationFlow] Invalid navigation result:', result);
return;
}
@@ -39,7 +38,6 @@ export function useNavigationFlow() {
router.push(href as any);
}
} catch (error) {
- console.error('[useNavigationFlow] Navigation error:', error);
}
}, [router]);
@@ -135,7 +133,6 @@ export function useNavigationFlow() {
const goToPurchase = useCallback((beneficiaryId: number | null | undefined) => {
// Null safety: only navigate if beneficiaryId is valid
if (!beneficiaryId || typeof beneficiaryId !== 'number') {
- console.warn('[useNavigationFlow] Invalid beneficiaryId for purchase:', beneficiaryId);
return;
}
@@ -148,7 +145,6 @@ export function useNavigationFlow() {
const goToActivate = useCallback((beneficiaryId: number | null | undefined, demo?: boolean) => {
// Null safety: only navigate if beneficiaryId is valid
if (!beneficiaryId || typeof beneficiaryId !== 'number') {
- console.warn('[useNavigationFlow] Invalid beneficiaryId for activation:', beneficiaryId);
return;
}
diff --git a/services/api.ts b/services/api.ts
index 6f37b36..4969017 100644
--- a/services/api.ts
+++ b/services/api.ts
@@ -207,7 +207,6 @@ class ApiService {
try {
await onLogoutBLECleanupCallback();
} catch (error) {
- console.error('[API] BLE cleanup failed during logout:', error);
// Continue with logout even if BLE cleanup fails
}
}
@@ -216,7 +215,6 @@ class ApiService {
try {
await wifiPasswordStore.clearAllWiFiPasswords();
} catch (error) {
- console.error('[API] WiFi password cleanup failed during logout:', error);
// Continue with logout even if cleanup fails
}
@@ -225,7 +223,6 @@ class ApiService {
const { clearEncryptionKey } = await import('./encryption');
await clearEncryptionKey();
} catch (error) {
- console.error('[API] Encryption key cleanup failed during logout:', error);
// Continue with logout even if cleanup fails
}
@@ -1633,7 +1630,6 @@ class ApiService {
if (isValidToken && userName && userId) {
// Check if userName matches expected demo user
if (userName !== this.DEMO_LEGACY_USER) {
- console.log('[API] Legacy credentials mismatch: stored userName', userName, 'expected', this.DEMO_LEGACY_USER);
needsRefresh = true;
}
@@ -1647,13 +1643,11 @@ class ApiService {
if (exp) {
const now = Math.floor(Date.now() / 1000);
if (now >= exp) {
- console.log('[API] Legacy token expired');
needsRefresh = true;
}
}
}
} catch (e) {
- console.log('[API] Failed to decode legacy token, refreshing');
needsRefresh = true;
}
}
@@ -1708,12 +1702,10 @@ class ApiService {
*/
async getDevicesForBeneficiary(beneficiaryId: string) {
try {
- console.log('[API] getDevicesForBeneficiary called:', beneficiaryId);
// Get auth token for WellNuo API
const token = await this.getToken();
if (!token) {
- console.log('[API] getDevicesForBeneficiary: No auth token');
return { ok: false, error: 'Not authenticated' };
}
@@ -1725,23 +1717,19 @@ class ApiService {
},
});
if (!response.ok) {
- console.log('[API] getDevicesForBeneficiary: Failed to get beneficiary, status:', response.status);
throw new Error('Failed to get beneficiary');
}
const beneficiary = await response.json();
const deploymentId = beneficiary.deploymentId;
- console.log('[API] getDevicesForBeneficiary: beneficiary data:', { deploymentId, name: beneficiary.firstName });
if (!deploymentId) {
- console.log('[API] getDevicesForBeneficiary: No deploymentId, returning empty');
return { ok: true, data: [] }; // No deployment = no devices
}
// Get Legacy API credentials
const creds = await this.getLegacyCredentials();
if (!creds) {
- console.log('[API] getDevicesForBeneficiary: No Legacy API credentials');
return { ok: false, error: 'Not authenticated with Legacy API' };
}
@@ -1755,7 +1743,6 @@ class ApiService {
last: '100',
});
- console.log('[API] getDevicesForBeneficiary: Calling Legacy API device_list_by_deployment for deployment:', deploymentId);
const devicesResponse = await fetch(this.legacyApiUrl, {
method: 'POST',
@@ -1764,19 +1751,15 @@ class ApiService {
});
if (!devicesResponse.ok) {
- console.log('[API] getDevicesForBeneficiary: Legacy API HTTP error:', devicesResponse.status);
throw new Error('Failed to fetch devices from Legacy API');
}
const devicesData = await devicesResponse.json();
- console.log('[API] getDevicesForBeneficiary: Legacy API response:', JSON.stringify(devicesData).substring(0, 500));
if (!devicesData.result_list || devicesData.result_list.length === 0) {
- console.log('[API] getDevicesForBeneficiary: No devices in result_list');
return { ok: true, data: [] };
}
- console.log('[API] getDevicesForBeneficiary: Found', devicesData.result_list.length, 'devices');
// Get online status
const onlineDevices = await this.getOnlineDevices(deploymentId);
@@ -1895,15 +1878,12 @@ class ApiService {
password: string
) {
try {
- console.log('[API] attachDeviceToBeneficiary called:', { beneficiaryId, wellId, ssid });
// Get auth token for WellNuo API
const token = await this.getToken();
if (!token) {
- console.error('[API] No auth token');
throw new Error('Not authenticated');
}
- console.log('[API] Got auth token');
// Get beneficiary details
const response = await fetch(`${this.baseUrl}/me/beneficiaries/${beneficiaryId}`, {
@@ -1912,29 +1892,23 @@ class ApiService {
'Authorization': `Bearer ${token}`,
},
});
- console.log('[API] Beneficiary response status:', response.status);
if (!response.ok) {
const errorText = await response.text();
- console.error('[API] Failed to get beneficiary:', errorText);
throw new Error(`Failed to get beneficiary: ${response.status}`);
}
const beneficiary = await response.json();
const deploymentId = beneficiary.deploymentId;
const beneficiaryName = beneficiary.firstName || 'Sensor';
- console.log('[API] Beneficiary data:', { deploymentId, firstName: beneficiary.firstName, beneficiaryName });
if (!deploymentId) {
- console.error('[API] Beneficiary has no deploymentId');
throw new Error('No deployment configured for this beneficiary. Please remove and re-add the beneficiary to fix this.');
}
const creds = await this.getLegacyCredentials();
if (!creds) {
- console.error('[API] No Legacy API credentials');
throw new Error('Not authenticated with Legacy API');
}
- console.log('[API] Got Legacy credentials for user:', creds.userName, 'token prefix:', creds.token.substring(0, 30));
// Use device_form to attach device to deployment
// Note: set_deployment now requires beneficiary_photo and email which we don't have
@@ -1946,36 +1920,26 @@ class ApiService {
device_id: wellId.toString(),
deployment: deploymentId.toString(),
});
- console.log('[API] Calling Legacy API device_form:', {
- device_id: wellId,
- deployment: deploymentId,
- });
const attachResponse = await fetch(this.legacyApiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: formData.toString(),
});
- console.log('[API] Legacy API response status:', attachResponse.status);
if (!attachResponse.ok) {
const errorText = await attachResponse.text();
- console.error('[API] Legacy API HTTP error:', errorText);
throw new Error(`Failed to attach device: HTTP ${attachResponse.status}`);
}
const data = await attachResponse.json();
- console.log('[API] Legacy API response data:', JSON.stringify(data).substring(0, 500));
if (data.status !== '200 OK') {
- console.error('[API] Legacy API error:', data.status, data.message);
throw new Error(data.message || `Legacy API error: ${data.status}`);
}
- console.log('[API] Device attached successfully');
return { ok: true };
} catch (error: any) {
- console.error('[API] attachDeviceToBeneficiary error:', error.message);
return { ok: false, error: error.message };
}
}
@@ -2012,7 +1976,6 @@ class ApiService {
formData.append('location', legacyCode.toString());
} else {
// If location ID not found, log warning but don't fail
- console.warn(`Unknown location ID: ${updates.location}, skipping location update`);
}
}
if (updates.description !== undefined) {
diff --git a/services/ble/BLEManager.ts b/services/ble/BLEManager.ts
index 23dca66..ece968f 100644
--- a/services/ble/BLEManager.ts
+++ b/services/ble/BLEManager.ts
@@ -13,7 +13,6 @@ export class RealBLEManager implements IBLEManager {
// Lazy initialization to prevent crash on app startup
private get manager(): BleManager {
if (!this._manager) {
- console.log('[BLE] Initializing BleManager (lazy)...');
this._manager = new BleManager();
}
return this._manager;
@@ -21,7 +20,6 @@ export class RealBLEManager implements IBLEManager {
constructor() {
// Don't initialize BleManager here - use lazy initialization
- console.log('[BLE] RealBLEManager created (BleManager will be initialized on first use)');
}
// Check and request permissions
@@ -123,69 +121,47 @@ export class RealBLEManager implements IBLEManager {
}
async connectDevice(deviceId: string): Promise {
- console.log('[BLE] connectDevice started:', deviceId);
try {
// Step 0: Check permissions (required for Android 12+)
- console.log('[BLE] Step 0: Checking permissions...');
const hasPermission = await this.requestPermissions();
if (!hasPermission) {
- console.error('[BLE] Permissions not granted!');
throw new Error('Bluetooth permissions not granted');
}
- console.log('[BLE] Permissions OK');
// Step 0.5: Check Bluetooth is enabled
- console.log('[BLE] Checking Bluetooth state...');
const isEnabled = await this.isBluetoothEnabled();
if (!isEnabled) {
- console.error('[BLE] Bluetooth is disabled!');
throw new Error('Bluetooth is disabled. Please enable it in settings.');
}
- console.log('[BLE] Bluetooth is ON');
// Check if already connected
const existingDevice = this.connectedDevices.get(deviceId);
if (existingDevice) {
- console.log('[BLE] Checking existing connection...');
const isConnected = await existingDevice.isConnected();
if (isConnected) {
- console.log('[BLE] Device already connected:', deviceId);
return true;
}
// Device was in map but disconnected, remove it
- console.log('[BLE] Removing stale connection from map:', deviceId);
this.connectedDevices.delete(deviceId);
}
- console.log('[BLE] Calling manager.connectToDevice with 10s timeout...');
const device = await this.manager.connectToDevice(deviceId, {
timeout: 10000, // 10 second timeout
});
- console.log('[BLE] Connected! Discovering services and characteristics...');
await device.discoverAllServicesAndCharacteristics();
- console.log('[BLE] Services discovered');
// Request larger MTU for Android (default is 23 bytes which is too small)
if (Platform.OS === 'android') {
try {
const mtu = await device.requestMTU(512);
- console.log('[BLE] MTU negotiated:', mtu);
} catch (mtuError) {
- console.warn('[BLE] MTU negotiation failed (non-critical):', mtuError);
}
}
this.connectedDevices.set(deviceId, device);
- console.log('[BLE] connectDevice SUCCESS:', deviceId);
return true;
} catch (error: any) {
- console.error('[BLE] connectDevice FAILED:', deviceId, {
- message: error?.message,
- errorCode: error?.errorCode,
- reason: error?.reason,
- stack: error?.stack?.substring(0, 200),
- });
return false;
}
}
@@ -199,7 +175,6 @@ export class RealBLEManager implements IBLEManager {
await device.cancelConnection();
} catch (error: any) {
// Log but don't throw - device may already be disconnected
- console.warn('[BLE] disconnectDevice error (ignored):', error?.message);
} finally {
this.connectedDevices.delete(deviceId);
}
@@ -211,11 +186,9 @@ export class RealBLEManager implements IBLEManager {
}
async sendCommand(deviceId: string, command: string): Promise {
- console.log('[BLE] sendCommand:', { deviceId, command });
const device = this.connectedDevices.get(deviceId);
if (!device) {
- console.error('[BLE] sendCommand FAILED: Device not in connected map');
throw new Error('Device not connected');
}
@@ -223,12 +196,10 @@ export class RealBLEManager implements IBLEManager {
try {
const isConnected = await device.isConnected();
if (!isConnected) {
- console.error('[BLE] sendCommand FAILED: Device disconnected');
this.connectedDevices.delete(deviceId);
throw new Error('Device disconnected');
}
} catch (checkError: any) {
- console.error('[BLE] Failed to check connection status:', checkError?.message);
throw new Error('Failed to verify connection');
}
@@ -246,12 +217,10 @@ export class RealBLEManager implements IBLEManager {
timeoutId = null;
}
if (subscription) {
- console.log('[BLE] Cleaning up notification subscription');
try {
subscription.remove();
} catch (removeError) {
// Ignore errors during cleanup - device may already be disconnected
- console.log('[BLE] Subscription cleanup error (ignored):', removeError);
}
subscription = null;
}
@@ -268,7 +237,6 @@ export class RealBLEManager implements IBLEManager {
// This happens when subscription is removed but BLE still tries to send callback
if (errorCode === 2 || errorCode === 'OperationCancelled' ||
(error?.message && error.message.includes('cancelled'))) {
- console.log('[BLE] Ignoring cancelled operation (normal cleanup)');
return;
}
@@ -283,7 +251,6 @@ export class RealBLEManager implements IBLEManager {
try {
// Subscribe to notifications with explicit transactionId
- console.log('[BLE] Setting up notification listener with transactionId:', transactionId);
subscription = device.monitorCharacteristicForService(
BLE_CONFIG.SERVICE_UUID,
BLE_CONFIG.CHAR_UUID,
@@ -294,13 +261,8 @@ export class RealBLEManager implements IBLEManager {
const errCode = (error as any)?.errorCode;
// errorCode 2 = "Operation was cancelled" — normal BLE cleanup, not a real error
if (errCode === 2) {
- console.log('[BLE] Notification cancelled (normal cleanup)');
} else {
- console.error('[BLE] Notification error:', {
- message: error?.message || 'null',
- errorCode: errCode || 'null',
- reason: (error as any)?.reason || 'null',
- });
+ // Notification error
}
safeReject(error);
return;
@@ -308,7 +270,6 @@ export class RealBLEManager implements IBLEManager {
if (characteristic?.value) {
const decoded = base64.decode(characteristic.value);
- console.log('[BLE] Response received:', decoded.substring(0, 100));
if (!responseReceived) {
responseReceived = true;
cleanup();
@@ -316,7 +277,6 @@ export class RealBLEManager implements IBLEManager {
}
}
} catch (callbackError: any) {
- console.error('[BLE] Callback exception:', callbackError?.message);
safeReject(callbackError);
}
},
@@ -325,47 +285,34 @@ export class RealBLEManager implements IBLEManager {
// Send command
const encoded = base64.encode(command);
- console.log('[BLE] Writing command to characteristic...');
await device.writeCharacteristicWithResponseForService(
BLE_CONFIG.SERVICE_UUID,
BLE_CONFIG.CHAR_UUID,
encoded
);
- console.log('[BLE] Command written successfully');
// Timeout
timeoutId = setTimeout(() => {
if (!responseReceived) {
- console.error('[BLE] Command timeout after', BLE_CONFIG.COMMAND_TIMEOUT, 'ms');
safeReject(new Error('Command timeout'));
}
}, BLE_CONFIG.COMMAND_TIMEOUT);
} catch (error: any) {
- console.error('[BLE] sendCommand exception:', {
- message: error?.message,
- errorCode: error?.errorCode,
- });
safeReject(error);
}
});
}
async getWiFiList(deviceId: string): Promise {
- console.log('[BLE] getWiFiList started for:', deviceId);
// Step 1: Unlock device
- console.log('[BLE] Step 1: Unlocking device...');
const unlockResponse = await this.sendCommand(deviceId, BLE_COMMANDS.PIN_UNLOCK);
- console.log('[BLE] Unlock response:', unlockResponse);
if (!unlockResponse.includes('ok')) {
- console.error('[BLE] Unlock FAILED - response does not contain "ok"');
throw new Error('Failed to unlock device');
}
// Step 2: Get WiFi list
- console.log('[BLE] Step 2: Getting WiFi list...');
const listResponse = await this.sendCommand(deviceId, BLE_COMMANDS.GET_WIFI_LIST);
- console.log('[BLE] WiFi list response:', listResponse);
// Parse response: "mac,XXXXXX|w|COUNT|SSID1,RSSI1|SSID2,RSSI2|..."
const parts = listResponse.split('|');
@@ -410,54 +357,40 @@ export class RealBLEManager implements IBLEManager {
}
async setWiFi(deviceId: string, ssid: string, password: string): Promise {
- console.log('[BLE] setWiFi started:', { deviceId, ssid, passwordLength: password.length });
// Step 1: Unlock device
- console.log('[BLE] Step 1: Unlocking device for WiFi config...');
const unlockResponse = await this.sendCommand(deviceId, BLE_COMMANDS.PIN_UNLOCK);
- console.log('[BLE] Unlock response:', unlockResponse);
if (!unlockResponse.includes('ok')) {
throw new Error(`Device unlock failed: ${unlockResponse}`);
}
// Step 1.5: Check if already connected to the target WiFi
// This prevents "W|fail" when sensor uses old saved credentials
- console.log('[BLE] === BLE FIX v2 ACTIVE (2026-01-27) ===');
- console.log('[BLE] Step 1.5: Checking current WiFi status...');
try {
const statusResponse = await this.sendCommand(deviceId, BLE_COMMANDS.GET_WIFI_STATUS);
- console.log('[BLE] Current WiFi status:', statusResponse);
// Parse: "mac,XXXXXX|a|SSID,RSSI" or "mac,XXXXXX|a|,0" (not connected)
const parts = statusResponse.split('|');
if (parts.length >= 3) {
const [currentSsid] = parts[2].split(',');
if (currentSsid && currentSsid.trim().toLowerCase() === ssid.toLowerCase()) {
- console.log('[BLE] Sensor is ALREADY connected to target WiFi:', ssid);
- console.log('[BLE] Skipping W| command - returning success');
return true;
}
- console.log('[BLE] Sensor connected to different network or not connected:', currentSsid || 'none');
}
} catch (statusError) {
- console.warn('[BLE] Failed to check WiFi status, continuing with config:', statusError);
}
// Step 2: Set WiFi credentials
const command = `${BLE_COMMANDS.SET_WIFI}|${ssid},${password}`;
- console.log('[BLE] Step 2: Sending WiFi credentials...');
const setResponse = await this.sendCommand(deviceId, command);
- console.log('[BLE] WiFi config response:', setResponse);
// Parse response: "mac,XXXXXX|W|ok" or "mac,XXXXXX|W|fail" or other errors
if (setResponse.includes('|W|ok')) {
- console.log('[BLE] WiFi configuration SUCCESS');
return true;
}
// WiFi config failed - check if sensor is still connected (using old credentials)
if (setResponse.includes('|W|fail')) {
- console.log('[BLE] W|fail received. Checking if sensor still connected to WiFi...');
try {
const recheckResponse = await this.sendCommand(deviceId, BLE_COMMANDS.GET_WIFI_STATUS);
@@ -468,13 +401,10 @@ export class RealBLEManager implements IBLEManager {
// If connected to target SSID (using old credentials), consider it success
if (currentSsid && currentSsid.trim().toLowerCase() === ssid.toLowerCase() && rssi < 0) {
- console.log('[BLE] Sensor IS connected to target WiFi (using saved credentials):', currentSsid, 'RSSI:', rssi);
- console.log('[BLE] Password may be wrong but sensor works - returning success');
return true;
}
}
} catch (recheckError) {
- console.warn('[BLE] Failed to recheck WiFi status after W|fail');
}
throw new Error('WiFi credentials rejected by sensor. Check password.');
@@ -532,7 +462,6 @@ export class RealBLEManager implements IBLEManager {
* Should be called on app logout to properly release resources
*/
async cleanup(): Promise {
- console.log('[BLE] Cleanup: disconnecting all devices');
// Stop any ongoing scan
if (this.scanning) {
@@ -545,7 +474,6 @@ export class RealBLEManager implements IBLEManager {
try {
await this.disconnectDevice(deviceId);
} catch (error) {
- console.warn('[BLE] Cleanup: error disconnecting device', deviceId, error);
// Continue cleanup even if one device fails
}
}
@@ -553,6 +481,5 @@ export class RealBLEManager implements IBLEManager {
// Clear the map
this.connectedDevices.clear();
- console.log('[BLE] Cleanup: complete');
}
}
diff --git a/services/ble/MockBLEManager.ts b/services/ble/MockBLEManager.ts
index c65db2b..3197ae5 100644
--- a/services/ble/MockBLEManager.ts
+++ b/services/ble/MockBLEManager.ts
@@ -24,24 +24,20 @@ export class MockBLEManager implements IBLEManager {
];
async scanDevices(): Promise {
- console.log('[MockBLE] Scanning for devices...');
await delay(2000); // Simulate scan delay
return this.mockDevices;
}
stopScan(): void {
- console.log('[MockBLE] Scan stopped');
}
async connectDevice(deviceId: string): Promise {
- console.log(`[MockBLE] Connecting to ${deviceId}...`);
await delay(1000);
this.connectedDevices.add(deviceId);
return true;
}
async disconnectDevice(deviceId: string): Promise {
- console.log(`[MockBLE] Disconnecting ${deviceId}`);
await delay(500);
this.connectedDevices.delete(deviceId);
}
@@ -51,7 +47,6 @@ export class MockBLEManager implements IBLEManager {
}
async sendCommand(deviceId: string, command: string): Promise {
- console.log(`[MockBLE] Sending command: ${command}`);
await delay(500);
// Simulate responses
@@ -72,7 +67,6 @@ export class MockBLEManager implements IBLEManager {
}
async getWiFiList(deviceId: string): Promise {
- console.log(`[MockBLE] Getting WiFi list for ${deviceId}`);
await delay(1500);
return [
@@ -88,13 +82,11 @@ export class MockBLEManager implements IBLEManager {
ssid: string,
password: string
): Promise {
- console.log(`[MockBLE] Setting WiFi: ${ssid}`);
await delay(2000);
return true;
}
async getCurrentWiFi(deviceId: string): Promise {
- console.log(`[MockBLE] Getting current WiFi for ${deviceId}`);
await delay(1000);
return {
@@ -105,7 +97,6 @@ export class MockBLEManager implements IBLEManager {
}
async rebootDevice(deviceId: string): Promise {
- console.log(`[MockBLE] Rebooting ${deviceId}`);
await delay(500);
this.connectedDevices.delete(deviceId);
}
@@ -115,7 +106,6 @@ export class MockBLEManager implements IBLEManager {
* Should be called on app logout to properly release resources
*/
async cleanup(): Promise {
- console.log('[MockBLE] Cleanup: disconnecting all devices');
// Disconnect all connected devices
const deviceIds = Array.from(this.connectedDevices);
@@ -124,6 +114,5 @@ export class MockBLEManager implements IBLEManager {
}
this.connectedDevices.clear();
- console.log('[MockBLE] Cleanup: complete');
}
}
diff --git a/services/ble/index.ts b/services/ble/index.ts
index 3f6488d..906cfae 100644
--- a/services/ble/index.ts
+++ b/services/ble/index.ts
@@ -11,7 +11,6 @@ let _bleManager: IBLEManager | null = null;
function getBLEManager(): IBLEManager {
if (!_bleManager) {
- console.log('[BLE] Creating BLEManager instance (lazy)...');
// Dynamic import to prevent crash on Android startup
if (isBLEAvailable) {
const { RealBLEManager } = require('./BLEManager');
diff --git a/services/encryption.ts b/services/encryption.ts
index d75f7cf..81b644c 100644
--- a/services/encryption.ts
+++ b/services/encryption.ts
@@ -41,7 +41,6 @@ async function getMasterKey(): Promise {
return newKey;
} catch (error) {
- console.error('[Encryption] Failed to get/generate master key:', error);
throw new Error('Failed to initialize encryption key');
}
}
@@ -69,7 +68,6 @@ async function deriveKey(masterKey: Uint8Array, salt: Uint8Array): Promise {
// Return as base64
return Buffer.from(combined).toString('base64');
} catch (error) {
- console.error('[Encryption] Encryption failed:', error);
throw new Error('Failed to encrypt data');
}
}
@@ -193,7 +190,6 @@ export async function decrypt(ciphertext: string): Promise {
// Convert to string
return new TextDecoder().decode(decrypted);
} catch (error) {
- console.error('[Encryption] Decryption failed:', error);
throw new Error('Failed to decrypt data');
}
}
@@ -221,9 +217,7 @@ export function isEncrypted(data: string): boolean {
export async function clearEncryptionKey(): Promise {
try {
await SecureStore.deleteItemAsync(ENCRYPTION_KEY_NAME);
- console.log('[Encryption] Master key cleared');
} catch (error) {
- console.error('[Encryption] Failed to clear master key:', error);
throw error;
}
}
diff --git a/services/pushNotifications.ts b/services/pushNotifications.ts
index b8b4cee..3488719 100644
--- a/services/pushNotifications.ts
+++ b/services/pushNotifications.ts
@@ -37,7 +37,6 @@ export async function registerForPushNotificationsAsync(): Promise {
const accessToken = await SecureStore.getItemAsync('accessToken');
if (!accessToken) {
- console.log('[Push] No access token, skipping server registration');
return false;
}
@@ -126,14 +121,11 @@ export async function registerTokenOnServer(token: string): Promise {
if (!response.ok) {
const error = await response.json();
- console.error('[Push] Server registration failed:', error);
return false;
}
- console.log('[Push] Token registered on server successfully');
return true;
} catch (error) {
- console.error('[Push] Error registering token on server:', error);
return false;
}
}
@@ -163,14 +155,11 @@ export async function unregisterToken(): Promise {
await SecureStore.deleteItemAsync(PUSH_TOKEN_KEY);
if (!response.ok) {
- console.error('[Push] Server unregistration failed');
return false;
}
- console.log('[Push] Token unregistered successfully');
return true;
} catch (error) {
- console.error('[Push] Error unregistering token:', error);
// Still clear local storage
await SecureStore.deleteItemAsync(PUSH_TOKEN_KEY);
return false;
@@ -182,7 +171,6 @@ export async function unregisterToken(): Promise {
* Call this after successful login
*/
export async function setupPushNotifications(): Promise {
- console.log('[Push] Setting up push notifications...');
const token = await registerForPushNotificationsAsync();
diff --git a/services/sherpaTTS.ts b/services/sherpaTTS.ts
index 2233e38..5d384d6 100644
--- a/services/sherpaTTS.ts
+++ b/services/sherpaTTS.ts
@@ -139,11 +139,9 @@ async function copyModelToDocuments(voice: PiperVoice): Promise {
// Check if already copied
const onnxInfo = await FileSystem.getInfoAsync(onnxPath);
if (onnxInfo.exists) {
- console.log('[SherpaTTS] Model already exists at:', destDir);
return destDir;
}
- console.log('[SherpaTTS] Copying model to documents directory...');
// Create destination directory
await FileSystem.makeDirectoryAsync(destDir, { intermediates: true });
@@ -178,11 +176,9 @@ async function copyModelToDocuments(voice: PiperVoice): Promise {
await FileSystem.makeDirectoryAsync(espeakDestDir, { intermediates: true });
// For now, we'll use the bundle path directly on iOS
- console.log('[SherpaTTS] Model copied successfully');
return destDir;
} catch (error) {
- console.error('[SherpaTTS] Error copying model:', error);
return null;
}
*/
diff --git a/services/wifiPasswordStore.ts b/services/wifiPasswordStore.ts
index db89a7d..f8cbd89 100644
--- a/services/wifiPasswordStore.ts
+++ b/services/wifiPasswordStore.ts
@@ -34,9 +34,7 @@ export async function saveWiFiPassword(ssid: string, password: string): Promise<
// Save back to SecureStore
await SecureStore.setItemAsync(WIFI_PASSWORDS_KEY, JSON.stringify(existing));
- console.log('[WiFiPasswordStore] Encrypted password saved for network:', ssid);
} catch (error) {
- console.error('[WiFiPasswordStore] Failed to save password:', error);
throw error;
}
}
@@ -59,7 +57,6 @@ export async function getWiFiPassword(ssid: string): Promise
const decryptedPassword = await decrypt(encryptedPassword);
return decryptedPassword;
} catch (error) {
- console.error('[WiFiPasswordStore] Failed to get password:', error);
return undefined;
}
}
@@ -79,7 +76,6 @@ async function getAllWiFiPasswordsEncrypted(): Promise {
return {};
} catch (error) {
- console.error('[WiFiPasswordStore] Failed to get all passwords:', error);
return {};
}
}
@@ -98,14 +94,12 @@ export async function getAllWiFiPasswords(): Promise {
try {
decryptedPasswords[ssid] = await decrypt(encryptedPassword);
} catch (error) {
- console.error(`[WiFiPasswordStore] Failed to decrypt password for ${ssid}:`, error);
// Skip this password if decryption fails
}
}
return decryptedPasswords;
} catch (error) {
- console.error('[WiFiPasswordStore] Failed to get all passwords:', error);
return {};
}
}
@@ -129,9 +123,7 @@ export async function removeWiFiPassword(ssid: string): Promise {
await SecureStore.deleteItemAsync(WIFI_PASSWORDS_KEY);
}
- console.log('[WiFiPasswordStore] Password removed for network:', ssid);
} catch (error) {
- console.error('[WiFiPasswordStore] Failed to remove password:', error);
throw error;
}
}
@@ -143,9 +135,7 @@ export async function removeWiFiPassword(ssid: string): Promise {
export async function clearAllWiFiPasswords(): Promise {
try {
await SecureStore.deleteItemAsync(WIFI_PASSWORDS_KEY);
- console.log('[WiFiPasswordStore] All WiFi passwords cleared');
} catch (error) {
- console.error('[WiFiPasswordStore] Failed to clear passwords:', error);
throw error;
}
}
@@ -159,7 +149,6 @@ export async function migrateToEncrypted(): Promise {
const stored = await SecureStore.getItemAsync(WIFI_PASSWORDS_KEY);
if (!stored) {
- console.log('[WiFiPasswordStore] No passwords to migrate');
return;
}
@@ -182,12 +171,9 @@ export async function migrateToEncrypted(): Promise {
// Save back if any were migrated
if (migrated > 0) {
await SecureStore.setItemAsync(WIFI_PASSWORDS_KEY, JSON.stringify(encryptedPasswords));
- console.log(`[WiFiPasswordStore] Successfully migrated ${migrated} passwords to encrypted format`);
} else {
- console.log('[WiFiPasswordStore] All passwords already encrypted');
}
} catch (error) {
- console.error('[WiFiPasswordStore] Migration to encrypted format failed:', error);
// Don't throw - migration failure shouldn't break the app
}
}
@@ -204,7 +190,6 @@ export async function migrateFromAsyncStorage(): Promise {
// Check if migration already done
const existing = await SecureStore.getItemAsync(WIFI_PASSWORDS_KEY);
if (existing) {
- console.log('[WiFiPasswordStore] Migration from AsyncStorage already completed');
// Still run encryption migration in case they were migrated but not encrypted
await migrateToEncrypted();
return;
@@ -229,12 +214,9 @@ export async function migrateFromAsyncStorage(): Promise {
await AsyncStorage.removeItem('WIFI_PASSWORDS');
await AsyncStorage.removeItem(LEGACY_SINGLE_PASSWORD_KEY);
- console.log('[WiFiPasswordStore] Successfully migrated and encrypted passwords from AsyncStorage');
} else {
- console.log('[WiFiPasswordStore] No passwords to migrate from AsyncStorage');
}
} catch (error) {
- console.error('[WiFiPasswordStore] Migration from AsyncStorage failed:', error);
// Don't throw - migration failure shouldn't break the app
}
}