Bluetooth Serial example un Puck #3139
Replies: 10 comments
-
|
Posted at 2019-10-22 by @gfwilliams Ahh - yes, you're right - that's just because the console is still using it. You just need to move it out the way. Easiest is to use LoopbackA (which loops back output to LoopbackB). Either:
Just be sure to do that as either the last thing you upload, or on some other input. (eg buttonpress or delay) - because once the console has moved anything after will get ignored. You can just do |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-23 by voodooless Thanks, that helps a lot! Another (set of) question(s): how is delivery of data guaranteed (if it is at all)? Is there any sort of flow control available that can he used for this? Maximum characters that can be send at once is 20 I think? Is there a way to increase the MTU at the moment? |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-23 by @gfwilliams
I believe some level of retransmit/error correction is done by the Bluetooth stack - it seems pretty reliable for code uploads anyway
Not yet, so you'd have to implement your own. Espruino itself can implement software XON/XOFF flow control on Serial, but so far that hasn't been extended for use with Bluetooth.
Yes. If you're sending from Espruino then it will automatically 'chunk' everything for you. When you're sending to Espruino then yes, you have to split at 20 chars.
There's a branch of the code that implements this (https://github.com/espruino/Espruino/tree/increased_mtu) but it's not merged yet as it permanently uses a chunk of RAM and I need to decide if that's a good idea or maybe whether there's a trade-off (eg. 100 byte MTU rather than the full amount). |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-23 by voodooless
These things are a bit contradictory, aren't they? I was actually meaning flow control over the BLE uart connection. I'm pretty sure that if I'm sending data to fast It will choke at some point.. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-24 by @gfwilliams
Not really - Bluetooth data will get reliably to the Bluetooth stack, but if it's not handled by Espruino fast enough it'll get lost (however a FIFO_FULL error flag gets set in that case).
That's what I meant. There is no flow control on BLE UART yet, but conceivably it could be added to the firmware at some point. Having said all that the datarate over BLE is pretty low with the standard MTU and there's a big input buffer, so it's entirely possible that you could write your code such that it can always handle data as fast as can come over BLE. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-24 by voodooless
Can one handle this error within the application code? I've tried overflowing by sending loads of data in a loop, but it seems be be fine. At least that is encouraging!
Yes, it looks like it works for now. That's something we can work with at least. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-25 by @gfwilliams Yes, you can detect the error at least - but obviously you can't stop it overflowing. To test, you can do something like I actually hit this issue yesterday, so the absolute latest builds of Espruino (and 2v05+ when released) will now have XON/XOFF flow control built in. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-29 by voodooless That's very cool. Some more questions: is there a way to actually detect that there is a BLE uart connection present at all? Are there any events for connect or disconnect? Furthermore, it all seems to be based on string data? How does it work with binary data? can I safely convert the string data to binary and the other way around? |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-10-30 by AkosLukacs There is an event for connect and disconnect that's fired when you connect / disconnect. For binary, you can either convert binary to text, and send that. For example I have a project using the Nordic Uart that transfers data (power measurements from INA226) from Espruino to a page with web bluetooth. Actual sending is this line Sends I have a version that uses a custom characteristic, but that's not yet up on Github. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-11-01 by @gfwilliams
As @AkosLukacs says you can detect connections, and Just a note that the Web Bluetooth Puck.js lib (http://www.puck-js.com/puck.js) now supports flow control. HOWEVER while sending binary data over UART was fine, with XON/XOFF flow control (now the default in 2v05+ builds) you can't do that. You'd have to explicitly disable it using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-10-22 by voodooless
Hi there,
I'm looking for an example to use the Bluetooth serial port. I don't seem to get it working, probably because the console is still bound to it. I've tried looking for examples, but I can't find any. To be clear, I mean this one: https://www.espruino.com/Reference#l__global_Bluetooth
A println seems to output some data to the console, but the "data" event gets never posted..
Beta Was this translation helpful? Give feedback.
All reactions