Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="ru-RU">
- <head>
- <link rel="shortcut icon" type="image/gif" href='data:image/gif;base64,Qk12AgAAAAAAAHYAAAAoAAAAIAAAACAAAAABAAQAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAICAgADAwMAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////u7u7u7u7u7u7u7u7u7u7+7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7MzMzMzMzMzMzu7u7szMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzLu8y7vMu7zLu8y7vMu7zMy5vMurzLq8y8vMvLzLy8zMu7zLu8y7vMu7zLu8y7vMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzu7u7szMzMzMzMzMzO7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7+7u7u7u7u7u7u7u7u7u7v////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'>
- <title>PIE Arduino Webserver v2.0</title>
- <script type="text/javascript">
- let domReady_Flag = 0;
- let channel_TPL = '';
- let reqAddr = '/';
- function send_request(addr, params, callbackResponse) {
- let xhr = new XMLHttpRequest();
- xhr.open('POST', addr);
- xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xhr.send(params);
- if (typeof callbackResponse !== 'undefined') {
- if (typeof xhr.onload !== 'undefined') {
- xhr.onload = function() {
- if (xhr.status == 200) {
- callbackResponse(xhr.responseText);
- }
- }
- }
- }
- }
- function setChannel_state(channel, state) {
- send_request(reqAddr, 'act=setChannel_state&state=' + state + '&channel=' + channel, function(response) {
- var channelTD = document.getElementById('ch' + channel) || undefined;
- if (channelTD) {
- try {
- var js = JSON.parse(response);
- channelTD.setAttribute('class', js.state);
- } catch (e) {
- }
- }
- });
- }
- function readChannel_State(channel, callback, callbackError) {
- send_request(reqAddr, 'act=readChannel_State&channel=' + channel, function(response) {
- try {
- var js = JSON.parse(response);
- result = js[channel];
- if (typeof callback !== 'undefined') callback(channel, result);
- } catch(e) {
- if (typeof callbackError !== 'undefined') callbackError(e);
- }
- });
- }
- setInterval(function() {
- if (domReady_Flag) {
- for (var i = 1; i <= 5; i++) {
- readChannel_State(i, function(ch, state) {
- var td = document.getElementById('ch' + ch);
- if (typeof td !== 'undefined') {
- td.setAttribute('class', state);
- }
- });
- }
- }
- }, 1000);
- window.onload = function() {
- send_request(reqAddr, 'act=getChannels_Count', function(response) {
- try {
- var js = JSON.parse(response);
- var count = js.channels;
- var channels_Row = document.getElementById('channels_Row') || undefined;
- var channelsActions_Row = document.getElementById('channelsActions_Row') || undefined;
- var channelRow_TPL = '<td align="center" id="ch%{id}%" class="off"><b><br>Канал %{id}%<br><br></b></td>';
- var channelRowAction_TPL = '<td align="center"><input style="background:lime" type="button" value="Вкл" onClick="return setChannel_state(%{id}%, \'on\');" /><input type="button" value="Откл" onClick="return setChannel_state(%{id}%, \'off\');" /></td>';
- channelsActions_Row.innerHTML = '';
- channels_Row.innerHTML = '';
- // make the rows channels
- var html_data1='';
- var html_data2='';
- for (var i = 1; i <= count; i++) {
- html_data1 += channelRow_TPL.replace(/%\{id\}%/g, i);
- html_data2 += channelRowAction_TPL.replace(/%\{id\}%/g, i);
- }
- channels_Row.innerHTML = html_data1;
- channelsActions_Row.innerHTML = html_data2;
- domReady_Flag = 1;
- } catch (e) {
- }
- });
- }
- </script>
- <style type="text/css">
- body {
- background: lightgray;
- }
- td.on {
- background: lime;
- }
- td.off {
- background: gray;
- }
- </style>
- </head>
- <body>
- <h1 align="center">PIE Home Server v2.0</h1>
- <h2 align="center">(based on Arduino with W5500)</h2>
- <table align="center" cellspacing="5">
- <tr>
- <th colspan="5">
- <font color="blue">Доступные каналы для управления:</font>
- </th>
- </tr>
- <tr id="channels_Row"></tr>
- <tr id="channelsActions_Row"></tr>
- </table>
- </body>
- </html>
Add Comment
Please, Sign In to add comment