enocean-js / node-enocean

an enocean implementation for node.js
GNU General Public License v2.0
29 stars 14 forks source link

Error : enocean.startLearning is not a function #23

Closed nemr closed 7 years ago

nemr commented 7 years ago

I'm trying to use tge startLearning function but its giving me the following error :

TypeError: enocean.startLearning is not a function

this is the code :

var enocean = require("node-enocean")();
enocean.listen("/dev/ttyUSB0");
enocean.startLearning()
enocean.on("learned",function(data){   
    console.log(data)
});
Holger-Will commented 7 years ago

startLearning should only be used after the ready event got fired. please try it like this and tell me if it works... it works here...

 enocean.on("ready",function(){
    enocean.timeout=120
    enocean.startLearning()
}  

p.s.: see the memory.js example in the examples folder

nemr commented 7 years ago

Hi , its working fine now thats .

Just to let u know I had an error before that which was :

/home/pi/Desktop/node_modules/node-enocean/index.js:226
        socket.on( "get-last-sensor-value" , async function( id ) {
                                             ^^^^^

SyntaxError: missing ) after argument list

I took out that function form the index file to get it working since I dont need that function at the moment , but it might be something that you would need to consider .

Thanks again for this great npm

Holger-Will commented 7 years ago

I already set a device on learning mode , but I didn't get the the learning confirmed response

the sensor is most likely already learned in please check your knownSensors file... (default location is ./node_modules/node-enocean/modules/knownSensors.json)

Holger-Will commented 7 years ago

the other error you are seeing is handled in issue #22 you have to update your node.js to the latest version (7.7.1) for this to work, or start your app with the --harmony-async-await flag