GenerateCode.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. include '../auth.php';
  3. ?>
  4. <html>
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=0.6, maximum-scale=0.6"/>
  7. <html>
  8. <head>
  9. <script type='text/javascript' charset='utf-8'>
  10. // Hides mobile browser's address bar when page is done loading.
  11. window.addEventListener('load', function(e) {
  12. setTimeout(function() { window.scrollTo(0, 1); }, 1);
  13. }, false);
  14. </script>
  15. <title>Home Dynamic</title>
  16. <link rel="stylesheet" href="../script/tocas/tocas.css">
  17. <script src="../script/tocas/tocas.js"></script>
  18. <script src="../script/jquery.min.js"></script>
  19. <link rel="stylesheet" href="script/simplemde.min.css">
  20. <script src="script/simplemde.min.js"></script>
  21. </head>
  22. <body>
  23. <div class="ts large link attached inverted primary menu">
  24. <div class="ts narrow container">
  25. <a class="header item"><i class="home icon"></i>Home Dynamic</a>
  26. <a class="item">Panel</a>
  27. <a class="item">Tools</a>
  28. <a class="right item">Setting</a>
  29. </div>
  30. </div>
  31. <div class="ts narrow container">
  32. <div class="ts inverted info message">
  33. <div class="header"><i class="terminal icon"></i>Hi there!</div>
  34. <p>This is the programming interface for the ESP8266 Wifi module. Only edit the code on the left directly when you know what you are doing. <br>
  35. <i class="caution sign icon"></i>Wrong code might lead to software or hardware failure on your IoT devices. Use this system for your own risk.</p>
  36. </div>
  37. </div>
  38. <div class="ts narrow container grid">
  39. <!-- Left Section Editor -->
  40. <div class="twelve wide column">
  41. <textarea id="mde"><?php
  42. $file = file_get_contents('script\esp_template\esp_template.ino');
  43. echo $file;
  44. ?>
  45. </textarea>
  46. </div>
  47. <!-- Right Section Editor -->
  48. <div class="four wide column">
  49. <div class="ts top attached borderless menu">
  50. <div class="header item">Script Generator</div>
  51. <div class="right item">
  52. <i class="setting icon"></i>
  53. </div>
  54. </div>
  55. <!-- Simple Script Variables -->
  56. <div class="ts bottom attached segment">
  57. <div class="ts form">
  58. <div class="field">
  59. <label>Wifi SSID</label>
  60. <input id="ssid" type="text">
  61. </div>
  62. <div class="field">
  63. <label>Wifi Password</label>
  64. <input id="wifiPassword" type="text">
  65. </div>
  66. <div class="field">
  67. <label>Device Host Name</label>
  68. <input id="hostName" type="text">
  69. </div>
  70. <div class="field">
  71. <label>ESP Username</label>
  72. <input id="username" type="text">
  73. </div>
  74. <div class="field">
  75. <label>ESP Password</label>
  76. <input id="espPassword" type="text">
  77. </div>.
  78. <div class="field">
  79. <label>Display Name</label>
  80. <input id="disName" type="text">
  81. </div>
  82. <div class="field">
  83. <details class="ts accordion">
  84. <summary>
  85. <i class="dropdown icon"></i>Advanced Setting
  86. </summary>
  87. <div class="content">
  88. <label>On Path</label>
  89. <input id="onPath" type="text" placeholder="This cannot be left empty!" value="On:switch|on">
  90. <br>
  91. <label>Off Path</label>
  92. <input id="offPath" type="text" placeholder="This cannot be left empty!" value="Off:switch|off">
  93. <br>
  94. </div>
  95. </details>
  96. </div>
  97. </div>
  98. </div>
  99. <!-- Buttons -->
  100. <button class="ts right floated fluid icon labeled button" onClick="GenerateScript();">
  101. <i class="tasks icon"></i>
  102. Generate
  103. </button>
  104. <button class="ts right floated fluid icon labeled button">
  105. <i class="download icon"></i>
  106. Download
  107. </button>
  108. </div>
  109. </div>
  110. <script>
  111. var simplemde = new SimpleMDE({ element: document.getElementById("mde"), spellChecker: false, status: false });
  112. function GenerateScript(){
  113. var ssid = $('#ssid').val();
  114. var wifipw = $('#wifiPassword').val();
  115. var username = $('#username').val();
  116. var espPassword = $('#espPassword').val();
  117. var hostName = $('#hostName').val();
  118. console.log("Updating Script");
  119. var template = $('#mde').val();
  120. var code = template.replace('%SSID%',ssid).replace('%WIFIPASSWORD%',wifipw).replace('%WEB_USERNAME%',username).replace('%WEB_PASSWORD%',espPassword).replace('%HOSTNAME%',hostName);
  121. console.log(code);
  122. simplemde.value(code);
  123. }
  124. </script>
  125. </body>
  126. </html>