View Single Post
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#122
The following code is a part of a Row, the Rectangle acts as a button and sends an IR command via WiFi to a Tasmotised Sonoff RF;

Code:
                
    Rectangle {
        id: mainLights1
        width: 80
         height: 80
         radius: 40
         color: "transparent"
         border.color: "yellow"
         border.width: mini1.pressed ? 4 : 2
         MouseArea {
             id: mini1
             anchors.fill: parent
             onClicked: {
                 var xhttp = new XMLHttpRequest()
                 xhttp.onreadystatechange = function() {
                     if (xhttp.readyState === 4 && xhttp.status === 200) {
                         led.opacity = 1.0
                         timer.start()
                         vibrate.start()
                         mainLights1.radius = 40

                         mainLights1.border.color = "green"  <-- ON, color is green

                         console.log("Main light1" + " " + xhttp.responseText)
                     }
                     else mainLights1.radius = 20
                 }
                 xhttp.open("POST", "http://192.168.0.230/cm?cmnd=cmnd/mini1/power toggle")
                 xhttp.send()
            }
        }
        Label { text: "<b>PATIO</b>" ; anchors.centerIn: parent; color: "white"; font.pixelSize: Theme.fontSizeTiny }
    }
I'd like the following to happen when pressing the button;

Light ON = GREEN (mainLights1.border.color) - DONE
Light OFF = YELLOW (mainLights1.border.color) - ????

I've tried so many things, too many to list. Perhaps using 'if/else' is not the way to go?
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following User Says Thank You to Markkyboy For This Useful Post: