#mja123_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1266111386312769570
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- mja123_code, 2 days ago, 29 messages
not updating the state to connected
Can you say more about this? What are you checking and expecting to find? WHat is actually happening?
const handleConnectBluetoothReader = async (
_reader: Reader.Type,
autoConnecting?: boolean,
) => {
try {
setReaderConnecting(true);
if (readerConnecting) {
return;
}
if (connectedReader) {
await disconnectReader();
}
await location.refetch();
if (location.error) {
setToast({
visible: true,
message: 'Could not get location',
type: 'error',
});
throw new Error(JSON.stringify(location.error));
}
Sentry.captureMessage('Location ' + JSON.stringify(location.data));
const { reader, error } = await connectBluetoothReader({
reader: _reader,
locationId: location.data?.data.stripe_id,
});
Sentry.captureMessage('Connected reader ' + JSON.stringify(reader));
if (error) {
setReaderConnecting(false);
console.log('connectBluetoothReader error', error);
setToast({
visible: true,
message: 'Could not connect to reader',
type: 'error',
});
throw new Error(JSON.stringify(error));
}
saveDeviceSerialNumber(reader.serialNumber);
setReaderConnecting(false);
setReaderConnecting should run after the device is connected, it runs when connecting to a simulated reader but not in case of a real reader
What is the reader you get back from connectBluetoothReader?
it doesnt return any value when connecting to a real reader
Then it seems like a different problem
Is your discovery step returning your reader?
Based on what, how are you checking/validating that?
upon closing the app, the device says disconnected
also if we only reload the js bundle and not the whole app, upon starting it says connected to the reader
Can you share your discovery code that runs before the connection attempt?
const handleDiscoverReaders = async () => {
if (bluetoothStatus !== 'PoweredOn') {
return;
}
const granted = await requestNeededAndroidPermissions({
accessFineLocation: {
title: 'Location permission',
message: 'Location permission is required to discover readers',
buttonPositive: 'Allow',
},
});
if (!granted) {
setToast({
visible: true,
message: 'Location permission is required to discover readers',
type: 'error',
});
return;
}
console.log('Discovering readers');
if (isDiscovering) {
return;
}
setIsDiscovering(true);
const { error } = await discoverReaders({
discoveryMethod: 'bluetoothScan',
// simulated: true,
});
if (error) {
setToast({
visible: true,
message: 'Could not discover readers',
type: 'error',
});
throw new Error(JSON.stringify(error));
}
};
const {
discoverReaders,
connectBluetoothReader,
disconnectReader,
connectedReader,
isInitialized,
discoveredReaders,
cancelDiscovering,
} = useStripeTerminal({
onUpdateDiscoveredReaders: (_devices) => {
setDevices(_devices);
Sentry.captureMessage('Discovered readers ' + JSON.stringify(devices));
setIsDiscovering(false);
},
onDidDisconnect(reason) {
console.log('Disconnected', reason);
},
onDidChangeConnectionStatus(status) {
console.log('Connection status', status);
Sentry.captureMessage('Connection status ' + JSON.stringify(status));
},
});
Something seems to be missing here
Are you reaching your handleConnectBluetoothReader and able to see your sentry logs from that?
yes
This should return a connected reader or an error:
const { reader, error } = await connectBluetoothReader({
reader: _reader,
locationId: location.data?.data.stripe_id,
});
yes, and it does when connecting to a simulated device but not on a real device
it gets stuck on this loading state until, the js bundle is refreshed and useEffect hook that has the sdk initialize fn runs
Actually, this might be related to required updates
Can you add the handlers for start/finish update installs described here?
In your onDidChangeConnectionStatus are you seeing connecting as that indicates?
didn't checked connection status though
thanks for this help, will implement this and check if this was really the case
also i have one question that why it shows connected upon reloading the js bundle?
That I am not 100% sure on. How exactly do you reload it here?
using "R" on the expo terminal. it only reloads the js bundle leaving the native SDK running
Gotcha. And this is happening after the update happened? If not, synthrider's theory could explain this as well: the javascript SDK trying to interact with a terminal on firmware it isn't expecting. Trying to find more info on this