#yeet_api
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/1389669216046547134
π Have more to share? Add more details, code, screenshots, videos, etc. below.
hello! taking a look at this now, but my familiarity with React Native + Terminal is a little low so i may need to pull someone else in for support
no worries
heres the full function
const connectToReader = async () => {
try {
console.log("π‘ starting scan");
setLoading(true);
await clearCachedCredentials();
await disconnectReader().catch(() => {});
const scanPromise = discoverReaders({
discoveryMethod: "bluetoothProximity",
});
setTimeout(() => cancelDiscovering().catch(() => {}), 10000);
const { readers, error } = await scanPromise;
if (error) {
Alert.alert("Discovery error", error.message);
return;
}
if (readers.length === 0) {
Alert.alert("No reader found", "Wake the M2 reader and keep it nearby.");
return;
}
const selected = readers[0];
console.log("β
Reader picked:", selected.serialNumber);
const { reader: connected, error: connErr } = await connectReader(
selected,
{ locationId: "MYLOCATIONID", failIfInUse: false }
);
console.log("π΄ connectReader result β", { connected, connErr });
if (connErr) {
Alert.alert("Connection failed", connErr.message);
return;
}
setReader(connected);
Alert.alert("Reader connected", connected.label || connected.deviceType);
} catch (err) {
console.error("π₯ connectToReader crashed:", err);
Alert.alert("Error", "Unexpected error connecting to reader");
} finally {
setLoading(false);
}
};
here is the log
[Stripe terminal]: didUpdateDiscoveredReaders [{"availableUpdate": null, "batteryLevel": 0.8299999833106995, "batteryStatus": "nominal", "deviceSoftwareVersion": "2.01.00.15-SZZZ_Prod_US_v1-480001", "deviceType": "stripeM2", "id": null, "ipAddress": null, "isCharging": false, "label": null, "location": null, "locationId": null, "locationStatus": "notSet", "serialNumber": "MYSERIALNUMBER", "simulated": false, "status": "offline"}]
(NOBRIDGE) LOG [Stripe terminal]: didChangeConnectionStatus notConnected
(NOBRIDGE) LOG [Stripe terminal]: didFinishDiscoveringReaders {" error": {"code": "Canceled", "message": "discoverReaders was cance led."}}
hmm yeah i'm not seeing anything that's jumping out at me.... let me see if i can find someone else who is more familiar to take a look
okay should i paste the whole file?
Hello
I'm looking at your code and a few things jump out.
First one is that you don't have await infront of discoverReaders function
so ive tried that. when i do that it just shows this
[Stripe terminal]: didUpdateDiscoveredReaders [{"availableUpdate": null, "batteryLevel": 0.8299999833106995, "batteryStatus": "nominal", "deviceSoftwareVersion": "2.01.00.15-SZZZ_Prod_US_v1-480001", "deviceType": "stripeM2", "id": null, "ipAddress": null, "isCharging": false, "label": null, "location": null, "locationId": null, "locationStatus": "notSet", "serialNumber": "MYSERIALNUMBER", "simulated": false, "status": "offline"}]
and then waits there indefinitely. i saw that it's supposed to time out after 30 seconds but it doesn't time out eveer.
Ah so that's the discovered reader being shown to you in the logged out line. So you definitely need await there
Also, you shouldn't use setTimeout for "timeout"
const connectToReader = async () => {
try {
console.log("π‘ Attempting to discover readersβ¦");
setLoading(true);
await clearCachedCredentials();
await disconnectReader().catch(() => {});
const { readers, error } = await discoverReaders({
discoveryMethod: "bluetoothProximity",
timeout: 2, // β short, responsive scan
});
if (error) {
Alert.alert("Discovery error", error.message);
return;
}
if (readers.length === 0) {
Alert.alert("No reader found", "Wake the M2 reader and keep it nearby.");
return;
}
const selected = readers[0];
console.log("β
Reader picked:", selected.serialNumber);
await cancelDiscovering?.();
const { reader: connected, error: connErr } = await connectReader(
selected,
{ locationId: "tml_GGBqowM4DFED9J", failIfInUse: false }
);
console.log("π΄ connectReader result β", { connected, connErr });
if (connErr) {
Alert.alert("Connection failed", connErr.message);
return;
}
setReader(connected);
Alert.alert("Reader connected", connected.label || connected.deviceType);
return connected;
} catch (err) {
console.error("π₯ Unexpected crash in connectToReader:", err);
Alert.alert("Error", "Unexpected error connecting to reader");
} finally {
setLoading(false);
}
};
ive tried this
SDK has a built in method afaik
Yup
timeout takes miliseconds afaik, let me double check
and this just shows the bluetooth m2 reader that was found but it doesnt timeout and stays in discover readers indefinitely
i can try right now again
Yup, hang on..
The other issue is that you're trying to chain "connectReader" after discoverReader in a way.. You shouldn't do that
You should listen to onUpdateDiscoveredReaders callback function to connect to a reader instead
https://docs.stripe.com/terminal/payments/connect-reader?terminal-sdk-platform=react-native&reader-type=bluetooth#discover-readers
kicking off connection flow would stop discovery
okay so instead of doing await discover readers then connecting the reader try what you just just shows instead?
Yup, the doc I shared is pretty descriptive about the flow
One example is using a FlatList to show "Discovered Readers" and then "onPress" -> kick off connectReader flow
okay thanks ill try this out.
is there any way i can contact you if i still have issues
this thread will stay open for some time in case you have immediate questions. Otherwise, you can always create a new thread via #help and someone should be able to help you
cool. thanks for your time