-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Cannot call method 'some' of undefined #276
Comments
Hi @ariafloat! A few questions for you.
Thanks Matt |
・What version of Zetta are you using? ・What version of the LED Driver are you using? |
@ariafloat Does your app run on the same zetta process as where the devices run? Or does the zetta process with the app run on a zetta process you link to? Trying to figure out why virtual_device is being used, based on your app you supplied it should only look for local devices and never use a virtual_device. Maybe provide your complete zetta server file? This is the file i'm using to reproduce it. Tried with both var zetta = require('zetta');
var Led = require('zetta-led-mock-driver');
var Photocell = require('zetta-photocell-mock-driver');
var MemoryRegistries = require('zetta-memory-registry')(zetta);
var PeerRegistry = MemoryRegistries.PeerRegistry;
var DeviceRegistry = MemoryRegistries.DeviceRegistry;
var app = function(server) {
var photocellQuery = server.where({ type: 'photocell' });
var ledQuery = server.where({ type: 'led' });
server.observe([photocellQuery, ledQuery], function(photocell, led){
photocell.streams.intensity.on('data', function(m) {
if(m.data < 0.5) {
if (led.available('turn-on')) {
led.call('turn-on', function(){});
}
} else {
if (led.available('turn-off')) {
led.call('turn-off', function(){});
}
}
});
});
}
zetta({ registry: new DeviceRegistry(), peerRegistry: new PeerRegistry() })
.name('Dillon')
.use(app)
.use(Led)
.use(Photocell)
.listen(0) Output
|
It may also help to see what versions of Could you give the output of |
Versions are the following. "dependencies": {
"argv": "0.0.2",
"zetta": "^1.0.0-beta.5",
"zetta-device": "^0.17.0",
"zetta-memory-registry": "^0.1.0"
} All codes are the following. core zetta server[server.js] is the following. var zetta = require('zetta');
var myApp = require('./apps/myapp.js');
var argv = require('argv');
var MemoryRegistries = require('zetta-memory-registry')(zetta);
var PeerRegistry = MemoryRegistries.PeerRegistry;
var DeviceRegistry = MemoryRegistries.DeviceRegistry;
zetta({ registry: new DeviceRegistry(), peerRegistry: new PeerRegistry() })
.name('core')
.load(myApp)
.listen(1337); App code is the following. module.exports = function (server) {
var ledQuery = server.from('*').where({
type: 'led'
});
var distanceQuery = server.from('*').where({
type: 'distance'
});
server.observe([ledQuery, distanceQuery], function (led, distance) {
distance.streams.level.on('data', function (m) {
console.log('level: ' + m.data + ', ' + 'led: ' + led.state);
if (m.data >= 30 && led.state === 'off') {
led.call('turn-on');
} else if (m.data <= 20 && led.state === 'on') {
led.call('turn-off');
}
});
});
}; Run the core zetta server node server.js end zetta server[server-end.js] is the following. var zetta = require('zetta');
var mockLed = require('./drivers/mock-led.js');
var mockDistance = require('./drivers/mock-distance.js');
var argv = require('argv');
var MemoryRegistries = require('zetta-memory-registry')(zetta);
var PeerRegistry = MemoryRegistries.PeerRegistry;
var DeviceRegistry = MemoryRegistries.DeviceRegistry;
var args = argv.option([{
name: 'link',
short: 'l',
type: 'string'
}]).run();
var linkServer = args.options.link || 'http://localhost:1337';
zetta({ registry: new DeviceRegistry(), peerRegistry: new PeerRegistry() })
.name('end')
.use(mockLed)
.use(mockDistance)
.link(linkServer)
.listen(1338); Driver[mock-led.js] is the following. var Device = require('zetta-device');
var util = require('util');
var LED = module.exports = function () {
Device.call(this);
};
util.inherits(LED, Device);
LED.prototype.init = function (config) {
config
.name('led')
.type('led')
.state('off')
.when('off', { allow: ['turn-on'] })
.when('on', { allow: ['turn-off'] })
.map('turn-on', this.turnOn)
.map('turn-off', this.turnOff);
};
LED.prototype.turnOn = function (cb) {
this.state = 'on';
cb();
};
LED.prototype.turnOff = function (cb) {
this.state = 'off';
cb();
}; Driver[mock-distance.js] is the following. var Device = require('zetta-device');
var util = require('util');
var Distance = module.exports = function(distance) {
Device.call(this);
this.distance = distance;
};
util.inherits(Distance, Device);
Distance.prototype.init = function (config) {
config
.name('distance')
.type('distance')
.stream('level', this.streamDistance, 'object');
};
var flag = true;
Distance.prototype.streamDistance = function (stream) {
setInterval(function () {
if(flag){
stream.write(30);
flag = false;
} else {
stream.write(20);
flag = true;
}
}, 1000);
}; Run the end zetta server linking the core server node server-end.js -l http://XXX.XXX.XXX.XXX:1337 [XXX.XXX.XXX.XXX] is the core server address. |
Did find the issue: We call What I get back from the log topic { topic: 'led/a76ae181-66cf-4bfe-8c7c-6b714ebc1f58/logs',
timestamp: 1452701209048,
transition: 'turn-off',
input: [],
properties:
{ id: 'a76ae181-66cf-4bfe-8c7c-6b714ebc1f58',
type: 'led',
name: 'led',
state: 'off' },
transitions: { 'turn-on': {} } } We expect it to have |
Ok I think i see what's going on here. In zetta-device we generate that object https://github.com/zettajs/zetta-device/blob/master/device.js#L354-L367 for all external websockets reading the logs stream we rewrite the object to the normal siren format you would see from a transition response. This is done in event_socket https://github.com/zettajs/zetta/blob/master/lib/event_socket.js#L162-L170, we have to do this to format the api hrefs correctly based on where the client is connecting. For the virtual_device we manually subscribe to the internals https://github.com/zettajs/zetta/blob/master/lib/virtual_device.js#L43-L46 which does not include the reformating. I think we only see this sometimes because generally the virtual_device gets updated by the logs stream and the response from the transition which overwrites the invalid logs one. |
In the following application,
When [led.call('turn-off');] is called after [led.call('turn-on');] was called, the following error is output in Zetta-Server.
The text was updated successfully, but these errors were encountered: