HomeGenie Forum

Development => Feature request => Topic started by: Jan on March 29, 2014, 07:55:47 PM

Title: JSON Flag for refresh time of widget
Post by: Jan on March 29, 2014, 07:55:47 PM
So, when writing my first widget I noticed (at least on the raspberry) that viewing the control panel causes quite a huge workload (80-98%) on the CPU.

Since all implemented widgets, actors (switches, light, etc) pull and render their current status every 10 or so seconds, one open browser with the control panel displayed will make the system react really slow on any other client.

If you want to check this yourself, ssh into the raspberry (usr: pi, pwd: raspberry) and execute
Code: [Select]
topto see the systemload.

So, where I can clearly see that you want your lights, switches, shutters, etc to reflect their current state as regular as possible, there are other widgets (like weather, sunrise/set or showing program-states) that would work just fine when pulling their status only every few hours.

What do you think: Wouldn't it make sense, if you could add a variable in the json-file like
Code: [Select]
Refresh : number_of_seconds_till_next_call
Thanks,
jan
Title: Re: JSON Flag for refresh time of widget
Post by: Gene on March 29, 2014, 08:36:47 PM
What is causing the overload on smaller cpus it is the web service call:
Code: [Select]
http://192.168.10.20/api/HomeAutomation.HomeGenie/Config/Modules.List
and specifically the method GetJsonSerializedModules:

https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Service/HomeGenieService.cs#L411

Using NewtonJson to serialize the modules structure was even resulting in worse cpu usage.

This is called periodically to get all the modules with updated parameters and so update ALL the widgets in the UI.

In the future this "polling" approach will be replaced by a presistent http connection that will receive real time events, instead of polling the whole thing everytime, and so update the corresponding UI element quickly.
Also events polling (the upper-right popup) will be replaced by that.
Off course.. any contribution in this direction is also accepted =D

Cheers,
g.
Title: Re: JSON Flag for refresh time of widget
Post by: Jan on March 29, 2014, 09:36:46 PM
Sounds like a well thought plan. Wouldn't want to argue on that.

I certainly would, though, like to help you on this one - yet, I'm basically learning c# by looking at your code - more of a php person myself  ;)

Best,
jan
Title: Re: JSON Flag for refresh time of widget
Post by: Gene on March 30, 2014, 07:46:10 PM
I did it  ;D

If you want help testing r356:

https://sourceforge.net/projects/homegenie/files/testing/

Also included your widget but I noticed it won't work under windows =/ perhaps some parsing/locale issues on numbers.
All values are displayed as NaN.

Cheers,
g.
Title: Re: JSON Flag for refresh time of widget
Post by: Gene on March 31, 2014, 11:25:53 AM
Hi Jan,

I found out where the NaN problem is coming from. This happen with locales using comma as decimal separator.
Seems to be actually a problem of the Javascript engine (Jint).
I filed an issue:

https://github.com/sebastienros/jint/issues/41

Cheers,
g.
Title: Re: JSON Flag for refresh time of widget
Post by: Gene on March 31, 2014, 12:04:05 PM
Nevermind I update Jint from the latest source code and they fixed it =) So SunCalc is working fine now.

g.
Title: Re: JSON Flag for refresh time of widget
Post by: Jan on March 31, 2014, 08:56:24 PM
Hey Gene,

Totally great that you could implement that switch to the presistent http connection so quickly!!

I saw the testing release the other night and installed it right away.

I also experienced the "NaN" on the mac once. But I'm glad to hear that it was due to the Jint.

r356 runs like a charm - cpu load it down to ~8-15% !  :-)

Great work!
Thanks,
jan