common.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* The UI can also be run locally, but you have to set the IP of your device accordingly.
  2. * And you also might have to disable CORS in your webbrowser!
  3. * Eg using https://chromewebstore.google.com/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf?utm_source=ext_app_menu on chrome
  4. * Keep empty to disable using it. Enabling it will break access through a forwared port, see
  5. * https://github.com/jomjol/AI-on-the-edge-device/issues/2681 */
  6. var domainname_for_testing = "";
  7. //var domainname_for_testing = "192.168.1.151";
  8. /* Returns the domainname with prepended protocol.
  9. Eg. http://watermeter.fritz.box or http://192.168.1.5 */
  10. function getDomainname(){
  11. var host = window.location.hostname;
  12. if (domainname_for_testing != "") {
  13. console.log("Using pre-defined domainname for testing: " + domainname_for_testing);
  14. domainname = "http://" + domainname_for_testing
  15. }
  16. else
  17. {
  18. domainname = window.location.protocol + "//" + host;
  19. if (window.location.port != "") {
  20. domainname = domainname + ":" + window.location.port;
  21. }
  22. }
  23. return domainname;
  24. }
  25. function UpdatePage(_dosession = true){
  26. var zw = location.href;
  27. zw = zw.substr(0, zw.indexOf("?"));
  28. if (_dosession) {
  29. window.location = zw + '?session=' + Math.floor((Math.random() * 1000000) + 1);
  30. }
  31. else {
  32. window.location = zw;
  33. }
  34. }
  35. function LoadHostname() {
  36. _domainname = getDomainname();
  37. var xhttp = new XMLHttpRequest();
  38. xhttp.addEventListener('load', function(event) {
  39. if (xhttp.status >= 200 && xhttp.status < 300) {
  40. hostname = xhttp.responseText;
  41. document.title = hostname + " - AI on the edge";
  42. document.getElementById("id_title").innerHTML = "Digitizer - AI on the edge - " + hostname;
  43. }
  44. else {
  45. console.warn(request.statusText, request.responseText);
  46. }
  47. });
  48. // var xhttp = new XMLHttpRequest();
  49. try {
  50. url = _domainname + '/info?type=Hostname';
  51. xhttp.open("GET", url, true);
  52. xhttp.send();
  53. }
  54. catch (error)
  55. {
  56. // alert("Loading Hostname failed");
  57. }
  58. }
  59. var fwVersion = "";
  60. var webUiVersion = "";
  61. function LoadFwVersion() {
  62. _domainname = getDomainname();
  63. var xhttp = new XMLHttpRequest();
  64. xhttp.addEventListener('load', function(event) {
  65. if (xhttp.status >= 200 && xhttp.status < 300) {
  66. fwVersion = xhttp.responseText;
  67. document.getElementById("Version").innerHTML = fwVersion;
  68. console.log(fwVersion);
  69. compareVersions();
  70. }
  71. else {
  72. console.warn(request.statusText, request.responseText);
  73. fwVersion = "NaN";
  74. }
  75. });
  76. try {
  77. url = _domainname + '/info?type=FirmwareVersion';
  78. xhttp.open("GET", url, true);
  79. xhttp.send();
  80. }
  81. catch (error) {
  82. fwVersion = "NaN";
  83. }
  84. }
  85. function LoadWebUiVersion() {
  86. _domainname = getDomainname();
  87. var xhttp = new XMLHttpRequest();
  88. xhttp.addEventListener('load', function(event) {
  89. if (xhttp.status >= 200 && xhttp.status < 300) {
  90. webUiVersion = xhttp.responseText;
  91. console.log("Web UI Version: " + webUiVersion);
  92. compareVersions();
  93. }
  94. else {
  95. console.warn(request.statusText, request.responseText);
  96. webUiVersion = "NaN";
  97. }
  98. });
  99. try {
  100. url = _domainname + '/info?type=HTMLVersion';
  101. console.log("url");
  102. xhttp.open("GET", url, true);
  103. xhttp.send();
  104. }
  105. catch (error) {
  106. webUiVersion = "NaN";
  107. }
  108. }
  109. function compareVersions() {
  110. if (fwVersion == "" || webUiVersion == "") {
  111. return;
  112. }
  113. arr = fwVersion.split(" ");
  114. fWGitHash = arr[arr.length - 1].substring(0, 7);
  115. arr = webUiVersion.split(" ");
  116. webUiHash = arr[arr.length - 1].substring(0, 7);
  117. console.log("FW Hash: " + fWGitHash + ", Web UI Hash: " + webUiHash);
  118. if (fWGitHash != webUiHash) {
  119. firework.launch("The version of the web interface (" + webUiHash +
  120. ") does not match the firmware version (" +
  121. fWGitHash + ")! It is suggested to keep them on the same version!", 'warning', 30000);
  122. }
  123. }