Table of Contents

Webpage Digital Output Pulse

This Skript will offer an additional webpage on the Web Manager HOME Page. You can trigger a Pulsesignal on the two Digital Outputs with a specific Length

This Way you can trigger a external Reset Signal for a device, e.g. a PC or a Measurment Device.

The Page can also be view by restricted non-admin users.

Requirements

Please have at least NRSW 4.0.0.106 installed

Installation

Please combine this script with the sdk-startup trigger into a job

The Script

/* DESC: This script will generate a page which can be viewed in the Web Manager
* You can trigger a pulse signal on the Digital Output of a specific length
* Copyright (C) 2017 NetModule AG, Switzerland, jj
*/
 
 
ID=1;
timeout1=(int)nb_config_get("custom.var1");
timeout2=(int)nb_config_get("custom.var2");
 
 
bool diopulse(string ifc, int timeout) {
 nb_syslog("We a sending a pulse on %s, length %d",ifc,timeout);
 nb_dio_set(ifc,1);
 sleep(timeout);
 nb_dio_set(ifc,0);
return true;
}
 
 
 
page = nb_userpage_register(ID, "Trigger", "DIO");
 
 
    printf("waiting for requests...\n");
while (1) {
 
            /* wait for page request */
     request = nb_page_request(page);
     if (!is_void(request)){ 
             /* evaluate GET params */
            htable = mkstruct("key","value");
            GET = struct_get(request, "GET"); 
           for (k = 0; k < length(GET); k++) {
                 key = struct_get(GET[k], "key");
                 value = struct_get(GET[k], "value");
                 htable = struct_set(htable,key,value);
 
                }
            reqifc=struct_get(htable,"ifc");
            reqlength=(int) struct_get(htable,"length");
            if (strlen(reqifc)>0 && is_int(reqlength)){
                diopulse(reqifc,reqlength);
                if(reqifc=="out1") { 
                        timeout1=reqlength;
                        nb_config_set(sprintf("custom.var1=%i",timeout1));
                        }
                if(reqifc=="out2") { 
                        timeout2=reqlength;
                        nb_config_set(sprintf("custom.var2=%i",timeout2));
                        }
 
            }
     }
 
 
    nb_page_respond(page,'<h1>Digital I/O Port Pulse</h1>
        <p>This button will close the Relais on the regarding OUTPUT for a specific time and open it again afterwards </p>
        <table>
            <tr>
                <td class=c2_left>
                  <table style="border: 0px; margin: 0; padding: 0;">
                    <tr style="border: 0px; margin: 0; padding: 0;">
                      <td style="border: 0px; margin: 0; padding: 0; vertical-align: middle; width: 75px;">Digital Out 1:</td> 
                      <td style="border: 0px; margin: 0; padding: 0; vertical-align: middle;"><img src="img/dio_off.png" style="height: 16px;"></td>
                    </tr>
                  </table>
                </td>
                <td class=c2_right>
                  <table style="border: 0px; margin: 0; padding: 0;">
                    <tr style="border: 0px; margin: 0; padding: 0;">
                      <td style="border: 0; margin: 0; padding: 0; vertical-align: middle;">
                        <form autocomplete="off" name="form1" METHOD="GET" ACTION="sdkPage.php">
                            <input type="submit" name="button" value="Trigger Output 1">
                            <input type="hidden" name="ifc" value="out1">
                            <input type="text" name="length" value="%d"size="4">  length in sec
                            <input type="hidden" name="id" value="%08X">
                        </form>
                      </td>
                    </tr>
                  </table>
                </td>
            </tr>
            <tr>
                <td class=c2_left>
                  <table style="border: 0px; margin: 0; padding: 0;">
                    <tr style="border: 0; margin: 0; padding: 0;">
                      <td style="border: 0; margin: 0; padding: 0; vertical-align: middle; width: 75px;">Digital Out 2:</td> 
                      <td style="border: 0; margin: 0; padding: 0; vertical-align: middle;"><img src="img/dio_on.png" style="height: 16px;"></td>
                    </tr>
                  </table>
                </td>
                <td class=c2_right>
                  <table style="border: 0px; margin: 0; padding: 0;">
                    <tr style="border: 0; margin: 0; padding: 0;">
                      <td style="border: 0; margin: 0; padding: 0; vertical-align: middle;">
                        <form autocomplete="off" name="form1" METHOD="GET" ACTION="sdkPage.php">
                            <input type="submit" name="button" value="Trigger Output 2">
                            <input type="hidden" name="ifc" value="out2">
                            <input type="text" name="length" value="%d" size="4">  length in sec
                            <input type="hidden" name="id" value="%08X">
                        </form>
                      </td>
                    </tr>
                  </table>
                </td>
            </tr>
 
     </table>',timeout1,ID,timeout2,ID);
 
    nb_page_finish(page); 
 
    sleep(1);
 
}