common.js 4.1 KB

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