I tried the code on the puck.js to be able to turn the AWOX smart light bulb on and off. After a few switches, a message pops up on my control with the following:

NRF ERROR 0x8 at ?:0

As soon as this message pops up, the puck lights up all 3 leds once, red flashes once and it goes dead until I reset it by holding the button and reinserting the battery.

I have tried my own code to be able to detect light and depending on light levels, it switches the bulb on or off; ideal if you have a pet at home and no one is home :) So I tried the basic code tutorial and I get the same problem. My puck.js has been updated with the latest firmware a few weeks ago.

I also get unhandled promise rejections which I can't catch using try catch blocks.

Thanks for the reply. I attach the code I am using using the light sensor and button sensor to result variables and switch the light to an off state. It might be that when len is too short as defined in the setInterval function, it kicks up the NRF error. I have tried longer len times and it resulted in crashes after several hours testing it.

but what you need to do to catch promises (like the one in setLight) is:

....then(function() {
// .....
}).catch(function(error) {
// here
});

So not the usual try...catch - it's a bit weird, but it's just the way you have to handle stuff with JS promises.

While you can catch other errors, unfortunately that NRF Error won't be catchable - it's right from the lower levels of the hardware.

To me, it looks like you're not doing any checks to see whether you're in the middle of doing something with Bluetooth - so quite likely what'll happen is it'll turn on the light, get too bright, and try and turn itself off - which could happen while Puck.js is trying to disconnect, which could really mess things up?

I've been looking in to this and I've found a few issues in Espruino that could be causing this. Hopefully I'll have a new version for you soon with it fixed.

The main issue seems to be really bad timing inside the Bluetooth stack - occasionally you can disconnect, and then the stack will ask Espruino to do something which isn't possible because the device has disconnected!

I have tested this over the few days and what I observed is that if there is a timeout error which is caught (sometimes weirdly it doesn't get caught) it will get into a busy state and nothing will happen. What I have to do (manually) is switch the light bulb off from the mains and then back on again and it will resume operation.

So far, so good - the behaviour is much more stable, but I'm getting an "Out of memory while appending to array" warning as the interval keeps checking for light levels. Is there a way of doing this in JS or is it C level malloc stuff?

That's odd - are you sure you're just running that code above and not doing anything else, like scanning for advertisements or checking for light levels really really quickly?

I'm pretty sure the error happens in this case when the code running in the interrupt is trying to allocate memory, but it can't because Espruino is in the middle of garbage collecting - but generally Espruino garbage collects very rarely and doesn't take long. The only way I could force errors when testing was to run code every few milliseconds, while also connecting.

I don't think it should actually be that big a deal as it'll be trying to update the GattServer object, which you're not interested in - does it keep working regardless?

I had a try with some code with an interval of 30 seconds and coded some behaviour that allows some light tolerance so that it does not change back and forth all the time. I noticed that sensing light has some variance and this can cause issues. One odd behaviour I notice from the Puck is that when viewing console output after some time, console looping stops and I need to reconnect again to the puck. Although I find that what works well is to switch the AWOX bulb off and then back on. Is this a sync issue?

I have a piece of code with a for loop (loops only 10 times to get lower, avg and upper bounds of light) inside an interval that outputs to the console - see print screen. It keeps working if it's not printing anything, but sometimes I need to either re-upload or switch off the bulb and then back on. You can also see that there is also a promise that wasn't caught which should have been already caught.

It keeps working if it's not printing anything, but sometimes I need to either re-upload or switch off the bulb and then back on.

So you need to re-upload/switch the bulb off eventually if it's printing - but it's absolutely fine if you remove the console.log?

What if you leave the prints in, but then disconnect your PC from the Puck? Does it still stay working ok?

Also, for the unhandled promise, can you try changing characteristic.writeValue(val); to return characteristic.writeValue(val);? I think that'll be the problem - looks like all Espruino's docs need updating as none of them mentioned that.

Also, for the unhandled promise, can you try changing characteristic.writeValue(val); to return ?characteristic.writeValue(val);? I think that'll be the problem - looks like all Espruino's docs need updating as none of them mentioned that.

I'll give it a try and update.

Post a reply

Bold

Italics

Link

Image

List

Quote

code

Preview

Formatting Help

Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.

Tips:

Create headers by underlining text with ==== or ----

To *italicise* text put one asterisk each side of the word

To **bold** text put two asterisks each side of the word

Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png)That's the hard one: exclamation, square brackets and then the URL to the image in brackets.

* Create lists by starting lines with asterisks

1. Create numbered lists by starting lines with a number and a dot

> Quote text by starting lines with >

Mention another user by @username

For syntax highlighting, surround the code block with three backticks:

```
Your code goes here
```
Just like Github, a blank line must precede a code block.

If you upload more than 5 files we will display all attachments as thumbnails.