Bluefruit app - parse incoming #2157
Replies: 10 comments
-
Posted at 2017-04-27 by @gfwilliams It's actually pretty easy - I used it for the robot demo in the KickStarter video and I may have forgotten to post the code up. Basically you treat For instance to handle colours:
or for the robot itself I did:
Because of the way BLE works, you'll get one big chunk of data received in one go, so you don't have to worry about detecting start and end - each time the handler is called it'll have a complete command in it. However: it's not quite that simple. By default, the actual JS interpreter is running on that Bluetooth UART, and will intercept any characters and try and execute them as JS before your code gets to see them. You need to force the console to stay on some other device, maybe with So probably what you want is simply:
That will move the console out of the way temporarily, when you press a button. So now when everything is running you can connect the Adafruit app, press the Puck's button to move the console out the way, and it all works fine. When you disconnect and reconnect with the PC, the console will go back to being on Bluetooth so you can program it as normal! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by JackJamesHoward Excellent explanation! Thank you for explaining the LoopBack to me, I was really scratching my head over how to stop the JS interpreter intercepting incoming data. It works really well with the app, however, I tried to use the WebIDE to pass a command string instead of using the app.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by Wilberforce At this point in the web ide disconnect and then connect, and you will be able to type again... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by JackJamesHoward I can't do that because the puck will go back to being on Bluetooth instead of being in LoopbackA. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by @gfwilliams As @wilberforce says, you'd have to reconnect to get control back. And if you're wondering why it's not working when you enter characters yourself, it's because they're being sent one by one - so To make it work properly in that case you'd have to store the whole string, a bit like:
The reason it works for the Adafruit app is that the app is sending the characters all in one chunk, so they're being received in one chunk. I guess you might have some luck if you copied and then pasted the command into the Web IDE, but it's not guaranteed :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by JackJamesHoward I get it now thanks @gfwilliams and sorry @wilberforce you were correct. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by JackJamesHoward How can I detect once a connection has estabilished then run a
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by @gfwilliams Yes, it'll be because How about:
Note that you could check the device's address, so you could avoid calling LoopbackA if your development PC is connecting? Check this out for an example: http://forum.espruino.com/comments/13603623/ |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by JackJamesHoward Thanks for your help Gordon. This is a nice little example to do with the puck by itself.
Just remeber to press the btn on the puck if you want to send some new code to the puck |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by @gfwilliams Neat - thanks for posting it up! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-27 by JackJamesHoward
The adafruit Bluefruit has a control pad the sends strings such as:
!B41CRC
I want to parse this into its component parts such as:
[‘!’] [‘B’] [‘4’] [‘1’] [CRC]
I think I can do this, but I don't know how to set a watch event that actually parses the string once it's received.
It is not like the bluefruit app calls a function
parse(!B41CRC)
. How do I watch for incoming data then do something with it?Beta Was this translation helpful? Give feedback.
All reactions