Hello fellow developers,
I encountered a problem using the level control cluster. In my client application I hit a button which triggers the move to level command. The server application takes it, applies it and in the end calls the emberAfLevelControlClusterServerAttributeChangedCallback. So far so good. Behaviour as expected. But from time to time I see that the move to level command is not processed which I can at my client and server as well (client LEDs feedback, server PWM output). This happens kind of regularly but not deterministic.
When tracing this bug I could se, that the server receives the command (emberAfPreMessageReceivedCallback and emberAfPreCommandReceivedCallback) and even processes (emAfIncomingMessageHandler() -> emberAfProcessMessage()) and parses it (emberAfLevelControlClusterServerCommandParse() --> emberAfLevelControlClusterMoveToLevelCallback(...)) and calls moveToLevelHandler() which returns success. BUt there is no level change happening.
Somehow the the attribute isnt written and therefore the emberAfLevelControlClusterServerAttributeChangedCallback isn't called.
Does somebody know what could be the reason for this misbehaviour?
Could it be
' // The setup was successful, so mark the new state as active and return.
status = EMBER_ZCL_STATUS_SUCCESS;' (line 616-618 in level-control.c)
has problems scheduling the event, if 'eventDurationMs' is set to '0' or am I following the wrong path here?
I hope you can help me.
I created a "closed loop" system with COO sending a move-to-level command and light sending a response from the emberAfLevelControlClusterServerAttributeChangedCallback function when the move-to-level command was received.
I ran this for several hours with a 1 sec interval between commands (~ time to move between levels) comparing the sent command to the actioned message. No commands were lost - ie every move-to-level command was acted upon.
I may need more information on your setup to accurately configure a comparable test (ie stack version, compiler, device number, clusters used, times etc)?
thank you for your replies.
My Setup is:
Simplicity Studio Version 184.108.40.206
EmberZNet SDK 220.127.116.11
32 bit MCU SDK 18.104.22.168
Toolchain: GNU ARM v7.2.1
On the Remote Control and the application control I use a customized Hardware with an mgm13p02f512ga.
The Remote Control is derived from the Z3 Switch Example and uses just endpoint 1 with the LO Dimmer Switch Configuration.
The application control is trickier. It acts as Coordinator or Router ( depending on a switch configuration which is evaluated at device init). If it is Coordinator it aditionally acts as the whole applications Master.
It gets the commands by the remote control, processes and applies it and then forwards it via broadcast to the as slave configured devices. In the current setup there is for testing purposes finding this bug no slave device.
So the flow is:
RC calls the move to level command:
emberAfGetCommandApsFrame()->sourceEndpoint = 1;
sendDataFrame = buildDataFrame(inData);
emberAfFillCommandLevelControlClusterMoveToLevel(sendDataFrame, 0xffff, 0, 0);
The Coordinator/Master gets it and it's emberAfLevelControlClusterServerAttributeChangedCallback(..) reads the attribute into a a variable which gets applied in the application and then takes it processes it in a new command where it's endpoint 2 is used ( kind of a 'master client' endpoint) and sends it via broadcast.
Additionally the coordinator sends every minute an on/off toggle command via broadcast to all slaves.
That's the application's structure so far.
On the RC remote control and the application control I use a classic time state machine derived by TIMER1 interrupt. Every 50ms a flag is set and in the maintickcallback i check for this flag und let the application code happen.
And as I mentioned before, when debugging the application control and the described error happens I was able to follow all actions to the movetolevel handler which even returns emberstatus_success. So I guess there is a timing problem like the scheduled event which should trigger the emberAfLevelControlClusterServerAttributeChangedCallback gets lost somewhere.
Do you need any more information?
@YK: No, I send the command on the button press of a user, I don't use the Button interrupt provided by the framework, I have an own written ported button API evaluating the GPIO Inputs, which polls every 50ms. The API is well known, safe and tested. I see the command firing once after press, in Debugging Mode And in Network Analyzer. Sniffing with the Analyzer I see the Command is being sent to the coordinator and it responds with an ACK. For synchronization purposes after that I ask the Coordinator via 'emberAfFillCommandGlobalClientToServerReadAttributes(LEVEL_CONTROLCLUSTER, &state, sizeof(state));' if he really updated.
As said most of time this totally works for me, but then... for a few minutes it doesnt work anymore and later it again works
Thanks for the detailed information - helps look into the potential cause of the problem. I have a few Silabs EmberZNet lights in service so would be interested in finding out if this is in fact a stack or 'developer' issue.
So far I have not found any reasons to indicate the former (ie stack issue) and am trying to emulate your system as closely as possible to see if I can discover a reason for the dropped callbacks. Unfortunately I have yet to see a dropped callback so it could be a timing issue where a new attribute value is sent to the framework while another is being handled?
BTW. A duration of 0 isn't the issue as it just means the event is immediately activated without going through the event process...
The only time I see a level control message being ignored is when there is no actual change in level...
I have created new test apps using the commands and settings you specified and they also work fine - though I will test more today to see if any problems arise.
In the current setup there is for testing purposes finding this bug no slave device
Does the code to broadcast to slave devices still get called or did you remove it for debugging purposes?