ON/OFF/ON State

Hello my friends,
I am trying 5 days now in html code to change the function " function postdata(o)" adding loop, delay, … just to change the button from 0N/OFF to ON/OFF/ON. I mean i need to close from “open” state to change to “close” state for 1-2 seconds and after change auto to “open” state again.

Has anyone tried before?

Friendly Stratos

Hi Stratos.
The following informations will help you.

Please update firmware and demo web pages both.
github.com/Wiznet/WIZ550web/releases/tag/v1.1.1

Thanks.

Eric,
Thank you for your reply, but the first link has nothing to do for what i asked for. I tried many times to change the web page , to add code, so when i use the “ON” button, the button doesn’t stay in ON state but after xx seconds to close again. This is what i can not get.
For example i am trying to make an automation to open the outdoor of the house. I need to modify the code so the button goes again in “off” state after “xx” seconds. I tried with “loop” … but with no result.

Any idea anyone??

Stratos

Hi, Stratos.
I’m sorry for incorrect answer to you.
I guess, you can implement your function using ‘setTimeout’ method.

This code (pseudocode) seems to be operable. Adding and try it.

function postdata(o){ 
 		...
		 }); 
		 dout.doPost('pin='+p+'&val='+v); // #1: on -> turn off (send HTTP request to HTTP server)
	 },300);
	 
	 /* added: setTimeout and re-request to web server */
	 if(o.className=='btn btn-on width-onoff'){v='1';}else{v='0';} // Pin state chagned
	 setTimeout(function(){
	 	dout.doPost('pin='+p+'&val='+v); // #2 off -> turn on after 2 sec (send HTTP request to HTTP server)
 	}, 2000); // 2 sec
 	/* added end */
}

Eric, something is wrong with all the function.
I tried as you said and sometimes it works and sometimes it stays to “ON” state and while you push the button again it returns to “on” state passing from “ON” to “OFF” AND AUTOMATICALLY AGAIN TO “ON”.

Anyway i will check again line by line, but the code is not correct or the module is not responds correct.

Thank you
Stratos

Did you tried using the updated firmware?

To resolve your problem, I think you need debugging more. Please try to module debugging using ‘#define HTTPSERVER_DEBUG’ define in ‘httpServer.h’ file. Using web browser developer tool (press the [F12] button in your web browser) is a good way to debugging.

Hello everybody,

Is this issue still open or has anybody found a solution?

I have just started to implement a similiar JS-function for automation to set all digital outputs at once.

The function is working correctly if I insert an output (alert():wink: between every step/setting (dout.doPost(‘pin=’+p+‘&val=’+v);).
If the alert(); is removed the digital output states are not changed. Even the setTimeout() does not help.

Does anybody has an idea to find a solution?

Help appreciated.
Bachus

I guess I found a solution.

The assumption is the non-blocking asynchronuous behavoir of javascipt and its function setTimeout as root-cause.

I used an own function for a real delay/sleep, blocking/waiting for subsequent processing of a loop.

function sleepFor( sleepDuration ){
    var now = new Date().getTime();
    while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } 
}

function calc(o) {
    var digit=o.value;
    var v;

    for(var p = 0; p < 16; p++) {
        v = digit % 2;
        digit = (digit - v) / 2;
        if(v == 1) {
            v = 0;
        }
        else {
            v = 1;
        }
        if(dout && dout.abort){dout.abort();}
        dout=new AJAX('dout.cgi', function(t){ 
                try{
                    eval(t);		 		
                }catch(e){alert(e);} 
            });
        dout.doPost('pin='+p+'&val='+v);
        sleepFor(40);
    }
}

20 ms delay seems to be okay for reliable processing. Using 10 ms, not every setting was really done in a non-secure channel without acknowledgement.
I’ve used 40 ms and I’m now writing/setting more than 600000 access cycles during the last days.
I guess/hope the delay time may be shorten, if data writing into flash is avoided.

I noticed that using another scripting like Python I have to use at least 100 ms delay time.

This topic is closed for me now, because I found a solution, which is working for me.

Bachus