#mja123_code

1 messages ¡ Page 1 of 1 (latest)

opaque lionBOT
#

👋 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.

wheat wyvernBOT
#

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.

lucid rampart
#

not updating the state to connected
Can you say more about this? What are you checking and expecting to find? WHat is actually happening?

main sky
#

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

lucid rampart
#

What is the reader you get back from connectBluetoothReader?

main sky
#

it doesnt return any value when connecting to a real reader

lucid rampart
#

Then it seems like a different problem

#

Is your discovery step returning your reader?

main sky
#

yes

#

the device gets connected however

#

just the sdk value is not updating

lucid rampart
main sky
#

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

lucid rampart
#

Can you share your discovery code that runs before the connection attempt?

main sky
#

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));
},
});

opaque lionBOT
lucid rampart
#

Something seems to be missing here

#

Are you reaching your handleConnectBluetoothReader and able to see your sentry logs from that?

main sky
#

yes

lucid rampart
#

This should return a connected reader or an error:

const { reader, error } = await connectBluetoothReader({
                        reader: _reader,
                        locationId: location.data?.data.stripe_id,
                  });
main sky
#

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

lucid rampart
#

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?

main sky
#

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?

versed sapphire
#

That I am not 100% sure on. How exactly do you reload it here?

main sky
#

using "R" on the expo terminal. it only reloads the js bundle leaving the native SDK running

versed sapphire
#

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