#yeet_api

1 messages Β· Page 1 of 1 (latest)

robust sorrelBOT
#

πŸ‘‹ 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.

twin rock
#

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

exotic flint
#

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."}}

twin rock
#

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

exotic flint
#

okay should i paste the whole file?

unreal dew
#

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

exotic flint
#

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.

unreal dew
#

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"

exotic flint
#

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

unreal dew
#

SDK has a built in method afaik

#

Yup

#

timeout takes miliseconds afaik, let me double check

exotic flint
#

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

unreal dew
#

Yup, hang on..

The other issue is that you're trying to chain "connectReader" after discoverReader in a way.. You shouldn't do that

#

kicking off connection flow would stop discovery

exotic flint
#

okay so instead of doing await discover readers then connecting the reader try what you just just shows instead?

unreal dew
#

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

exotic flint
#

okay thanks ill try this out.

#

is there any way i can contact you if i still have issues

unreal dew
#

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

exotic flint
#

cool. thanks for your time