AWOX smart bulb tutorial - NRF ERROR 0x8 at ?:0 #2306
Replies: 20 comments
-
Posted at 2017-08-07 by @gfwilliams So it's literally just with this code:
that you're having problems? Is it anything particular that you do that causes the error? To catch a promise rejection, just do:
you can't catch them with a try...catch block because the function will have already finished executing by the time the error occurs. The majority of errors will probably be because you're pressing the button quickly enough that the Puck won't have finished the last connection before the latest request to connect comes in? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-07 by Joe Hi Gordon, 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.
I also added the catch after when writing to the smart bulb and it didn't catch it; the NRF error crept up and crashed the whole thing. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-07 by @gfwilliams It seems you're doing:
but what you need to do to catch promises (like the one in setLight) is:
So not the usual While you can catch other errors, unfortunately that 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? Could you try replacing
It might help, as it'll refuse to do anything else if it's already in the middle of controlling the light. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-07 by Joe Hi Gordon, I'll give this new code block a try. Cheers. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-07 by @gfwilliams 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! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-07 by @gfwilliams If you update with the puck.js firmware zip from here: http://www.espruino.com/binaries/travis/47df0cf7e15453bc2485c2d6a9f1756a1de072d4/ Then things should be a huge amount better - however there are still some niggling issues I'd like to fix to do with the connection sometimes failing if your code is really busy. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-07 by Joe Gordon, Cheers for this, I have updated my puck and will give this a go. I'll let you know of any progress. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by Joe Hi Gordon, 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. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by @gfwilliams Thanks! I think that's what I was finding as well. It's actually connected ok, but it failed to tell the rest of the code so is stuck in a connected state but isn't able to disconnect. Please could you try a build from here: http://www.espruino.com/binaries/travis/e8ceb5c61bd145e7a74e92a620f4af1cbb96dd78/ I think I finally fixed it this morning - at least it seems a lot better for me now. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by Joe HI Gordon, 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? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by @gfwilliams 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? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by Joe It's only doing this task, so no advertisement. It's weird. I ran it again, and I don't get it anymore. As a precaution, I have set the interval to be 30 seconds. I'll let you know if it kicks up a fuss :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by @gfwilliams Ok, great! It's something I'm planning on fixing eventually, but it's quite a difficult problem to work around. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-09 by Joe I can definitely sympathise with you :) My code so far is not terribly very clean; there are opportunities to refactor some functions to make it cleaner. Once it's squeaky clean and behaves as it should, I'll post it here. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-12 by Joe 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? Ill copy my code so far here with some refactoring done.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-14 by @gfwilliams What do you mean by 'console looping'? Just printing data to the console? When it's not printing anything, is it still working correctly? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-14 by Joe Hi Gordon, 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.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-14 by Joe Update: after it disconnects on its own, I get the 3 LEDs of death followed by the red LED flashing once. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-14 by @gfwilliams
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 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-14 by Joe
I'll give it a try and update. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-08-06 by Joe
Hi,
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.
Any ideas about these issues?
Beta Was this translation helpful? Give feedback.
All reactions