Fix bugs and add JS API

add turnOn, turnOff API of JavaScript
fix bugs: illigal DB writing after switch off.
Inproper error handling when serial is not detached.