Closed SpaceDux closed 3 years ago
See here for an example use case:
https://github.com/iobroker-community-adapters/ioBroker.unifi/blob/master/main.js#L1123
Apart from that cb
is of course the callback function you need to specify. Thus, you should use the following function call:
controller.createVouchers(config.UBQT.Site, config.UBQT.Expiry, function(err, result) {
...
}, '', "1", "1", "WiFi Voucher via Node", config.UBQT.MaxUp, config.UBQT.MaxDown);
Thus, note the different position of the function(err, result)
callback function...
Hi Jens,
Great & very efficient response! I kinda guessed CB would mean callback. But ofcourse I was doing it incorrectly. Your response was all I needed to get on track. Good job on the package, it seems great 👍 .
My code now looks like this now;
var unifi = require('node-unifi');
var controller = new unifi.Controller(config.UBQT.Address, config.UBQT.Port);
let thisclass = {
GenerateVoucher: function()
{
return new Promise(function(resolve, reject) {
controller.login(config.UBQT.User, config.UBQT.Password, function(err) {
if(err) {
console.log('ERROR: ' + err);
reject(err);
}
controller.createVouchers(config.UBQT.Site, config.UBQT.Expiry, async function(err, result) {
if(err)
{
console.log(err);
reject(err);
}
let response = await result[0];
controller.getVouchers(config.UBQT.Site, async function(err, result) {
if(err)
{
console.log(err);
reject(err);
}
let return_codes = await result[0];
console.log("Code: " + return_codes[0].code);
resolve(return_codes[0].code);
controller.logout();
}, response[0].create_time)
}, "1", "1", "Generated via NodeJS", config.UBQT.MaxUp, config.UBQT.MaxDown);
});
});
}
}
module.exports = thisclass;
Hopefully the above may help another person that hit the same wall as I did :).
Thanks again Jens, appreciate the support.
Hi, I've just started looking into this, I previously used the PHP version, however I can't find any documentation of your JS build.
Generating the voucher is working as expected, which is great, however the callback/return isn't being piped? Am I missing something, or doing something incorrect?
within this function, what is "cb"?
Any help on this would be greatly appreciated.
Thank you 👍