Post by jimkernsjr on Jan 9, 2017 1:04:25 GMT
Hi All...
Just a little background, since Computourist developed the great ESP nodes, I have put them to good use both on Sonoff's and an automated roller shade project I developed. I actually have the shades working absolutely teriffic if I send it commands manually via MQTT.
About the programming:
I implemented a device 72, string type that takes the format Lnnn (LETTER, number number number) which is a command to control the shade. Straight from my comments section:
//////////Accepted Device 72 commands:////////////////////////////
// //
// U020 up 20 in //
// D024 down 24 in //
// G010 goto 10 in down //
// P020 goto 20 percent down, so if 50" window same as a G10 //
// R000 resync - Home then back to same postion (more or less) //
// T000 led test - 3 blinks //
// //
// home/esp_gw/sb/node21/16 ON - turns on LED //
// home/esp_gw/sb/node21/16 OFF - turns off LED //
// //
// These commands should be sent to device 72, //
//i.e. home/esp_gw/sb/node32/dev72 G010 //
//////////////////////////////////////////////////////////////////
node 32 is a left shade, node 31 is a right shade in a pair of double windows together.
The hardware:
I built a L shaped hollow box, with an old HP printer stepper motor with a worm drive gear on the end, driven by a darlington to step it. The roller shade has a gear glued to the side of it that sits on the worm gear and turns the shade. The weight of the shade is plenty sitting on the gear for good tension. It senses it's location by a hall sensor at the edge of the box, and a magnet glued inside the bottom bar of the shade. Upon boot-up, and after it's first command, the first thing it does is wheel up the shade, find home, and either go back where it was (resync) or to where you moved it to. It works a treat, accurate to about 2mm!
The problem:
While the ESP is busy driving the stepper, that is ALL it does. It does not process client.loop() nor send acknowledgements. When it receives a command, it acknowledges, then go.
For some reason, the code, especially then 2 are online simultaneously, tends to come disconnected. Part of this is planned (during a motion) and partly not. I really prefer NOT to interrupt the motion by sending it through client.loop while it's driving the stepper...for one, I do a ramp up to not skip teeth or misstep which will lead to an inaccuracy. Seeing as though I don't always know how long client.loop would take, I prefer not to send it through while the shade is in motion. The shade is in a 54" window, so it takes over a minute to go up/down to it's extremities.
To work around said problem, I put a retry loop in the rules of the send mqtt command in OPENHAB. It looks like this:
//Window Shades
//Dev 31 is right, dev32 is left
rule "Shade_HSE_MBR_Position_L Changed"
when
Item Shade_HSE_MBR_Position_L received update
then
Shade_HSE_MBR_Ack_L.state=OFF
val pval = String::format("P%1$03d", (Shade_HSE_MBR_Position_L.state as DecimalType).intValue)
// "mqtt publish" with retry loop
logInfo("rules", "*Rules-Shade_HSE_MBR_Position_R update to: " + pval + ". Transmitting/Posting MQTT msg. RuleRev.6");
var iL = 1
while ((iL<50) && (Shade_HSE_MBR_Ack_L.state==OFF)){
Pub_Shade_HSE_MBR_Command_L.sendCommand(pval)
//logInfo("rules", "*Rules-Shade_HSE_MBR_Position_L -TX msg " + iL);
Thread::sleep(1000)
iL++
}
logInfo("rules", "*Rules-Shade_HSE_MBR_Position_L updated to: " + pval + " after " + iL + " tries.");
if (Shade_HSE_MBR_LockTogether.state == ON && Shade_HSE_MBR_Position_R.state != Shade_HSE_MBR_Position_L.state) {Shade_HSE_MBR_Position_R.state=Shade_HSE_MBR_Position_L.state}
end
I seem to find now that OpenHAB tends to resend messages, even after the shade starts to move. I tend to think that from what I can tell from the log, very often when the slider is moved, it triggers more than once. As you can see, I have a little ACK switch hidden in my items that it watches to know when it's successful. So the problem I've now created is:
Slider moved, and maybe "fumbled"
1st MQTT msg send,
shade acknowledges, slider moves on
second MQTT msg sent
shade is now busy and wont acknowledge, so it keeps sending.
shade is done, finally gets the message again
I use Computourist's built in device 5 to acknowledge BTW
I can sent it for example G005 (Goto 5%), G054, G000, etc etc, and it will aways go where it's told, never misbehaving. I do it with OpenHAB and all H@## breaks loose like it's possessed.
Any better ideas how I can handle the OpenHAB side of it? What I'd really like would be move the slider, disable it, send the message, receive acknowledgement, and when the motion is complete, send one final acknowledgement to re-enable. During this process, disable the rule from a second trigger. I really would prefer not to "rig" the ESP code around the problem, because I feel it's ideal the way it is. I think my code in OpenHAB "spamming" the MQTT bus is really more the problem.
I really went to alot of trouble over this project, and I really want to share the whole thing when I'm done here, including wiring diagrams, rules, parts list, and a 3D print of the housing box. I put too much into it now to just use it for 2 windows for myself, I hope someone else can get some good out of it.
Any ideas?
Just a little background, since Computourist developed the great ESP nodes, I have put them to good use both on Sonoff's and an automated roller shade project I developed. I actually have the shades working absolutely teriffic if I send it commands manually via MQTT.
About the programming:
I implemented a device 72, string type that takes the format Lnnn (LETTER, number number number) which is a command to control the shade. Straight from my comments section:
//////////Accepted Device 72 commands:////////////////////////////
// //
// U020 up 20 in //
// D024 down 24 in //
// G010 goto 10 in down //
// P020 goto 20 percent down, so if 50" window same as a G10 //
// R000 resync - Home then back to same postion (more or less) //
// T000 led test - 3 blinks //
// //
// home/esp_gw/sb/node21/16 ON - turns on LED //
// home/esp_gw/sb/node21/16 OFF - turns off LED //
// //
// These commands should be sent to device 72, //
//i.e. home/esp_gw/sb/node32/dev72 G010 //
//////////////////////////////////////////////////////////////////
node 32 is a left shade, node 31 is a right shade in a pair of double windows together.
The hardware:
I built a L shaped hollow box, with an old HP printer stepper motor with a worm drive gear on the end, driven by a darlington to step it. The roller shade has a gear glued to the side of it that sits on the worm gear and turns the shade. The weight of the shade is plenty sitting on the gear for good tension. It senses it's location by a hall sensor at the edge of the box, and a magnet glued inside the bottom bar of the shade. Upon boot-up, and after it's first command, the first thing it does is wheel up the shade, find home, and either go back where it was (resync) or to where you moved it to. It works a treat, accurate to about 2mm!
The problem:
While the ESP is busy driving the stepper, that is ALL it does. It does not process client.loop() nor send acknowledgements. When it receives a command, it acknowledges, then go.
For some reason, the code, especially then 2 are online simultaneously, tends to come disconnected. Part of this is planned (during a motion) and partly not. I really prefer NOT to interrupt the motion by sending it through client.loop while it's driving the stepper...for one, I do a ramp up to not skip teeth or misstep which will lead to an inaccuracy. Seeing as though I don't always know how long client.loop would take, I prefer not to send it through while the shade is in motion. The shade is in a 54" window, so it takes over a minute to go up/down to it's extremities.
To work around said problem, I put a retry loop in the rules of the send mqtt command in OPENHAB. It looks like this:
//Window Shades
//Dev 31 is right, dev32 is left
rule "Shade_HSE_MBR_Position_L Changed"
when
Item Shade_HSE_MBR_Position_L received update
then
Shade_HSE_MBR_Ack_L.state=OFF
val pval = String::format("P%1$03d", (Shade_HSE_MBR_Position_L.state as DecimalType).intValue)
// "mqtt publish" with retry loop
logInfo("rules", "*Rules-Shade_HSE_MBR_Position_R update to: " + pval + ". Transmitting/Posting MQTT msg. RuleRev.6");
var iL = 1
while ((iL<50) && (Shade_HSE_MBR_Ack_L.state==OFF)){
Pub_Shade_HSE_MBR_Command_L.sendCommand(pval)
//logInfo("rules", "*Rules-Shade_HSE_MBR_Position_L -TX msg " + iL);
Thread::sleep(1000)
iL++
}
logInfo("rules", "*Rules-Shade_HSE_MBR_Position_L updated to: " + pval + " after " + iL + " tries.");
if (Shade_HSE_MBR_LockTogether.state == ON && Shade_HSE_MBR_Position_R.state != Shade_HSE_MBR_Position_L.state) {Shade_HSE_MBR_Position_R.state=Shade_HSE_MBR_Position_L.state}
end
I seem to find now that OpenHAB tends to resend messages, even after the shade starts to move. I tend to think that from what I can tell from the log, very often when the slider is moved, it triggers more than once. As you can see, I have a little ACK switch hidden in my items that it watches to know when it's successful. So the problem I've now created is:
Slider moved, and maybe "fumbled"
1st MQTT msg send,
shade acknowledges, slider moves on
second MQTT msg sent
shade is now busy and wont acknowledge, so it keeps sending.
shade is done, finally gets the message again
I use Computourist's built in device 5 to acknowledge BTW
I can sent it for example G005 (Goto 5%), G054, G000, etc etc, and it will aways go where it's told, never misbehaving. I do it with OpenHAB and all H@## breaks loose like it's possessed.
Any better ideas how I can handle the OpenHAB side of it? What I'd really like would be move the slider, disable it, send the message, receive acknowledgement, and when the motion is complete, send one final acknowledgement to re-enable. During this process, disable the rule from a second trigger. I really would prefer not to "rig" the ESP code around the problem, because I feel it's ideal the way it is. I think my code in OpenHAB "spamming" the MQTT bus is really more the problem.
I really went to alot of trouble over this project, and I really want to share the whole thing when I'm done here, including wiring diagrams, rules, parts list, and a 3D print of the housing box. I put too much into it now to just use it for 2 windows for myself, I hope someone else can get some good out of it.
Any ideas?