more G-Labs products

Author Topic: JSON Flag for refresh time of widget  (Read 1966 times)

March 29, 2014, 07:55:47 PM
Read 1966 times

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
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

March 29, 2014, 08:36:47 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
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.
« Last Edit: March 29, 2014, 08:38:42 PM by Gene »

March 29, 2014, 09:36:46 PM
Reply #2

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
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

March 30, 2014, 07:46:10 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
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.

March 31, 2014, 11:25:53 AM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
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.

March 31, 2014, 12:04:05 PM
Reply #5

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Nevermind I update Jint from the latest source code and they fixed it =) So SunCalc is working fine now.

g.

March 31, 2014, 08:56:24 PM
Reply #6

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
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