@@ -235,8 +235,8 @@ <h2 id="https-web-request">HTTPS Web request</h2>
235
235
< p > The code snippet demonstrates how to use REQUEST to interact with a
236
236
specified endpoint, providing necessary data and token for
237
237
authentication.</ p >
238
- < h2 id ="iot-device-communication "> IoT Device Communication</ h2 >
239
- < h3 id ="usb-serial-support "> USB Serial Support</ h3 >
238
+ < h1 id ="iot-device-communication "> IoT Device Communication</ h1 >
239
+ < h2 id ="usb-serial-support "> USB Serial Support</ h2 >
240
240
< p > These functions allow you to connect, send, and receive data over a
241
241
USB serial connection.</ p >
242
242
< h4 id ="open-a-usb-serial-connection "> 🔌 Open a USB Serial
@@ -289,6 +289,74 @@ <h4 id="example">📝 Example</h4>
289
289
print "sent "; n
290
290
print usb.receive()
291
291
wend</ code > </ pre >
292
+ < h2 id ="bluetooth-support "> Bluetooth Support</ h2 >
293
+ < p > These functions allow you to connect to Bluetooth serial devices,
294
+ send and receive data, and manage the connection within your Smallbasic
295
+ program.</ p >
296
+ < h4 id ="open-a-bluetooth-serial-connection "> 🔌 Open a Bluetooth Serial
297
+ Connection</ h4 >
298
+ < div class ="sourceCode " id ="cb21 "> < pre
299
+ class ="sourceCode smallbasic "> < code class ="sourceCode smallbasic "> < span id ="cb21-1 "> < a href ="#cb21-1 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="dt "> const</ span > bt = android.openBluetooth(deviceName)</ span > </ code > </ pre > </ div >
300
+ < p > Parameters:</ p >
301
+ < ul >
302
+ < li > < code > deviceName</ code > : (required) The Bluetooth device name to
303
+ connected with.</ li >
304
+ </ ul >
305
+ < p > Returns:</ p >
306
+ < ul >
307
+ < li > A Bluetooth object to be used with other Bluetooth functions.</ li >
308
+ </ ul >
309
+ < h4 id ="close-the-bluetooth-connection "> ❌ Close the Bluetooth
310
+ Connection</ h4 >
311
+ < div class ="sourceCode " id ="cb22 "> < pre
312
+ class ="sourceCode smallbasic "> < code class ="sourceCode smallbasic "> < span id ="cb22-1 "> < a href ="#cb22-1 " aria-hidden ="true " tabindex ="-1 "> </ a > bt.< span class ="fu "> close</ span > ()</ span > </ code > </ pre > </ div >
313
+ < p > Closes the current Bluetooth connection.</ p >
314
+ < p > Tip: Always close the connection when you’re done to free
315
+ resources.</ p >
316
+ < h4 id ="check-whether-the-bluetooth-connection-is-open "> 🔌 Check whether
317
+ the Bluetooth Connection is open</ h4 >
318
+ < div class ="sourceCode " id ="cb23 "> < pre
319
+ class ="sourceCode smallbasic "> < code class ="sourceCode smallbasic "> < span id ="cb23-1 "> < a href ="#cb23-1 " aria-hidden ="true " tabindex ="-1 "> </ a > cn = bt.connected()</ span > </ code > </ pre > </ div >
320
+ < p > Returns true if the Bluetooth connection is currently open, otherwise
321
+ false.</ p >
322
+ < h4 id ="get-device-description-1 "> 📋 Get Device Description</ h4 >
323
+ < div class ="sourceCode " id ="cb24 "> < pre
324
+ class ="sourceCode smallbasic "> < code class ="sourceCode smallbasic "> < span id ="cb24-1 "> < a href ="#cb24-1 " aria-hidden ="true " tabindex ="-1 "> </ a > bt.description()</ span > </ code > </ pre > </ div >
325
+ < p > Returns a string with details about the Bluetooth connection
326
+ inclusing name and address (if available).</ p >
327
+ < h4 id ="receive-data-1 "> 📥 Receive Data</ h4 >
328
+ < div class ="sourceCode " id ="cb25 "> < pre
329
+ class ="sourceCode smallbasic "> < code class ="sourceCode smallbasic "> < span id ="cb25-1 "> < a href ="#cb25-1 " aria-hidden ="true " tabindex ="-1 "> </ a > dat = bt.receive()</ span > </ code > </ pre > </ div >
330
+ < p > Reads incoming data from the connected Bluetooth device.</ p >
331
+ < p > Returns:</ p >
332
+ < p > A string containing the received data, or an empty string if no data
333
+ is received before the timeout.</ p >
334
+ < h4 id ="send-data-1 "> 📤 Send Data</ h4 >
335
+ < div class ="sourceCode " id ="cb26 "> < pre
336
+ class ="sourceCode smallbasic "> < code class ="sourceCode smallbasic "> < span id ="cb26-1 "> < a href ="#cb26-1 " aria-hidden ="true " tabindex ="-1 "> </ a > n = bt.send(dat)</ span > </ code > </ pre > </ div >
337
+ < p > Sends data to the connected Bluetooth device.</ p >
338
+ < p > Parameters:</ p >
339
+ < p > dat – The data to send as a string.</ p >
340
+ < p > Returns:</ p >
341
+ < p > The number of bytes successfully sent.</ p >
342
+ < h4 id ="example-1 "> 📝 Example</ h4 >
343
+ < pre > < code > import android
344
+
345
+ bt = android.openBluetooth("TeensyBT")
346
+ print "opened"
347
+ print bt.description()
348
+ for i = 0 to 1000
349
+ if bt.connected() then
350
+ n= bt.send(i)
351
+ delay 10
352
+ print bt.receive(); " "; i
353
+ else
354
+ print "waiting..."
355
+ delay 3000
356
+ endif
357
+ next</ code > </ pre >
358
+ < p > This example opens a connection to a device named “TeensyBT”, then
359
+ continuously sends and receives data in a loop.</ p >
292
360
< h2 id ="how-to-edit-and-run-a-program "> How to edit and run a
293
361
program</ h2 >
294
362
< h3 id ="internal-editor "> Internal editor:</ h3 >
@@ -358,7 +426,7 @@ <h2 id="privacy-policy">Privacy Policy <a
358
426
< p > < a href ="privacy.html "> Privacy Policy</ a > </ p >
359
427
</ div >
360
428
< div class ="pagefooter ">
361
- This page was last edited on Sun, 20 Apr 2025 08:02:09 +0930
429
+ This page was last edited on Sun, 20 Apr 2025 09:34:07 +0930
362
430
|
363
431
< a href ="https://en.wikipedia.org/wiki/Markdown " target ="_blank " rel ="nofollow "> Markdown</ a >
364
432
processed with
0 commit comments