One of the things I am stuck on with the ble_uart module, is what does the puck code look like if I already have an established connection. When I look at the source of the module, and most of the examples, they show requestDevice as the default. But when I try to use the standard ble_uart, I am getting errors that I am already connected or if I do something like :
// Function to send a message
function sendMessage() {
console.log("Trying to Connect");
NRF.requestDevice({ filters: [{ id: feather }], active:true }).then(function(device) {
print(device);
uart.write(device, "true");
}).then(function() {
console.log('Done!');
});
}
I get a "Uncaught Error: Unhandled promise rejection: Error: Function "write" not found!"
Here is all of the testing code:
var feather = "ff:8d:05:ae:17:64 random";
var uart = require("ble_uart");
NRF.setAdvertising({},{
name: "Splitz Puck",
showName: true,
discoverable: true,
connectable: true,
scannable : true,
});
// Blink green for 100ms
function blinkGreen() {
LED2.write(true);
setTimeout(function () { LED2.write(false); }, 100);
}
// Function to send a message
function sendMessage() {
console.log("Trying to Connect");
NRF.requestDevice({ filters: [{ id: feather }], active:true }).then(function(device) {
print(device);
uart.write(device, "true");
}).then(function() {
console.log('Done!');
});
}
/*function sendMessage(text, tx) {
return new Promise(function sender(resolve, reject) {
if (text.length) {
tx.writeValue(text.substr(0,20)).then(function() {
sender(resolve, reject);
}).catch(reject);
text = text.substr(20);
} else resolve();
});
}*/
// Send a message when the button is pressed
setWatch(function() {
blinkGreen();
sendMessage();
}, BTN, { edge: "rising", debounce: 50, repeat: true });
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.
One of the things I am stuck on with the ble_uart module, is what does the puck code look like if I already have an established connection. When I look at the source of the module, and most of the examples, they show requestDevice as the default. But when I try to use the standard ble_uart, I am getting errors that I am already connected or if I do something like :
I get a "Uncaught Error: Unhandled promise rejection: Error: Function "write" not found!"
Here is all of the testing code: