maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Sonoff basic switch with SailfishOS (https://talk.maemo.org/showthread.php?t=100644)

Markkyboy 2019-03-29 12:52

Re: Sonoff basic switch with SailfishOS
 
I also found another app in Jolla Store which works well with Tasmota/Sonoff; that app is 'd1webclient' by jsm.

With a few minor changes made in the UI, it is very usable. With this app, you can combine all functions to its 'main page', so no need to see the full Tasmota UI every time, quite handy I thought. Functions can be added to the cover; example: I can turn off my desk lamp from the cover - very handy indeed if you have one particular function you use regularly.

Markkyboy 2019-04-03 12:06

Re: Sonoff basic switch with SailfishOS
 
I need some help with the following;

I'm making a webview app for tasmota, it has 2 preset cover actions; 1 for toggling power of my 'sonoff basic' and the other for my main desk lamp via 'sonoff RF bridge'.

When I press either of my cover action buttons, I get the desired result (light off or on; power off or on), the first press of either button returns the http response data and displays it on the cover, but pressing either of the cover actions after the initial press, the response message is not displayed - why is this response text not repeatable?, what do i need to do so that each time a cover action is pressed, I get the response text displayed.

I think Timer may have something to do with the problem, or does it?,

Here's my code so far;

Code:

        CoverAction {
            iconSource: "image://theme/icon-cover-location"
            onTriggered: getData();

            function getData(url) {
                var xhttp = new XMLHttpRequest();
                var url = "http://192.168.1.201/cm?cmnd=rfkey1"

                xhttp.onreadystatechange=function() {
                    if (xhttp.readyState == XMLHttpRequest.DONE) {
                        console.log(xhttp.responseText);
                        mainText.text = xhttp.responseText;
                    }
                };
                xhttp.open("GET", url);
                xhttp.send();
            }
        }
    }
    Label {
        text: ""
        id: mainText
        x: Theme.paddingMedium
        horizontalAlignment: Text.AlignHCenter
        font.pixelSize: Theme.fontSizeExtraSmall
        width: parent.width -x*2
        anchors {
            bottom: cover.bottom
            bottomMargin: Theme.paddingLarge*4
            horizontalCenter: parent.horizontalCenter
        }
        Timer {
            interval: 5000; running: true;
            onTriggered: mainText.opacity = 0.0;
        }
    }


Markkyboy 2019-04-18 16:30

Re: Sonoff basic switch with SailfishOS
 
Quote:

Originally Posted by Markkyboy (Post 1555887)
I need some help with the following;

I'm making a webview app for tasmota, it has 2 preset cover actions; 1 for toggling power of my 'sonoff basic' and the other for my main desk lamp via 'sonoff RF bridge'.

When I press either of my cover action buttons, I get the desired result (light off or on; power off or on), the first press of either button returns the http response data and displays it on the cover, but pressing either of the cover actions after the initial press, the response message is not displayed - why is this response text not repeatable?, what do i need to do so that each time a cover action is pressed, I get the response text displayed.

I think Timer may have something to do with the problem, or does it?,

Here's my code so far;

Code:

        CoverAction {
            iconSource: "image://theme/icon-cover-location"
            onTriggered: getData();

            function getData(url) {
                var xhttp = new XMLHttpRequest();
                var url = "http://192.168.1.201/cm?cmnd=rfkey1"

                xhttp.onreadystatechange=function() {
                    if (xhttp.readyState == XMLHttpRequest.DONE) {
                        console.log(xhttp.responseText);
                        mainText.text = xhttp.responseText;
                    }
                };
                xhttp.open("GET", url);
                xhttp.send();
            }
        }
    }
    Label {
        text: ""
        id: mainText
        x: Theme.paddingMedium
        horizontalAlignment: Text.AlignHCenter
        font.pixelSize: Theme.fontSizeExtraSmall
        width: parent.width -x*2
        anchors {
            bottom: cover.bottom
            bottomMargin: Theme.paddingLarge*4
            horizontalCenter: parent.horizontalCenter
        }
        Timer {
            interval: 5000; running: true;
            onTriggered: mainText.opacity = 0.0;
        }
    }


Hmmm, okay, no responses then, I guess that means nobody knows the answer..?, fair enough!, back to the drawing board :/

coderus 2019-04-18 16:47

Re: Sonoff basic switch with SailfishOS
 
your timer hides label after 5 seconds

Thoke 2019-04-19 08:47

Re: Sonoff basic switch with SailfishOS
 
What @coderus said and to explain further the opacity is never set back to 1.0 so it will never return to be visible.

Markkyboy 2019-04-21 09:19

Re: Sonoff basic switch with SailfishOS
 
Quote:

Originally Posted by coderus (Post 1556215)
your timer hides label after 5 seconds

correct, that's what I want it to do and when a cover action is pressed again, I want the test to appear and fade away again, but I cannot work out how to make the text re-appear on the next press.

Markkyboy 2019-04-21 09:27

Re: Sonoff basic switch with SailfishOS
 
Quote:

Originally Posted by Thoke (Post 1556222)
What @coderus said and to explain further the opacity is never set back to 1.0 so it will never return to be visible.

Yep, I already know that is the problem, which is why I am asking for a resolution, I don't know how to make the text visible again when the cover action is pressed again.

coderus 2019-04-21 10:04

Re: Sonoff basic switch with SailfishOS
 
set text, set opacity to 1, start timer

Markkyboy 2019-05-02 10:41

Re: Sonoff basic switch with SailfishOS
 
Quote:

Originally Posted by coderus (Post 1556238)
set text, set opacity to 1, start timer

Thanks, could you give me an idea of syntax?, how to lay it out?, I'm looking for examples but not finding much related.

coderus 2019-05-02 10:44

Re: Sonoff basic switch with SailfishOS
 
assign id for your TImer, remove running: true, after mainText.text = line add mainText.opacity = 1.0 and yourTImerId.start()


All times are GMT. The time now is 04:54.

vBulletin® Version 3.8.8