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

Kingart curtain switch UI support #2250

Merged
merged 15 commits into from
May 17, 2020
Merged

Kingart curtain switch UI support #2250

merged 15 commits into from
May 17, 2020

Conversation

echauvet
Copy link
Contributor

@echauvet echauvet commented May 13, 2020

This is a preliminary commit to extend KA work by @AlbertWeterings. Using AT+START commands, we know the real position of the curtain. Small MCU bugs are bypassed as commented in the code.
The UI is animated and displays :

  • A basic animation of the curtain opening (4 types available) - this reflects the real position of the curtain if the switch is correctly calibrated ( the MCU adds 2 seconds to the initial calibration)
  • The 3 buttons are displayed and animated (blue/red colors) as the curtain switch. (this is achieved with AT+START commands and move status detection)
  • A slider to set an absolute position. Its position is refreshed whenever the curtain stops moving.

image

A configuration panel as been created to choose:

  • The curtain type. I will use it later for mqtt to integrate a basic UI layout of the curtain
    image
  • Once rebooted/powered on, the curtain initial position could be set
    image

Next steps are code cleaning, integrate any reviews from contributors and improve the MQTT stack with RedNode. For now, I can drive my curtain as a Google curtain, or a switch or a lamp bulb (for brightness setting). I'm preparing some demo flow with Google legacy curtain, and the hybrid solution.

Both core base and latest-base are working - with latest-base, a two steps upgrade is required.
I'm cheking the work done for OTA in RedNode to check if some code is ready for 2 steps upgrade.

All Tests has been done using a curtain switch, espurna UI, google home and RedNode UI and all seems to animate together without bugs.

echauvet and others added 4 commits May 13, 2020 17:20
Added Web UI controls and view in status
Added power up behaviour (nothing, close, open, last position)
Added curtain style (Roller, etc...) for UI status and to be used in MQTT
…ling position from received messages. Added comment to debug tab to show how to enable debug
Copy link
Collaborator

@mcspr mcspr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

  • If you don't mind going over code comments once more, please verify that those still apply.
  • We should explain magic numbers in code (and, if possible, in log too). I've added some helpers for getSetting() 2nd arg, we can map any type from string. see namespace settings { namespace internal in relays / buttons / sensors.
  • We don't enforce any specific style / formatting... But one thing I am not a fan of is if (cond) expr;, unless those are one-liners like if (something) return;. Having brackets is preferable.

code/html/custom.js Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
echauvet and others added 7 commits May 14, 2020 17:38
Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>
Added public set position function and curtain count
…ot (00:00 after refresh). Default Hour is 12h
Schedule support.
Light support is having an issue with new schedules corrected here.
Copy link
Collaborator

@mcspr mcspr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think a bit more about the scheduler stuff? I am not sure restoring works like that, but I'd expect normal operation mode does. This can be a separate patch, not to complicate things further.

If you are ok with kingart .cpp stuff, I'll reformat it for the merge.

code/espurna/scheduler.cpp Outdated Show resolved Hide resolved
code/espurna/scheduler.cpp Outdated Show resolved Hide resolved
code/espurna/scheduler.cpp Outdated Show resolved Hide resolved
code/html/custom.js Show resolved Hide resolved
code/espurna/curtain_kingart.cpp Outdated Show resolved Hide resolved
@@ -311,7 +337,7 @@ void schSetup() {

static bool restore_once = true;
if (restore_once) {
for (unsigned char i = 0; i < relayCount(); i++) {
for (unsigned char i = 0; i < schedulableCount(); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this step on schCheck id resolution? If we have 1 relay and 1 curtain, for example.

Copy link
Contributor Author

@echauvet echauvet May 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done a big answer and as a result:
image
So the quick answer is that I tested all with a dummy switch in hardware.h and you can choose between both types and it works:
image

Switch and curtain schedule task worked.
This is how the light schedule bug has been detected (it stays as a switch schedule instead of light schedule)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific block, schCheck will recursively check every 'rule' that uses specific relayID (index from old relayCount()) and goes back a week day-by-day to check if rule applies in the past.
Although, we don't count light channels, so it's still sort-of broken because of non-matching ID / indexes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood! In fact, we need specific processing for curtain.

@AlbertWeterings
Copy link
Contributor

Great work you are doing Eric, your work makes the Curtain switch usable for many people that are not using it only over MQTT. I did not have the knowledge and time to build the web interface so I took off after MQTT was finished and my 9 shutters where moving the way I wanted them to move.

In your code I fount this:
// Need to send confirmation to the N76E003AT20 that message is received
// ECH : TODO Check this is the case every time
_KACurtainSend("AT+SEND=ok");

I can confirm it is mandatory to confirm to the N76E003AT20 that every message send by it is received. When I started working on it I found that after power up the switch it takes about 30sec before the N76E003AT20 starts sending messages (just not log enough to flash the ESP) so at first I had jumpers on the data lines to disconnect both chips from each other and be able to flash ESPURNA. After silencing the N76E003AT20 flashing is possible. Now a day's we have to OTA flash in two stages this is possible as long the N76E003AT20 stay's quiet after a power cycle flashing is not possible anymore as the N76E003AT20 is corrupting the flash process.

I have been logging communication between both chips with the original software for quite some time to fully understand how it works.

@mcspr
Copy link
Collaborator

mcspr commented May 17, 2020

Now a day's we have to OTA flash in two stages this is possible as long the N76E003AT20 stay's quiet after a power cycle flashing is not possible anymore as the N76E003AT20 is corrupting the flash process.

re. some discussions in the Core repository and general observations about reboot.
Perhaps we need to do Serial.end() before doing OTA? Chip persist some of the configuration between sw reboots, including pins state / uart / etc.

@AlbertWeterings
Copy link
Contributor

b.t.w. Flashing over serial also fails as the N76E003AT20 starts sending data during flashing. This can be solved by holding it's pin 4 or on the rear side of the board RES1 to GND this keeps the N76E003AT20 in reset state.

Copy link
Collaborator

@mcspr mcspr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging as-is b/c curtain part is done, delaying scheduler changes (?) for later.

@mcspr mcspr merged commit 21e75be into xoseperez:dev May 17, 2020
@echauvet
Copy link
Contributor Author

@AlbertWeterings the solution I found is to calibrate the curtain to a very long period for intial flash so the MCU does not send messages until the closed position is not reached. Do you confirm that this is the AT+UPDATE message "setclose":0 "switch":"off" sent at the end of the first move which breaks the update? If so, just calibrate curtain opening to > 60s - this will be enough to keep MCU quiet.

@AlbertWeterings
Copy link
Contributor

@echauvet This is a nice work around at the moment you are blocked from flashing after something went wrong. I think good to document. I preferer to silence the MCU in the software by confirming the last message is understood. I did a quick test, you can preform a OTA 2 stage update without problems when ESP is rebooting the MCU doesn't. Only if someone is touching the buttons the MCU starts repeating it's last message and flashing is not possible. Disabling the serial port during OTA flash procedure as @mcspr referred to is the best sollution.

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

Successfully merging this pull request may close these issues.

3 participants