[APP][Pro] Simple (Sys) LOG - Use this app for Simple (Sys) Logging

HTML page ready!

Here you can check Syslog on the fly (while at home).
Just change the Homey IP address in the URL…

Save this code to a HTML file and save on eg. your Home screen on you phone.

<!DOCTYPE html>
<html>
<head>
    <style>
        table, th, td 
        {
            border: solid 1px #ddd;
            border-collapse: collapse;
            padding: 2px 3px;
            text-align: left;
        }
        th { 
            font-weight:bold;
        }
    </style>
</head>
<body>
    
    <p id="showData"></p>

</body>

<script>

    // the json data.

const url = "http://192.168.1.223/api/app/nl.nielsdeklerk.log/";

async function FetchData() {
  const response = await fetch(url);
  const data = await response.text();
  const string = "["+data+"]";
  const myJSON = JSON.parse(string);
  const JSONtable = myJSON[0].logs;

  response.ok;     // => false
  response.status; // => 404

  return JSONtable;
}

FetchData().then(JSONtable => {
  JSONtable; // => 'Page not found'

    // Extract value from table header. 

    let col = [];
    for (let i = 0; i < JSONtable.length; i++) {
      for (let key in JSONtable[i]) {
        if (col.indexOf(key) === -1) {
          col.push(key);
        }
      }
    }

    // Create table.
    const table = document.createElement("table");

    // Create table header row using the extracted headers above.
    let tr = table.insertRow(-1);                   // table row.

    for (let i = 0; i < col.length; i++) {
      let th = document.createElement("th");      // table header.
      th.innerHTML = col[i];
      tr.appendChild(th);
    }

    // add json data to the table as rows.
    for (let i = 0; i < JSONtable.length; i++) {

      tr = table.insertRow(-1);

      for (let j = 0; j < col.length; j++) {
        let tabCell = tr.insertCell(-1);
        tabCell.innerHTML = JSONtable[i][col[j]];
      }
    }

    // Now, add the newly created table with json data, to a container.
    const divShowData = document.getElementById('showData');
    divShowData.innerHTML = "";
    divShowData.appendChild(table);

	});
  

</script>
</html>
3 Likes