common.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. var domainname_for_testing = "192.168.178.44";
  4. function gethost_Version(){
  5. return "1.0.0 - 20200910";
  6. }
  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 (((host == "127.0.0.1") || (host == "localhost") || (host == ""))
  12. // && ((window.location.port == "80") || (window.location.port == ""))
  13. )
  14. {
  15. console.log("Using pre-defined domainname for testing: " + domainname_for_testing);
  16. domainname = "http://" + domainname_for_testing
  17. }
  18. else
  19. {
  20. domainname = window.location.protocol + "//" + host;
  21. if (window.location.port != "") {
  22. domainname = domainname + ":" + window.location.port;
  23. }
  24. }
  25. return domainname;
  26. }
  27. function UpdatePage(_dosession = true){
  28. var zw = location.href;
  29. zw = zw.substr(0, zw.indexOf("?"));
  30. if (_dosession) {
  31. window.location = zw + '?session=' + Math.floor((Math.random() * 1000000) + 1);
  32. }
  33. else {
  34. window.location = zw;
  35. }
  36. }
  37. function LoadHostname() {
  38. _domainname = getDomainname();
  39. var xhttp = new XMLHttpRequest();
  40. xhttp.addEventListener('load', function(event) {
  41. if (xhttp.status >= 200 && xhttp.status < 300) {
  42. hostname = xhttp.responseText;
  43. document.title = hostname + " - AI on the edge";
  44. document.getElementById("id_title").innerHTML = "Digitizer - AI on the edge - " + hostname;
  45. }
  46. else {
  47. console.warn(request.statusText, request.responseText);
  48. }
  49. });
  50. // var xhttp = new XMLHttpRequest();
  51. try {
  52. url = _domainname + '/info?type=Hostname';
  53. xhttp.open("GET", url, true);
  54. xhttp.send();
  55. }
  56. catch (error)
  57. {
  58. // alert("Loading Hostname failed");
  59. }
  60. }
  61. var fwVersion = "";
  62. var webUiVersion = "";
  63. function LoadFwVersion() {
  64. _domainname = getDomainname();
  65. var xhttp = new XMLHttpRequest();
  66. xhttp.addEventListener('load', function(event) {
  67. if (xhttp.status >= 200 && xhttp.status < 300) {
  68. fwVersion = xhttp.responseText;
  69. document.getElementById("Version").innerHTML = fwVersion;
  70. console.log(fwVersion);
  71. compareVersions();
  72. }
  73. else {
  74. console.warn(request.statusText, request.responseText);
  75. fwVersion = "NaN";
  76. }
  77. });
  78. try {
  79. url = _domainname + '/info?type=FirmwareVersion';
  80. xhttp.open("GET", url, true);
  81. xhttp.send();
  82. }
  83. catch (error) {
  84. fwVersion = "NaN";
  85. }
  86. }
  87. function LoadWebUiVersion() {
  88. _domainname = getDomainname();
  89. var xhttp = new XMLHttpRequest();
  90. xhttp.addEventListener('load', function(event) {
  91. if (xhttp.status >= 200 && xhttp.status < 300) {
  92. webUiVersion = xhttp.responseText;
  93. console.log("Web UI Version: " + webUiVersion);
  94. compareVersions();
  95. }
  96. else {
  97. console.warn(request.statusText, request.responseText);
  98. webUiVersion = "NaN";
  99. }
  100. });
  101. try {
  102. url = _domainname + '/info?type=HTMLVersion';
  103. console.log("url");
  104. xhttp.open("GET", url, true);
  105. xhttp.send();
  106. }
  107. catch (error) {
  108. webUiVersion = "NaN";
  109. }
  110. }
  111. function compareVersions() {
  112. if (fwVersion == "" || webUiVersion == "") {
  113. return;
  114. }
  115. arr = fwVersion.split(" ");
  116. fWGitHash = arr[arr.length - 1].substring(0, 7);
  117. arr = webUiVersion.split(" ");
  118. webUiHash = arr[arr.length - 1].substring(0, 7);
  119. console.log("FW Hash: " + fWGitHash + ", Web UI Hash: " + webUiHash);
  120. if (fWGitHash != webUiHash) {
  121. firework.launch("The Version of the Web Interface (" + webUiHash +
  122. ") does not match the Firmware Version (" +
  123. fWGitHash + ")! It is suggested to keep them on the same version!", 'warning', 30000);
  124. }
  125. }