Skip to content
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

Circular structure to JSON error; remove device from registry?; "this" does not work in Device.prototype methods #357

Open
DecimusMaximus opened this issue Sep 7, 2017 · 0 comments

Comments

@DecimusMaximus
Copy link

Hello, first of all, this framework really is cool. There's a massive lack of documentation regarding its features though, most of what I've tried to make comes from the examples posted on the project's wiki. Either that or it needs more examples, with real stuff, not "mock" things. Also there's a guy that made 3 videos on youtube, used that too( although I had to speed up, too many pauses).

My problem: the sensor I'm modelling as a "device" is not physically connected to the zetta-containing server. Instead, it's connected over wi-fi and communicates over UDP. Since the project advertises "Scouts" as things which sit in the background and "discover" new devices, I said that instead of writing just the device driver and consider it just as only ONE sensor, I'd write the scout which would discover new sensors on the fly... that is, I could add on the fly sensors to the server.

What I've implemented works great for a single sensor, it even reconnects if the sensor/server looses connection. But that's because I had to use some work-arounds, else the code would discover new devices( I tried but I've got a conflicting problem with the nodejs UDP Socket).

First of all, in the Scout, when provisioning a new device( you know from the examples, if the results > 0 then provision the results[0] object), it seems as though the Device constructor isn't called anymore. I've searched for methods to remove the object from the registry, nothing seems to work. I've got a Device.prototype.checkConnection() method that is scheduled by a setInterval, and inside that method I tried calling "this.destroy" if after a set amount of time the connection isn't re-established. It won't work. Oh by the way, this doesn't seem to work in a prototype method defined by me, other than the init() one. I don't know why. I tried calling this.destroy when querying the device in the Scout, to destroy it before "discovering" a new one. It won't work.
So at the moment, whenever I loose connection and have to re-discover (the udp server code that listens for new devices is in the Scout), I keep growing the list of the same device(its name will be the same in my name generating scheme, just the UUID different), so in the zetta browser I keep getting lots of "empty" devices because I just don't know how to get rid of them.

Then, there's another quirk I had to make a work-around. The UDP-server. You can't make that thing part of the Device (like self.udpServer.on("message", function(msg, rinfo){...});. Nope, it will give you Circular structure to JSON error when trying to discover the device in the scout.
So I was forced to define it as a global variable in the Device driver, which means that every time a new Device is "discovered", the server will bind to a new port and the last device that was instantiated looses connection.

I realize this is quite a wall of text but I tried doing everything I know. Unfortunately I don't have the time to get into the guts of zetta and discover just what the heck is going on :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant