fix(ble): bmsManualRead reconecta GATT antes do probe v1.10.5
Some checks are pending
Build Android (APK + AAB) / build-android (push) Waiting to run
Some checks are pending
Build Android (APK + AAB) / build-android (push) Waiting to run
Bug v1.10.4: clicar 🔄 Re-ler gerava 'getServices erro: Bluetooth LE not initialized' porque Android desconecta GATT em background pra economizar bateria, mas state.btDevices ainda mostra 'conectado'. Fix: bmsManualRead agora faz 3 passos sequenciais com diagnóstico: 1. ensureBleNativeReady() — garante plugin inicializado 2. ble.connect({deviceId, timeout:15000}) — reconecta GATT (silent se 'already connected') 3. bmsProbeAndAttach() — probe completo Cada passo emite log próprio: "Plugin init OK", "GATT reconectado" ou "GATT já conectado", "🔍 Enumerando characteristics..." Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
840f0b0dc5
commit
2fca191676
5 changed files with 50 additions and 14 deletions
|
|
@ -6125,12 +6125,30 @@ async function bmsQueryBasic(deviceId,withoutResponse){
|
|||
await bmsWriteCmd(deviceId,BMS_CMD_BASIC,withoutResponse);
|
||||
}
|
||||
|
||||
// Re-leitura manual a partir do botão UI
|
||||
// Re-leitura manual: garante init + reconecta GATT + roda probe
|
||||
async function bmsManualRead(deviceId){
|
||||
setBleDiag('🔄 Re-leitura manual · re-rodando probe completo...','info');
|
||||
setBleDiag('🔄 Re-leitura manual','info');
|
||||
const dev=state.btDevices?.find(d=>d.id===deviceId);
|
||||
const deviceName=dev?.name||'BMS';
|
||||
try{
|
||||
// Re-roda probe completo (lista chars de novo + tenta protocolos)
|
||||
await bmsProbeAndAttach(deviceId,state.btDevices?.find(d=>d.id===deviceId)?.name||'BMS');
|
||||
// 1. Garante plugin inicializado
|
||||
await ensureBleNativeReady();
|
||||
setBleDiag('Plugin init OK','info');
|
||||
// 2. Reconecta GATT (Android pode ter desconectado em background)
|
||||
const ble=window.Capacitor?.Plugins?.BluetoothLe;
|
||||
if(ble){
|
||||
try{
|
||||
await ble.connect({deviceId,timeout:15000});
|
||||
setBleDiag('GATT reconectado','ok');
|
||||
await new Promise(r=>setTimeout(r,500));
|
||||
}catch(e){
|
||||
const msg=e.message||e.errorMessage||'?';
|
||||
if(/already/i.test(msg))setBleDiag('GATT já conectado','info');
|
||||
else setBleDiag('Reconnect erro: '+msg,'warn');
|
||||
}
|
||||
}
|
||||
// 3. Roda probe completo
|
||||
await bmsProbeAndAttach(deviceId,deviceName);
|
||||
}catch(e){setBleDiag('Manual read falhou: '+(e.message||e.errorMessage),'err')}
|
||||
}
|
||||
|
||||
|
|
@ -6247,7 +6265,7 @@ async function removeBluetoothDevice(id){
|
|||
renderBluetoothCard();
|
||||
}
|
||||
|
||||
const APP_VERSION='1.10.4';
|
||||
const APP_VERSION='1.10.5';
|
||||
function renderBluetoothCard(){
|
||||
const el=document.getElementById('bt-list');
|
||||
const supportEl=document.getElementById('bt-support');
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ android {
|
|||
applicationId "br.com.pontualtech.shivao"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 20
|
||||
versionName "1.10.4"
|
||||
versionCode 21
|
||||
versionName "1.10.5"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "shivao-mobile",
|
||||
"version": "1.10.4",
|
||||
"version": "1.10.5",
|
||||
"description": "Shivao app nativo (Capacitor wrapper Android/iOS)",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
|
|
|
|||
|
|
@ -6125,12 +6125,30 @@ async function bmsQueryBasic(deviceId,withoutResponse){
|
|||
await bmsWriteCmd(deviceId,BMS_CMD_BASIC,withoutResponse);
|
||||
}
|
||||
|
||||
// Re-leitura manual a partir do botão UI
|
||||
// Re-leitura manual: garante init + reconecta GATT + roda probe
|
||||
async function bmsManualRead(deviceId){
|
||||
setBleDiag('🔄 Re-leitura manual · re-rodando probe completo...','info');
|
||||
setBleDiag('🔄 Re-leitura manual','info');
|
||||
const dev=state.btDevices?.find(d=>d.id===deviceId);
|
||||
const deviceName=dev?.name||'BMS';
|
||||
try{
|
||||
// Re-roda probe completo (lista chars de novo + tenta protocolos)
|
||||
await bmsProbeAndAttach(deviceId,state.btDevices?.find(d=>d.id===deviceId)?.name||'BMS');
|
||||
// 1. Garante plugin inicializado
|
||||
await ensureBleNativeReady();
|
||||
setBleDiag('Plugin init OK','info');
|
||||
// 2. Reconecta GATT (Android pode ter desconectado em background)
|
||||
const ble=window.Capacitor?.Plugins?.BluetoothLe;
|
||||
if(ble){
|
||||
try{
|
||||
await ble.connect({deviceId,timeout:15000});
|
||||
setBleDiag('GATT reconectado','ok');
|
||||
await new Promise(r=>setTimeout(r,500));
|
||||
}catch(e){
|
||||
const msg=e.message||e.errorMessage||'?';
|
||||
if(/already/i.test(msg))setBleDiag('GATT já conectado','info');
|
||||
else setBleDiag('Reconnect erro: '+msg,'warn');
|
||||
}
|
||||
}
|
||||
// 3. Roda probe completo
|
||||
await bmsProbeAndAttach(deviceId,deviceName);
|
||||
}catch(e){setBleDiag('Manual read falhou: '+(e.message||e.errorMessage),'err')}
|
||||
}
|
||||
|
||||
|
|
@ -6247,7 +6265,7 @@ async function removeBluetoothDevice(id){
|
|||
renderBluetoothCard();
|
||||
}
|
||||
|
||||
const APP_VERSION='1.10.4';
|
||||
const APP_VERSION='1.10.5';
|
||||
function renderBluetoothCard(){
|
||||
const el=document.getElementById('bt-list');
|
||||
const supportEl=document.getElementById('bt-support');
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ app.get('/.well-known/assetlinks.json', (req, res) => {
|
|||
});
|
||||
|
||||
// Atalho: /apk redireciona pra última APK release no Forgejo
|
||||
const LATEST_APK_URL = 'https://git.pontualtech.work/karlao/shivao-projeto/releases/download/v1.10.4/Shivao-v1.10.4.apk';
|
||||
const LATEST_APK_URL = 'https://git.pontualtech.work/karlao/shivao-projeto/releases/download/v1.10.5/Shivao-v1.10.5.apk';
|
||||
app.get('/apk', (req, res) => res.redirect(302, LATEST_APK_URL));
|
||||
|
||||
// Página A4 imprimível com QR Code + instruções (cola no barco/marina)
|
||||
|
|
|
|||
Loading…
Reference in a new issue