Aller au contenu

HC3 - 5.040.37 - 23/07/2020


TonyC

Messages recommandés

Oui mprinfo a bien résumé

et ce genre de discussion n'a rien à faire dans la section pour les nuls, car déjà c'est un sujet avancé, et c'est un topic de travail amené à évoluer. Ça a été déplacé par un modérateur, je vois que c'est dans Support HC3, je ne sais pas si c'est le meilleur endroit, mais y'a pas trop d'endroit idéal pour ce genre de sujet.

  • Like 1
Lien vers le commentaire
Partager sur d’autres sites

Ma charge moyenne du CPU à nettement diminuée avec les optimisations préconisées...

 

image.thumb.png.5cdd60d520adb4a169ed30a93047e685.png

 

et je suis sûr que je peux encore mieux faire !

 

en tout cas merci pour les conseils !! ;) 

 

Cela dit, mon histoire de script avec les notifications n'est pas résolu, il est tout simplement désactivé pour le moment...

Va falloir sérieusement que je m'y colle !

  • Like 1
  • Upvote 1
Lien vers le commentaire
Partager sur d’autres sites

@Lazer :  : pour en revenir à l’optimisation des fonctions, ce principe est toujours correct ? 

 

- bouclage de la fonction principale

- selon les cas, appel de la sous fonction x

 

function Principale()

	if ... then setTimeout(0, MaSousFonction1()) end
	if ... then setTimeout(0, MaSousFonction2()) end

	setTimeout(50, Principale())
end

function MaSousFonction1()
	...
end

function MaSousFonction2()
	...
end

 

 

Lien vers le commentaire
Partager sur d’autres sites

Helper function?

local function call(f,...) 
  local args = {...}
  if type(f)=='number' then return setTimeout(function() args[1](select(2,unpack(args))) end,f) 
  else return setTimeout(function() f(unpack(args)) end,0) end
end

function foo1(x)
  print(x)
  if x < 10 then 
    call(foo1,x+1)  -- 0s delay
  end
end

function foo2(x)
  print(x)
  if x < 10 then 
    call(1000,foo2,x+1) -- 1s delay
  end
end

function QuickApp:onInit()
  foo1(0)
  foo2(0)
end

and

function main()

	if ... then call(MySubFunction1,42) end
	if ... then call(MySubFunction2,17) end

	call(50,main)
end

function MySubFunction1(x)
	...
end

function MySubFunction2(x)
	...
end

 

  • Like 3
Lien vers le commentaire
Partager sur d’autres sites

Performance worries...

function foo3(x,y) return (x or 5)+(y or 6) end

function QuickApp:onInit()
  local function printf(...) self:debug(string.format(...)) end
  local n = 1000
  local t0 = os.clock()
  for i=1,n do setTimeout(foo3,0) end
  local t1 = os.clock()-t0
  printf("SetTimeout:%.3fms",1000*t1/n)
  t0 = os.clock()
  for i=1,n do call(foo3) end
  local t2 = os.clock()-t0
  printf("Call:%.3fms",1000*t2/n)
  printf("Factor:%.2f",t2/t1)
end
[02.08.2020] [11:02:26] [DEBUG] [QUICKAPP1449]: SetTimeout:0.015ms
[02.08.2020] [11:02:26] [DEBUG] [QUICKAPP1449]: Call:0.019ms
[02.08.2020] [11:02:26] [DEBUG] [QUICKAPP1449]: Factor:1.28

 

  • Like 3
Lien vers le commentaire
Partager sur d’autres sites

@jang yes, a lot of questions about...

 

I have some problems with a function which modify the Notifications properties of device in API /deviceNotifications/V1.

The box crashes when the script modifies the API while a device is changing his state.

Since the latest update...

 

So I juste change my code and now I use my QA which check the RefreshState every 50 ms.

And case of certains criteria, I notify or not...

It works fine.

 

But this script begins to do a lot of thing !!

It allows me to (with another specifics QA of course, all is not in the same QA :):

  • send debug data in database through a socket
  • send events of devices in a soft for an IHM through a another socket
  • switch ON/OFF the lights with PIR sensor
  • send Events from notifications panel by mail
  • and now, notify me by Push, TTS, mail or Prowl of states of devices

This script is very big and it works fine !

I have in, a big variable table with all devices and informations to make what I need.

But I ask me some questions above performances...

 

I ask me if I should not create a new QA for notifications, but always with API RefreshState...

And why not for the Lights with PIR...

but 2 or 3 script which question the same API every 50 ms !! 

It's not too ??

 

I don't know what doing... what is the best method...

This QA replaces the multi instances of scenes...

Lien vers le commentaire
Partager sur d’autres sites

api.get("/refreshState returns when there are events available - or times out after ~30s with empty events.

So you will not always poll every 50ms.

I always do http:request("http://127.0.0.1:11111/api/refreshStates?last=" .. lastRefresh... these days so I will not block other timers. (Ex. QA_Toolbox)

 

You could have a master QA that push events to your other QAs.

Pseudo code:

QA.id=42  {
       subscribers = {43,44}
       while(true)
         events = get refreshState
         if events then 
           for _,id in ipairs(subscribers) do
               fibaro.call(id,"NEW_EVENTS",events)
           end
        end
      end
}

QA.id=43 {
       function QuickApp:NEW_EVENTS(events)
        ...
       end
}

QA.is=44 {
       function QuickApp:NEW_EVENTS(events)
        ...
       end
}

You could add additional filtering to only send relevant events to each QA.

 

Lien vers le commentaire
Partager sur d’autres sites

Il y a 1 heure, jang a dit :

So you will not always poll every 50ms.

I must poll it quickly !

I need to intercept the change of state of PIR sensor for switch ON/OFF lights...

and to update an IHM...

It must be reactive...

 

My code looks like yours : 

 

I have 2 setTimeout, one for main loop, and one for each treatment...

is it correct ?

 

Function Main()

	local res = self.http:request("http://127.0.0.1:11111/api/refreshStates?last=" .. self.lastRefresh,{

	success=function(res)
	
		for _,e in ipairs(res.data.states.events or {}) do

                fibaro.setTimeout(0, function() 
	
					if ...Filter1... then
						...
						fibaro.call(QA1, "Function", ...)
					end
					
					if ...Filter2... then
						...
						fibaro.call(QA2, "Function", ...)
					end
					
					if ...Filter3... then
						...
						fibaro.call(QA3, "Function", ...)
					end

					...
				end)
		end
	
		setTimeout(Main(), 50)
	end,
	
	error = function(res)
		...
		setTimeout(Main(), 50)
	end,
	)}	
end

 

Lien vers le commentaire
Partager sur d’autres sites

Should be - setTimeout (Main, 50) - not setTimeout (Main(), 50)

Anyway, it looks ok. My point was that sometimes the success() will not be called until there are events available. e.g. > 50ms.

You could think about how to do the filtering effective with some kind of dispatch table....

 

  • Like 1
Lien vers le commentaire
Partager sur d’autres sites

il y a 4 minutes, jang a dit :

will not be called until there are events available

I understand, but I can't wait 2 even 1 second to switch ON a light, it must be instantly... when the sensor up to true...

 

example of filters I use : 

 

if e.type == 'DevicePropertyUpdatedEvent' and e.data.property ~= 'quickAppVariables' then
...

elseif e.type == "NotificationCreatedEvent" then
...

 

 

Lien vers le commentaire
Partager sur d’autres sites

il y a 3 minutes, jjacques68 a dit :

I understand, but I can't wait 2 even 1 second to switch ON a light, it must be instantly ... when the sensor up to true ...

No problem. success() will be called immediately when the sensor event is available. It's just the the HTTP request is hanging until there are events available.

 

If you have many event types a table like this can make sense - if you only have 2 it is not worth it.

Events={
  DevicePropertyUpdatedEvent = function(e) 
     if e.data.property == 'quickAppVariables' then return end
     for _,id in ipairs({...}) do fibaro.call(id,"Function",e) end
  end,
  NotificationCreatedEvent = function(e) 
     for _,id in ipairs({...}) do fibaro.call(id,"Function",e) end
 end,
}

if Events[e.type] then Events[e.type](e) end

 

Lien vers le commentaire
Partager sur d’autres sites

Ma HC3 a enfin planté elle en a mis du temps :D

 

Je fais un backup tout les 2 jours pour voir

voila ce que cela donne la seul chose que j'ai touché c'est l'inclusion et l'exclusion de modules je n'en ai pas ajouté au final j'ai juste inclus puis exclus le module a partir du 27/07/2020

 

1.jpg.a473fa351a125afbe56011bad5491c39.jpg

 

Je crois que c'est pas pour demain qu il faut miger sur HC3 car fibaro fait toujours du fibaro :D

 

Ma HC2 a encore de beaux jours devant elle :D

Lien vers le commentaire
Partager sur d’autres sites

J'ai déplacé les messages dans le bon topic, et j'ai fait un peu de ménage

 

Une fois de plus, c'est mprinfo qui a posté n'importe où.... ça devient une habitude cette saison... la chaleur te tape sur la tête ? Fait attention à ton age :P

  • Like 1
Lien vers le commentaire
Partager sur d’autres sites

Plus sérieusement, pourriez-vous me décrire les symptômes EXACTS du plantage ?

 

- Page web affichée

- Code d'erreur

- Résultat de la page /api/service/servicesStatus

- toute information utile

 

Afin que je vois s'il est possible de porter mon watchdog HC2 sur la HC3

 

Le seul plantage de mon HC3 a occasionné un reboot automatique avec restauration automatique, comme j'en avait déjà parlé.

 

Lien vers le commentaire
Partager sur d’autres sites

J'ai déplacé les messages dans le bon topic, et j'ai fait un peu de ménage
 
Une fois de plus, c'est mprinfo qui a posté n'importe où.... ça devient une habitude cette saison... la chaleur te tape sur la tête ? Fait attention à ton age
Désolé Christophe je croyais être dans le topic hc3 et le pire c'est que j'étais sur pc

Envoyé avec Tapatalk

  • Like 1
Lien vers le commentaire
Partager sur d’autres sites

alors dans mon cas c'est simple

 

aux vu des fichiers .fbi qui augmentent de 1 Mo par jour (qui du coup fond planté le backup automtique, car trop long visiblement), j'ai fait un "REPAIR" depuis le Recovery (sur les conseils du supports)

 

et la c'est la dégringolade...

 

le "REPAIR" à visiblement pas fonctionné du tout.

La box a redémarrer 3 fois de suite sans résultat.

Elle est entrée en mode "repair auto"

elle m'a retrogradé en 5.037 (avec le Sytem B )

J'ai donc perdu toutes mes modifications d'optimisation de script en 5.040

J'ai essayé de restaurer la 5.040 sans succès (depuis l'interface web) --> echec.

Plus de reboot plossible.

J'ai forcer le mode recovery depuis les boutons sur la box, et voulu utiliser un des fichiers générés par le backup du Syno.

Marche pas car pas la bonne extension

J'ai compressé le fichier .fbi en .7z.

La restauration à fonctionné.

J'ai rebooté, et ça a planté anouveau.

Du coup reset usine.

Depuis l'interface WEB, j'ai restaurer le dernier backup du Syno (depuis l'interface WEB, il accepte les fichier .fbi)

Là ça à l'aire OK.

 

Je viens de faire un backup, et je suis à 14 Mo !!!!

 

 

Lien vers le commentaire
Partager sur d’autres sites

Et bah dis donc, ça fait peur....

 

De mon coté j'ai juste constaté un petit bug non bloquant sur cette mise à jour, sur la date de dernier déclenchement d'un capteur (ça le fait sur tous, détecteur de mouvement, capteur d'ouverture...) :

 

image.png.03a7cc10c9b6943f3922124b5296fdff.png

 

 

Elle ressemble bien à une beta cette version.....

 

Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...