common.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. try {
  49. url = _domainname + '/info?type=Hostname';
  50. xhttp.open("GET", url, true);
  51. xhttp.send();
  52. }
  53. catch (error)
  54. {
  55. }
  56. }
  57. var fwVersion = "";
  58. var webUiVersion = "";
  59. function LoadFwVersion() {
  60. _domainname = getDomainname();
  61. var xhttp = new XMLHttpRequest();
  62. xhttp.addEventListener('load', function(event) {
  63. if (xhttp.status >= 200 && xhttp.status < 300) {
  64. fwVersion = xhttp.responseText;
  65. document.getElementById("Version").innerHTML = fwVersion;
  66. console.log(fwVersion);
  67. compareVersions();
  68. }
  69. else {
  70. console.warn(request.statusText, request.responseText);
  71. fwVersion = "NaN";
  72. }
  73. });
  74. try {
  75. url = _domainname + '/info?type=FirmwareVersion';
  76. xhttp.open("GET", url, true);
  77. xhttp.send();
  78. }
  79. catch (error) {
  80. fwVersion = "NaN";
  81. }
  82. }
  83. function LoadWebUiVersion() {
  84. _domainname = getDomainname();
  85. var xhttp = new XMLHttpRequest();
  86. xhttp.addEventListener('load', function(event) {
  87. if (xhttp.status >= 200 && xhttp.status < 300) {
  88. webUiVersion = xhttp.responseText;
  89. console.log("Web UI Version: " + webUiVersion);
  90. compareVersions();
  91. }
  92. else {
  93. console.warn(request.statusText, request.responseText);
  94. webUiVersion = "NaN";
  95. }
  96. });
  97. try {
  98. url = _domainname + '/info?type=HTMLVersion';
  99. console.log("url");
  100. xhttp.open("GET", url, true);
  101. xhttp.send();
  102. }
  103. catch (error) {
  104. webUiVersion = "NaN";
  105. }
  106. }
  107. function compareVersions() {
  108. if (fwVersion == "" || webUiVersion == "") {
  109. return;
  110. }
  111. arr = fwVersion.split(" ");
  112. fWGitHash = arr[arr.length - 1].substring(0, 7);
  113. arr = webUiVersion.split(" ");
  114. webUiHash = arr[arr.length - 1].substring(0, 7);
  115. console.log("FW Hash: " + fWGitHash + ", Web UI Hash: " + webUiHash);
  116. if (fWGitHash != webUiHash) {
  117. firework.launch("The version of the web interface (" + webUiHash +
  118. ") does not match the firmware version (" +
  119. fWGitHash + ")! It is suggested to keep them on the same version!", 'warning', 30000);
  120. }
  121. }