Ok, that looks good - the Uncaught ReferenceError: "nE" is not defined would be because you'd previously sent the wrong command (wrong \n) and it was still in the input buffer, so when you later sent the correct command it errored because of the misplaced n.
If you run it a second time it'd work fine.
how this could be captured by an app on the bangle to manage the code style etc
You have three options -
Create a function, and then send the JS code to call it
This is by far the easiest and what I'd recommend. So right now you're sending E.showMessage('Hello','A Title').
Define a function on the Bangle and upload it - let's just call it X:
function X(some, data) {
E.showMessage(some, data);
// or display some other way
}
For this to work alongside other apps, you want to write this into a storage file called myapp.boot.js.
Then you can connect and send something like "X('Hello','A Title')\n".
Have the app 'grab' the Bluetooth Serial port and handle all data that comes in.
Bluetooth.on('data',function(d) {
print("Got some data",d);
});
Terminal.setConsole();
This isn't ideal though - you have to handle the fact that the data sent will be split up into ~20 byte chunks. On top of that, debugging is a complete pain, because if you're grabbing the serial port that means you're no longer able to connect with the Web IDE.
Custom service
You could create a custom service with NRF.setServices and then handle writes using the onWrite handler. It's more secure, but a bit of a pain to set up.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ok, that looks good - the
Uncaught ReferenceError: "nE" is not defined
would be because you'd previously sent the wrong command (wrong\n
) and it was still in the input buffer, so when you later sent the correct command it errored because of the misplacedn
.If you run it a second time it'd work fine.
You have three options -
Create a function, and then send the JS code to call it
This is by far the easiest and what I'd recommend. So right now you're sending
E.showMessage('Hello','A Title')
.Define a function on the Bangle and upload it - let's just call it
X
:For this to work alongside other apps, you want to write this into a storage file called
myapp.boot.js
.Then you can connect and send something like
"X('Hello','A Title')\n"
.Have the app 'grab' the Bluetooth Serial port and handle all data that comes in.
This isn't ideal though - you have to handle the fact that the data sent will be split up into ~20 byte chunks. On top of that, debugging is a complete pain, because if you're grabbing the serial port that means you're no longer able to connect with the Web IDE.
Custom service
You could create a custom service with
NRF.setServices
and then handle writes using theonWrite
handler. It's more secure, but a bit of a pain to set up.