_wwwServer.ino 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  1. // 1-channel LoRa Gateway for ESP8266
  2. // Copyright (c) 2016, 2017, 2018, 2019 Maarten Westenberg version for ESP8266
  3. // Version 6.1.4
  4. // Date: 2019-11-29
  5. //
  6. // based on work done by many people and making use of several libraries.
  7. //
  8. // All rights reserved. This program and the accompanying materials
  9. // are made available under the terms of the MIT License
  10. // which accompanies this distribution, and is available at
  11. // https://opensource.org/licenses/mit-license.php
  12. //
  13. // NO WARRANTY OF ANY KIND IS PROVIDED
  14. //
  15. // Author: Maarten Westenberg (mw12554@hotmail.com)
  16. //
  17. // This file contains the webserver code for the ESP Single Channel Gateway.
  18. // Note:
  19. // The ESP Webserver works with Strings to display HTML content.
  20. // Care must be taken that not all data is output to the webserver in one string
  21. // as this will use a LOT of memory and possibly kill the heap (cause system
  22. // crash or other unreliable behaviour.
  23. // Instead, output of the various tables on the webpage should be displayed in
  24. // chunks so that strings are limited in size.
  25. // Be aware that using no strings but only sendContent() calls has its own
  26. // disadvantage that these calls take a lot of time and cause the page to be
  27. // displayed like an old typewriter.
  28. // So, the trick is to make chucks that are sent to the website by using
  29. // a response String but not make those Strings too big.
  30. //
  31. // Also, selecting too many options for Statistics, display, Hopping channels
  32. // etc makes the gateway more sluggish and may impact the available memory and
  33. // thus its performance and reliability. It's up to the user to select wisely!
  34. //
  35. // --------------------------------------------------------------------------------
  36. // PRINT IP
  37. // Output the 4-byte IP address for easy printing.
  38. // As this function is also used by _otaServer.ino do not put in #define
  39. // --------------------------------------------------------------------------------
  40. static void printIP(IPAddress ipa, const char sep, String& response)
  41. {
  42. response+=(String)ipa[0]; response+=sep;
  43. response+=(String)ipa[1]; response+=sep;
  44. response+=(String)ipa[2]; response+=sep;
  45. response+=(String)ipa[3];
  46. }
  47. //
  48. // The remainder of the file ONLY works is A_SERVER=1 is set.
  49. //
  50. #if A_SERVER==1
  51. // ================================================================================
  52. // WEBSERVER DECLARATIONS
  53. // ================================================================================
  54. // None at the moment
  55. // ================================================================================
  56. // WEBSERVER FUNCTIONS
  57. // ================================================================================
  58. // --------------------------------------------------------------------------------
  59. // Used by all functions requiring user confirmation
  60. // Displays a menu by user and two buttons "OK" and "CANCEL"
  61. // The function returns true for OK and false for CANCEL
  62. // Usage: Call this function ONCE during startup to declare and init
  63. // the ynDialog JavaScript function, and call the function
  64. // from the program when needed.
  65. // Paramters of the JavaScript function:
  66. // s: Th strig contining the question to be answered
  67. // o: The OK tab for the webpage where to go to
  68. // c: The Cancel string (optional)
  69. // --------------------------------------------------------------------------------
  70. boolean YesNo()
  71. {
  72. boolean ret = false;
  73. String response = "";
  74. response += "<script>";
  75. response += "var ch = \"\"; "; // Init choice
  76. response += "function ynDialog(s,y) {";
  77. response += " try { adddlert(s); }";
  78. response += " catch(err) {";
  79. response += " ch = \" \" + s + \".\\n\\n\"; ";
  80. response += " ch += \"Click OK to continue,\\n\"; ";
  81. response += " ch += \"or Cancel\\n\\n\"; ";
  82. response += " if(!confirm(ch)) { ";
  83. response += " javascript:window.location.reload(true);";
  84. response += " } ";
  85. response += " else { ";
  86. response += " document.location.href = '/'+y; ";
  87. response += " } ";
  88. response += " }";
  89. response += "}";
  90. response += "</script>";
  91. server.sendContent(response);
  92. // Put something like this in the ESP program
  93. // response += "<input type=\"button\" value=\"YesNo\" onclick=\"ynDialog()\" />";
  94. return(ret);
  95. }
  96. // --------------------------------------------------------------------------------
  97. // WWWFILE
  98. // This function will open a pop-up in the browser and then
  99. // display the contents of a file in that window
  100. // Output is sent to server.sendContent()
  101. // Note: The output is not in a variable, its size would be too large
  102. // Parameters:
  103. // fn; String with filename
  104. // Returns:
  105. // <none>
  106. // --------------------------------------------------------------------------------
  107. void wwwFile(String fn) {
  108. if (!SPIFFS.exists(fn)) {
  109. #if _DUSB>=1
  110. Serial.print(F("wwwFile:: ERROR: file not found="));
  111. Serial.println(fn);
  112. #endif
  113. return;
  114. }
  115. #if _DUSB>=2
  116. else {
  117. Serial.print(F("wwwFile:: File existist= "));
  118. Serial.println(fn);
  119. }
  120. #endif
  121. #if _DUSB>=1
  122. File f = SPIFFS.open(fn, "r"); // Open the file for reading
  123. int j;
  124. for (j=0; j<LOGFILEREC; j++) {
  125. String s=f.readStringUntil('\n');
  126. if (s.length() == 0) {
  127. Serial.print(F("wwwFile:: String length 0"));
  128. break;
  129. }
  130. server.sendContent(s.substring(12)); // Skip the first 12 Gateway specific binary characters
  131. server.sendContent("\n");
  132. yield();
  133. }
  134. f.close();
  135. #endif
  136. }
  137. // --------------------------------------------------------------------------------
  138. // Button function Docu, display the documentation pages.
  139. // This is a button on the top of the GUI screen.
  140. // --------------------------------------------------------------------------------
  141. void buttonDocu()
  142. {
  143. String response = "";
  144. response += "<script>";
  145. response += "var txt = \"\";";
  146. response += "function showDocu() {";
  147. response += " try { adddlert(\"Welcome,\"); }";
  148. response += " catch(err) {";
  149. response += " txt = \"Do you want the documentation page.\\n\\n\"; ";
  150. response += " txt += \"Click OK to continue viewing documentation,\\n\"; ";
  151. response += " txt += \"or Cancel to return to the home page.\\n\\n\"; ";
  152. response += " if(confirm(txt)) { ";
  153. response += " document.location.href = \"https://things4u.github.io/Projects/SingleChannelGateway/UserGuide/Introduction%206.html\"; ";
  154. response += " }";
  155. response += " }";
  156. response += "}";
  157. response += "</script>";
  158. server.sendContent(response);
  159. }
  160. // --------------------------------------------------------------------------------
  161. // Button function Log displays logfiles.
  162. // This is a button on the top of the GUI screen
  163. // --------------------------------------------------------------------------------
  164. void buttonLog()
  165. {
  166. // String response = "";
  167. String fn = "";
  168. int i = 0;
  169. while (i< LOGFILEMAX ) {
  170. fn = "/log-" + String(gwayConfig.logFileNo - i);
  171. wwwFile(fn); // Display the file contents in the browser
  172. i++;
  173. }
  174. // server.sendContent(response);
  175. }
  176. // --------------------------------------------------------------------------------
  177. // BUTTONSEEN
  178. // List the listSeen array.
  179. // Read the logfiles and display info about nodes (last seend, SF used etc).
  180. // This is a button on the top of the USB GUI screen
  181. // --------------------------------------------------------------------------------
  182. void buttonSeen()
  183. {
  184. String fn = "";
  185. int i = 0;
  186. printSeen(listSeen);
  187. #if _DUSB>=1
  188. if (( debug>=1 ) && ( pdebug & P_MAIN )) {
  189. Serial.println(F("buttonSeen:: printSeen called"));
  190. }
  191. #endif
  192. }
  193. // --------------------------------------------------------------------------------
  194. // Navigate webpage by buttons. This method has some advantages:
  195. // - Less time/cpu usage
  196. // - Less memory usage <a href=\"SPEED=160\">
  197. // --------------------------------------------------------------------------------
  198. static void wwwButtons()
  199. {
  200. String response = "";
  201. String mode = (gwayConfig.expert ? "Basic Mode" : "Expert Mode");
  202. YesNo(); // Init the Yes/No function
  203. buttonDocu();
  204. response += "<input type=\"button\" value=\"Documentation\" onclick=\"showDocu()\" >";
  205. response += "<a href=\"EXPERT\" download><button type=\"button\">" + mode + "</button></a>";
  206. response += "<a href=\"SEEN\" download><button type=\"button\">Nodes Seen</button></a>";
  207. response += "<a href=\"LOG\" download><button type=\"button\">Log Files</button></a>";
  208. server.sendContent(response); // Send to the screen
  209. }
  210. // --------------------------------------------------------------------------------
  211. // SET ESP8266/ESP32 WEB SERVER VARIABLES
  212. //
  213. // This funtion implements the WiFi Webserver (very simple one). The purpose
  214. // of this server is to receive simple admin commands, and execute these
  215. // results which are sent back to the web client.
  216. // Commands: DEBUG, ADDRESS, IP, CONFIG, GETTIME, SETTIME
  217. // The webpage is completely built response and then printed on screen.
  218. //
  219. // Parameters:
  220. // cmd: Contains a character array with the command to execute
  221. // arg: Contains the parameter value of that command
  222. // Returns:
  223. // <none>
  224. // --------------------------------------------------------------------------------
  225. static void setVariables(const char *cmd, const char *arg) {
  226. // DEBUG settings; These can be used as a single argument
  227. if (strcmp(cmd, "DEBUG")==0) { // Set debug level 0-2
  228. if (atoi(arg) == 1) {
  229. debug = (debug+1)%4;
  230. }
  231. else if (atoi(arg) == -1) {
  232. debug = (debug+3)%4;
  233. }
  234. writeGwayCfg(CONFIGFILE); // Save configuration to file
  235. }
  236. if (strcmp(cmd, "CAD")==0) { // Set -cad on=1 or off=0
  237. _cad=(bool)atoi(arg);
  238. writeGwayCfg(CONFIGFILE); // Save configuration to file
  239. }
  240. if (strcmp(cmd, "HOP")==0) { // Set -hop on=1 or off=0
  241. _hop=(bool)atoi(arg);
  242. if (! _hop) {
  243. ifreq=0;
  244. setFreq(freqs[ifreq].upFreq);
  245. rxLoraModem();
  246. sf = SF7;
  247. cadScanner();
  248. }
  249. writeGwayCfg(CONFIGFILE); // Save configuration to file
  250. }
  251. // DELAY, write txDelay for transmissions
  252. //
  253. if (strcmp(cmd, "DELAY")==0) { // Set delay usecs
  254. gwayConfig.txDelay+=atoi(arg)*1000;
  255. writeGwayCfg(CONFIGFILE); // Save configuration to file
  256. }
  257. // TRUSTED, write node trusted value
  258. //
  259. if (strcmp(cmd, "TRUSTED")==0) { // Set delay usecs
  260. gwayConfig.trusted=atoi(arg);
  261. if (atoi(arg) == 1) {
  262. gwayConfig.trusted = (gwayConfig.trusted +1)%4;
  263. }
  264. else if (atoi(arg) == -1) {
  265. gwayConfig.trusted = (gwayConfig.trusted -1)%4;
  266. }
  267. writeGwayCfg(CONFIGFILE); // Save configuration to file
  268. }
  269. // SF; Handle Spreading Factor Settings
  270. //
  271. if (strcmp(cmd, "SF")==0) {
  272. uint8_t sfi = sf;
  273. if (atoi(arg) == 1) {
  274. if (sf>=SF12) sf=SF7; else sf= (sf_t)((int)sf+1);
  275. }
  276. else if (atoi(arg) == -1) {
  277. if (sf<=SF7) sf=SF12; else sf= (sf_t)((int)sf-1);
  278. }
  279. rxLoraModem(); // Reset the radio with the new spreading factor
  280. writeGwayCfg(CONFIGFILE); // Save configuration to file
  281. }
  282. // FREQ; Handle Frequency Settings
  283. //
  284. if (strcmp(cmd, "FREQ")==0) {
  285. uint8_t nf = sizeof(freqs)/ sizeof(freqs[0]); // Number of frequency elements in array
  286. // Compute frequency index
  287. if (atoi(arg) == 1) {
  288. if (ifreq==(nf-1)) ifreq=0; else ifreq++;
  289. }
  290. else if (atoi(arg) == -1) {
  291. Serial.println("down");
  292. if (ifreq==0) ifreq=(nf-1); else ifreq--;
  293. }
  294. setFreq(freqs[ifreq].upFreq);
  295. rxLoraModem(); // Reset the radio with the new frequency
  296. writeGwayCfg(CONFIGFILE); // Save configuration to file
  297. }
  298. //if (strcmp(cmd, "GETTIME")==0) { Serial.println(F("gettime tbd")); } // Get the local time
  299. //
  300. //if (strcmp(cmd, "SETTIME")==0) { Serial.println(F("settime tbd")); } // Set the local time
  301. //
  302. // Help
  303. //
  304. if (strcmp(cmd, "HELP")==0) { Serial.println(F("Display Help Topics")); }
  305. // Node
  306. //
  307. #if GATEWAYNODE==1
  308. if (strcmp(cmd, "NODE")==0) { // Set node on=1 or off=0
  309. gwayConfig.isNode =(bool)atoi(arg);
  310. writeGwayCfg(CONFIGFILE); // Save configuration to file
  311. }
  312. // File Counter//
  313. if (strcmp(cmd, "FCNT")==0) {
  314. frameCount=0;
  315. rxLoraModem(); // Reset the radio with the new frequency
  316. writeGwayCfg(CONFIGFILE);
  317. }
  318. #endif
  319. // WiFi Manager
  320. //
  321. #if _WIFIMANAGER==1
  322. if (strcmp(cmd, "NEWSSID")==0) {
  323. WiFiManager wifiManager;
  324. strcpy(wpa[0].login,"");
  325. strcpy(wpa[0].passw,"");
  326. WiFi.disconnect();
  327. wifiManager.autoConnect(AP_NAME, AP_PASSWD );
  328. }
  329. #endif
  330. // Update the software (from User Interface)
  331. #if A_OTA==1
  332. if (strcmp(cmd, "UPDATE")==0) {
  333. if (atoi(arg) == 1) {
  334. updateOtaa();
  335. writeGwayCfg(CONFIGFILE);
  336. }
  337. }
  338. #endif
  339. #if A_REFRESH==1
  340. if (strcmp(cmd, "REFR")==0) { // Set refresh on=1 or off=0
  341. gwayConfig.refresh =(bool)atoi(arg);
  342. writeGwayCfg(CONFIGFILE); // Save configuration to file
  343. }
  344. #endif
  345. }
  346. // --------------------------------------------------------------------------------
  347. // OPEN WEB PAGE
  348. // This is the init function for opening the webpage
  349. //
  350. // --------------------------------------------------------------------------------
  351. static void openWebPage()
  352. {
  353. ++gwayConfig.views; // increment number of views
  354. #if A_REFRESH==1
  355. //server.client().stop(); // Experimental, stop webserver in case something is still running!
  356. #endif
  357. String response="";
  358. server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
  359. server.sendHeader("Pragma", "no-cache");
  360. server.sendHeader("Expires", "-1");
  361. // init webserver, fill the webpage
  362. // NOTE: The page is renewed every _WWW_INTERVAL seconds, please adjust in configGway.h
  363. //
  364. server.setContentLength(CONTENT_LENGTH_UNKNOWN);
  365. server.send(200, "text/html", "");
  366. #if A_REFRESH==1
  367. if (gwayConfig.refresh) {
  368. response += String() + "<!DOCTYPE HTML><HTML><HEAD><meta http-equiv='refresh' content='"+_WWW_INTERVAL+";http://";
  369. printIP((IPAddress)WiFi.localIP(),'.',response);
  370. response += "'><TITLE>ESP8266 1ch Gateway</TITLE>";
  371. }
  372. else {
  373. response += String() + "<!DOCTYPE HTML><HTML><HEAD><TITLE>ESP8266 1ch Gateway</TITLE>";
  374. }
  375. #else
  376. response += String() + "<!DOCTYPE HTML><HTML><HEAD><TITLE>ESP8266 1ch Gateway</TITLE>";
  377. #endif
  378. response += "<META HTTP-EQUIV='CONTENT-TYPE' CONTENT='text/html; charset=UTF-8'>";
  379. response += "<META NAME='AUTHOR' CONTENT='M. Westenberg (mw1554@hotmail.com)'>";
  380. response += "<style>.thead {background-color:green; color:white;} ";
  381. response += ".cell {border: 1px solid black;}";
  382. response += ".config_table {max_width:100%; min-width:400px; width:98%; border:1px solid black; border-collapse:collapse;}";
  383. response += "</style></HEAD><BODY>";
  384. response +="<h1>ESP Gateway Config</h1>";
  385. response +="<p style='font-size:10px;'>";
  386. response +="Version: "; response+=VERSION;
  387. response +="<br>ESP alive since "; // STARTED ON
  388. stringTime(startTime, response);
  389. response +=", Uptime: "; // UPTIME
  390. uint32_t secs = millis()/1000;
  391. uint16_t days = secs / 86400; // Determine number of days
  392. uint8_t _hour = hour(secs);
  393. uint8_t _minute = minute(secs);
  394. uint8_t _second = second(secs);
  395. response += String() + days + "-";
  396. if (_hour < 10) response += "0";
  397. response += String() + _hour + ":";
  398. if (_minute < 10) response += "0";
  399. response += String() + _minute + ":";
  400. if (_second < 10) response += "0";
  401. response += String() + _second;
  402. response +="<br>Current time "; // CURRENT TIME
  403. stringTime(now(), response);
  404. response +="<br>";
  405. response +="</p>";
  406. server.sendContent(response);
  407. }
  408. // --------------------------------------------------------------------------------
  409. // H2 Gateway Settings
  410. //
  411. // Display the configuration and settings data. This is an interactive setting
  412. // allowing the user to set CAD, HOP, Debug and several other operating parameters
  413. //
  414. // --------------------------------------------------------------------------------
  415. static void gatewaySettings()
  416. {
  417. String response="";
  418. String bg="";
  419. response +="<h2>Gateway Settings</h2>";
  420. response +="<table class=\"config_table\">";
  421. response +="<tr>";
  422. response +="<th class=\"thead\">Setting</th>";
  423. response +="<th colspan=\"2\" style=\"background-color: green; color: white; width:120px;\">Value</th>";
  424. response +="<th colspan=\"4\" style=\"background-color: green; color: white; width:100px;\">Set</th>";
  425. response +="</tr>";
  426. bg = " background-color: ";
  427. bg += ( _cad ? "LightGreen" : "orange" );
  428. response +="<tr><td class=\"cell\">CAD</td>";
  429. response +="<td colspan=\"2\" style=\"border: 1px solid black;"; response += bg; response += "\">";
  430. response += ( _cad ? "ON" : "OFF" );
  431. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"CAD=1\"><button>ON</button></a></td>";
  432. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"CAD=0\"><button>OFF</button></a></td>";
  433. response +="</tr>";
  434. bg = " background-color: ";
  435. bg += ( _hop ? "LightGreen" : "orange" );
  436. response +="<tr><td class=\"cell\">HOP</td>";
  437. response +="<td colspan=\"2\" style=\"border: 1px solid black;"; response += bg; response += "\">";
  438. response += ( _hop ? "ON" : "OFF" );
  439. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"HOP=1\"><button>ON</button></a></td>";
  440. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"HOP=0\"><button>OFF</button></a></td>";
  441. response +="</tr>";
  442. response +="<tr><td class=\"cell\">SF Setting</td><td class=\"cell\" colspan=\"2\">";
  443. if (_cad) {
  444. response += "AUTO</td>";
  445. }
  446. else {
  447. response += sf;
  448. response +="<td class=\"cell\"><a href=\"SF=-1\"><button>-</button></a></td>";
  449. response +="<td class=\"cell\"><a href=\"SF=1\"><button>+</button></a></td>";
  450. }
  451. response +="</tr>";
  452. // Channel
  453. response +="<tr><td class=\"cell\">Channel</td>";
  454. response +="<td class=\"cell\" colspan=\"2\">";
  455. if (_hop) {
  456. response += "AUTO</td>";
  457. }
  458. else {
  459. response += String() + ifreq;
  460. response +="</td>";
  461. response +="<td class=\"cell\"><a href=\"FREQ=-1\"><button>-</button></a></td>";
  462. response +="<td class=\"cell\"><a href=\"FREQ=1\"><button>+</button></a></td>";
  463. }
  464. response +="</tr>";
  465. // Trusted options, when TRUSTED_NODE is set
  466. #ifdef _TRUSTED_NODES
  467. response +="<tr><td class=\"cell\">Trusted Nodes</td><td class=\"cell\" colspan=\"2\">";
  468. response +=gwayConfig.trusted;
  469. response +="</td>";
  470. response +="<td class=\"cell\"><a href=\"TRUSTED=-1\"><button>-</button></a></td>";
  471. response +="<td class=\"cell\"><a href=\"TRUSTED=1\"><button>+</button></a></td>";
  472. response +="</tr>";
  473. #endif
  474. // Debugging options, only when _DUSB is set, otherwise no
  475. // serial activity
  476. #if _DUSB>=1
  477. response +="<tr><td class=\"cell\">Debug Level</td><td class=\"cell\" colspan=\"2\">";
  478. response +=debug;
  479. response +="</td>";
  480. response +="<td class=\"cell\"><a href=\"DEBUG=-1\"><button>-</button></a></td>";
  481. response +="<td class=\"cell\"><a href=\"DEBUG=1\"><button>+</button></a></td>";
  482. response +="</tr>";
  483. // Time Correction
  484. if (gwayConfig.expert) {
  485. response +="<tr><td class=\"cell\">Time Correction (uSec)</td><td class=\"cell\" colspan=\"2\">";
  486. response += gwayConfig.txDelay;
  487. response +="</td>";
  488. response +="<td class=\"cell\"><a href=\"DELAY=-1\"><button>-</button></a></td>";
  489. response +="<td class=\"cell\"><a href=\"DELAY=1\"><button>+</button></a></td>";
  490. response +="</tr>";
  491. }
  492. // Debug Pattern
  493. response +="<tr><td class=\"cell\">Debug pattern</td>";
  494. bg = ( (pdebug & P_SCAN) ? "LightGreen" : "orange" );
  495. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  496. response += bg; response += "\">";
  497. response +="<a href=\"PDEBUG=SCAN\">";
  498. response +="<button>SCN</button></a></td>";
  499. bg = ( (pdebug & P_CAD) ? "LightGreen" : "orange" );
  500. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  501. response += bg; response += "\">";
  502. response +="<a href=\"PDEBUG=CAD\">";
  503. response +="<button>CAD</button></a></td>";
  504. bg = ( (pdebug & P_RX) ? "LightGreen" : "orange" );
  505. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  506. response += bg; response += "\">";
  507. response +="<a href=\"PDEBUG=RX\">";
  508. response +="<button>RX</button></a></td>";
  509. bg = ( (pdebug & P_TX) ? "LightGreen" : "orange" );
  510. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  511. response += bg; response += "\">";
  512. response +="<a href=\"PDEBUG=TX\">";
  513. response +="<button>TX</button></a></td>";
  514. response += "</tr>";
  515. // Use a second Line
  516. response +="<tr><td class=\"cell\"></td>";
  517. bg = ( (pdebug & P_PRE) ? "LightGreen" : "orange" );
  518. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  519. response += bg; response += "\">";
  520. response +="<a href=\"PDEBUG=PRE\">";
  521. response +="<button>PRE</button></a></td>";
  522. bg = ( (pdebug & P_MAIN) ? "LightGreen" : "orange" );
  523. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  524. response += bg; response += "\">";
  525. response +="<a href=\"PDEBUG=MAIN\">";
  526. response +="<button>MAI</button></a></td>";
  527. bg = ( (pdebug & P_GUI) ? "LightGreen" : "orange" );
  528. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  529. response += bg; response += "\">";
  530. response +="<a href=\"PDEBUG=GUI\">";
  531. response +="<button>GUI</button></a></td>";
  532. bg = ( (pdebug & P_RADIO) ? "LightGreen" : "orange" );
  533. response +="<td class=\"cell\" style=\"border: 1px solid black; width:20px; background-color: ";
  534. response += bg; response += "\">";
  535. response +="<a href=\"PDEBUG=RADIO\">";
  536. response +="<button>RDIO</button></a></td>";
  537. response +="</tr>";
  538. #endif
  539. // USB Debug, Serial Debugging
  540. response +="<tr><td class=\"cell\">Usb Debug</td><td class=\"cell\" colspan=\"2\">";
  541. response += _DUSB;
  542. response +="</td>";
  543. //response +="<td class=\"cell\"> </td>";
  544. //response +="<td class=\"cell\"> </td>";
  545. response +="</tr>";
  546. #if GATEWAYNODE==1
  547. response +="<tr><td class=\"cell\">Framecounter Internal Sensor</td>";
  548. response +="<td class=\"cell\" colspan=\"2\">";
  549. response +=frameCount;
  550. response +="</td><td colspan=\"2\" style=\"border: 1px solid black;\">";
  551. response +="<button><a href=\"/FCNT\">RESET</a></button></td>";
  552. response +="</tr>";
  553. bg = " background-color: ";
  554. bg += ( (gwayConfig.isNode == 1) ? "LightGreen" : "orange" );
  555. response +="<tr><td class=\"cell\">Gateway Node</td>";
  556. response +="<td class=\"cell\" colspan=\"2\" style=\"border: 1px solid black;" + bg + "\">";
  557. response += ( (gwayConfig.isNode == true) ? "ON" : "OFF" );
  558. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"NODE=1\"><button>ON</button></a></td>";
  559. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"NODE=0\"><button>OFF</button></a></td>";
  560. response +="</tr>";
  561. #endif
  562. /// WWW Refresh
  563. #if A_REFRESH==1
  564. bg = " background-color: ";
  565. bg += ( (gwayConfig.refresh == 1) ? "LightGreen" : "orange" );
  566. response +="<tr><td class=\"cell\">WWW Refresh</td>";
  567. response +="<td class=\"cell\" colspan=\"2\" style=\"border: 1px solid black; " + bg + "\">";
  568. response += ( (gwayConfig.refresh == 1) ? "ON" : "OFF" );
  569. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"REFR=1\"><button>ON</button></a></td>";
  570. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"REFR=0\"><button>OFF</button></a></td>";
  571. response +="</tr>";
  572. #endif
  573. // Reset Accesspoint
  574. #if _WIFIMANAGER==1
  575. response +="<tr><td><tr><td>";
  576. response +="Click <a href=\"/NEWSSID\">here</a> to reset accesspoint<br>";
  577. response +="</td><td></td></tr>";
  578. #endif
  579. // Update Firmware all statistics
  580. response +="<tr><td class=\"cell\">Update Firmware</td><td colspan=\"2\"></td>";
  581. response +="<td class=\"cell\" colspan=\"2\" class=\"cell\"><a href=\"/UPDATE=1\"><button>UPDATE</button></a></td></tr>";
  582. // Format the Filesystem
  583. response +="<tr><td class=\"cell\">Format SPIFFS</td>";
  584. response +=String() + "<td class=\"cell\" colspan=\"2\" >"+""+"</td>";
  585. response +="<td colspan=\"2\" class=\"cell\"><input type=\"button\" value=\"FORMAT\" onclick=\"ynDialog(\'Do you really want to format?\',\'FORMAT\')\" /></td></tr>";
  586. // Reset all statistics
  587. #if _STATISTICS >= 1
  588. response +="<tr><td class=\"cell\">Statistics</td>";
  589. response +=String() + "<td class=\"cell\" colspan=\"2\" >"+statc.resets+"</td>";
  590. response +="<td colspan=\"2\" class=\"cell\"><input type=\"button\" value=\"RESET\" onclick=\"ynDialog(\'Do you really want to reset statistics?\',\'RESET\')\" /></td></tr>";
  591. // Reset
  592. response +="<tr><td class=\"cell\">Boots and Resets</td>";
  593. response +=String() + "<td class=\"cell\" colspan=\"2\" >"+gwayConfig.boots+"</td>";
  594. response +="<td colspan=\"2\" class=\"cell\"><input type=\"button\" value=\"RESET\" onclick=\"ynDialog(\'Do you want to reset boots?\',\'BOOT\')\" /></td></tr>";
  595. #endif
  596. response +="</table>";
  597. server.sendContent(response);
  598. }
  599. // --------------------------------------------------------------------------------
  600. // H2 Package Statistics
  601. //
  602. // This section display a matrix on the screen where everay channel and spreading
  603. // factor is displayed.
  604. // --------------------------------------------------------------------------------
  605. static void statisticsData()
  606. {
  607. String response="";
  608. // Header
  609. response +="<h2>Package Statistics</h2>";
  610. response +="<table class=\"config_table\">";
  611. response +="<tr><th class=\"thead\">Counter</th>";
  612. #if _STATISTICS == 3
  613. response +="<th class=\"thead\">C 0</th>";
  614. response +="<th class=\"thead\">C 1</th>";
  615. response +="<th class=\"thead\">C 2</th>";
  616. #endif
  617. response +="<th class=\"thead\">Pkgs</th>";
  618. response +="<th class=\"thead\">Pkgs/hr</th>";
  619. response +="</tr>";
  620. //
  621. // Table rows
  622. //
  623. response +="<tr><td class=\"cell\">Packages Downlink</td>";
  624. #if _STATISTICS == 3
  625. response +="<td class=\"cell\">" + String(statc.msg_down_0) + "</td>";
  626. response +="<td class=\"cell\">" + String(statc.msg_down_1) + "</td>";
  627. response +="<td class=\"cell\">" + String(statc.msg_down_2) + "</td>";
  628. #endif
  629. response += "<td class=\"cell\">" + String(statc.msg_down) + "</td>";
  630. response +="<td class=\"cell\"></td></tr>";
  631. response +="<tr><td class=\"cell\">Packages Uplink Total</td>";
  632. #if _STATISTICS == 3
  633. response +="<td class=\"cell\">" + String(statc.msg_ttl_0) + "</td>";
  634. response +="<td class=\"cell\">" + String(statc.msg_ttl_1) + "</td>";
  635. response +="<td class=\"cell\">" + String(statc.msg_ttl_2) + "</td>";
  636. #endif
  637. response +="<td class=\"cell\">" + String(statc.msg_ttl) + "</td>";
  638. response +="<td class=\"cell\">" + String((statc.msg_ttl*3600)/(now() - startTime)) + "</td></tr>";
  639. response +="<tr><td class=\"cell\">Packages Uplink OK </td>";
  640. #if _STATISTICS == 3
  641. response +="<td class=\"cell\">" + String(statc.msg_ok_0) + "</td>";
  642. response +="<td class=\"cell\">" + String(statc.msg_ok_1) + "</td>";
  643. response +="<td class=\"cell\">" + String(statc.msg_ok_2) + "</td>";
  644. #endif
  645. response +="<td class=\"cell\">" + String(statc.msg_ok) + "</td>";
  646. response +="<td class=\"cell\"></td></tr>";
  647. // Provide a table with all the SF data including percentage of messsages
  648. #if _STATISTICS == 2
  649. response +="<tr><td class=\"cell\">SF7 rcvd</td>";
  650. response +="<td class=\"cell\">"; response +=statc.sf7;
  651. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf7/statc.msg_ttl : 0)+" %";
  652. response +="</td></tr>";
  653. response +="<tr><td class=\"cell\">SF8 rcvd</td>";
  654. response +="<td class=\"cell\">"; response +=statc.sf8;
  655. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf8/statc.msg_ttl : 0)+" %";
  656. response +="</td></tr>";
  657. response +="<tr><td class=\"cell\">SF9 rcvd</td>";
  658. response +="<td class=\"cell\">"; response +=statc.sf9;
  659. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf9/statc.msg_ttl : 0)+" %";
  660. response +="</td></tr>";
  661. response +="<tr><td class=\"cell\">SF10 rcvd</td>";
  662. response +="<td class=\"cell\">"; response +=statc.sf10;
  663. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf10/statc.msg_ttl : 0)+" %";
  664. response +="</td></tr>";
  665. response +="<tr><td class=\"cell\">SF11 rcvd</td>";
  666. response +="<td class=\"cell\">"; response +=statc.sf11;
  667. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf11/statc.msg_ttl : 0)+" %";
  668. response +="</td></tr>";
  669. response +="<tr><td class=\"cell\">SF12 rcvd</td>";
  670. response +="<td class=\"cell\">"; response +=statc.sf12;
  671. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf12/statc.msg_ttl : 0)+" %";
  672. response +="</td></tr>";
  673. #endif
  674. #if _STATISTICS == 3
  675. response +="<tr><td class=\"cell\">SF7 rcvd</td>";
  676. response +="<td class=\"cell\">"; response +=statc.sf7_0;
  677. response +="<td class=\"cell\">"; response +=statc.sf7_1;
  678. response +="<td class=\"cell\">"; response +=statc.sf7_2;
  679. response +="<td class=\"cell\">"; response +=statc.sf7;
  680. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf7/statc.msg_ttl : 0)+" %";
  681. response +="</td></tr>";
  682. response +="<tr><td class=\"cell\">SF8 rcvd</td>";
  683. response +="<td class=\"cell\">"; response +=statc.sf8_0;
  684. response +="<td class=\"cell\">"; response +=statc.sf8_1;
  685. response +="<td class=\"cell\">"; response +=statc.sf8_2;
  686. response +="<td class=\"cell\">"; response +=statc.sf8;
  687. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf8/statc.msg_ttl : 0)+" %";
  688. response +="</td></tr>";
  689. response +="<tr><td class=\"cell\">SF9 rcvd</td>";
  690. response +="<td class=\"cell\">"; response +=statc.sf9_0;
  691. response +="<td class=\"cell\">"; response +=statc.sf9_1;
  692. response +="<td class=\"cell\">"; response +=statc.sf9_2;
  693. response +="<td class=\"cell\">"; response +=statc.sf9;
  694. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf9/statc.msg_ttl : 0)+" %";
  695. response +="</td></tr>";
  696. response +="<tr><td class=\"cell\">SF10 rcvd</td>";
  697. response +="<td class=\"cell\">"; response +=statc.sf10_0;
  698. response +="<td class=\"cell\">"; response +=statc.sf10_1;
  699. response +="<td class=\"cell\">"; response +=statc.sf10_2;
  700. response +="<td class=\"cell\">"; response +=statc.sf10;
  701. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf10/statc.msg_ttl : 0)+" %";
  702. response +="</td></tr>";
  703. response +="<tr><td class=\"cell\">SF11 rcvd</td>";
  704. response +="<td class=\"cell\">"; response +=statc.sf11_0;
  705. response +="<td class=\"cell\">"; response +=statc.sf11_1;
  706. response +="<td class=\"cell\">"; response +=statc.sf11_2;
  707. response +="<td class=\"cell\">"; response +=statc.sf11;
  708. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf11/statc.msg_ttl : 0)+" %";
  709. response +="</td></tr>";
  710. response +="<tr><td class=\"cell\">SF12 rcvd</td>";
  711. response +="<td class=\"cell\">"; response +=statc.sf12_0;
  712. response +="<td class=\"cell\">"; response +=statc.sf12_1;
  713. response +="<td class=\"cell\">"; response +=statc.sf12_1;
  714. response +="<td class=\"cell\">"; response +=statc.sf12;
  715. response +="<td class=\"cell\">"; response += String(statc.msg_ttl>0 ? 100*statc.sf12/statc.msg_ttl : 0)+" %";
  716. response +="</td></tr>";
  717. #endif
  718. response +="</table>";
  719. server.sendContent(response);
  720. }
  721. // --------------------------------------------------------------------------------
  722. // Message History
  723. // If enabled, display the sensor messageHistory on the current webserver Page.
  724. // In this GUI section a number of statr[x] records are displayed such as:
  725. //
  726. // Time, The time the sensor message was received
  727. // Node, the DevAddr or even Node name for Trusted nodes,
  728. // Data (Localserver), when _LOCALSERVER is enabled contains decoded data
  729. // C, Channel frequency on which the sensor was received
  730. // Freq, The frequency of the channel
  731. // SF, Spreading Factor
  732. // pRSSI, Packet RSSI
  733. //
  734. // Parameters:
  735. // - <none>
  736. // Returns:
  737. // - <none>
  738. //
  739. // As we make the TRUSTED_NODE a dynamic parameter, it can be set/unset in the user
  740. // interface. It will allow the user to only see known nodes (with a name) in the
  741. // list or also nodes with only an address (Unknown nodes).
  742. // As a result, the size of the list will NOT be as large when only known nodes are
  743. // selected, as in can be deselcted in the GUI and we have only so much space on
  744. // th screen.
  745. // --------------------------------------------------------------------------------
  746. static void messageHistory()
  747. {
  748. #if _STATISTICS >= 1
  749. String response="";
  750. // PRINT HEADERS
  751. response += "<h2>Message History</h2>";
  752. response += "<table class=\"config_table\">";
  753. response += "<tr>";
  754. response += "<th class=\"thead\">Time</th>";
  755. response += "<th class=\"thead\">Node</th>";
  756. #if _LOCALSERVER==1
  757. response += "<th class=\"thead\">Data</th>";
  758. #endif
  759. response += "<th class=\"thead\" style=\"width: 20px;\">C</th>";
  760. response += "<th class=\"thead\">Freq</th>";
  761. response += "<th class=\"thead\" style=\"width: 40px;\">SF</th>";
  762. response += "<th class=\"thead\" style=\"width: 50px;\">pRSSI</th>";
  763. #if RSSI==1
  764. if (debug > 1) {
  765. response += "<th class=\"thead\" style=\"width: 50px;\">RSSI</th>";
  766. }
  767. #endif
  768. response += "</tr>";
  769. server.sendContent(response);
  770. // PRINT NODE CONTENT
  771. for (int i=0; i<MAX_STAT; i++) { // For every Node in the list
  772. if (statr[i].sf == 0) break;
  773. response = "";
  774. response += String() + "<tr><td class=\"cell\">"; // Tmst
  775. stringTime((statr[i].tmst), response); // XXX Change tmst not to be millis() dependent
  776. response += "</td>";
  777. response += String() + "<td class=\"cell\">"; // Node
  778. #ifdef _TRUSTED_NODES // DO nothing with TRUSTED NODES
  779. switch (gwayConfig.trusted) {
  780. case 0: printHEX((char *)(& (statr[i].node)),' ',response);
  781. break;
  782. case 1: if (SerialName((char *)(& (statr[i].node)), response) < 0) {
  783. printHEX((char *)(& (statr[i].node)),' ',response);
  784. };
  785. break;
  786. case 2: if (SerialName((char *)(& (statr[i].node)), response) < 0) {
  787. continue;
  788. };
  789. break;
  790. case 3: // Value and we do not print unless also defined for LOCAL_SERVER
  791. default:
  792. #if _DUSB>=1
  793. Serial.println("Unknow value for gwayConfig.trusted");
  794. #endif
  795. break;
  796. }
  797. #else // _TRUSTED_NODES
  798. printHEX((char *)(& (statr[i].node)),' ',response);
  799. #endif // _TRUSTED_NODES
  800. response += "</td>";
  801. #if _LOCALSERVER==1
  802. response += String() + "<td class=\"cell\">"; // Data
  803. for (int j=0; j<statr[i].datal; j++) {
  804. if (statr[i].data[j] <0x10) response+= "0";
  805. response += String(statr[i].data[j],HEX) + " ";
  806. }
  807. response += "</td>";
  808. #endif
  809. response += String() + "<td class=\"cell\">" + statr[i].ch + "</td>";
  810. response += String() + "<td class=\"cell\">" + freqs[statr[i].ch].upFreq + "</td>";
  811. response += String() + "<td class=\"cell\">" + statr[i].sf + "</td>";
  812. response += String() + "<td class=\"cell\">" + statr[i].prssi + "</td>";
  813. #if RSSI==1
  814. if (debug >= 2) {
  815. response += String() + "<td class=\"cell\">" + statr[i].rssi + "</td>";
  816. }
  817. #endif
  818. response += "</tr>";
  819. server.sendContent(response);
  820. }
  821. server.sendContent("</table>");
  822. #endif
  823. }
  824. // --------------------------------------------------------------------------------
  825. // H2 NODE SEEN HISTORY
  826. // If enabled, display the sensor last Seen history.
  827. // This setting ,pves togetjer with the "expert" mode.
  828. // If that mode is enabled than the node seen intory is displayed
  829. //
  830. // Parameters:
  831. // - <none>
  832. // Returns:
  833. // - <none>
  834. // --------------------------------------------------------------------------------
  835. static void nodeHistory()
  836. {
  837. #if _SEENMAX > 0
  838. if (gwayConfig.expert) {
  839. // First draw the headers
  840. String response="";
  841. response += "<h2>Node Last Seen History</h2>";
  842. response += "<table class=\"config_table\">";
  843. response += "<tr>";
  844. response += "<th class=\"thead\" style=\"width: 220px;\">Time</th>";
  845. response += "<th class=\"thead\">Node</th>";
  846. response += "<th class=\"thead\">Count</th>";
  847. //#if _LOCALSERVER==1
  848. // response += "<th class=\"thead\">Data</th>";
  849. //#endif
  850. response += "<th class=\"thead\" style=\"width: 20px;\">C</th>";
  851. response += "<th class=\"thead\" style=\"width: 40px;\">SF</th>";
  852. response += "</tr>";
  853. server.sendContent(response);
  854. // Now start the contents
  855. int i;
  856. for (i=0; i<_SEENMAX; i++) {
  857. if (listSeen[i].idSeen == 0) break;
  858. response = "";
  859. response += String() + "<tr><td class=\"cell\">"; // Tmst
  860. stringTime((listSeen[i].timSeen), response);
  861. response += "</td>";
  862. response += String() + "<td class=\"cell\">"; // Node
  863. #ifdef _TRUSTED_NODES // DO nothing with TRUSTED NODES
  864. switch (gwayConfig.trusted) {
  865. case 0: printHEX((char *)(& (listSeen[i].idSeen)),' ',response);
  866. break;
  867. case 1: if (SerialName((char *)(& (listSeen[i].idSeen)), response) < 0) {
  868. printHEX((char *)(& (listSeen[i].idSeen)),' ',response);
  869. };
  870. break;
  871. case 2: if (SerialName((char *)(& (listSeen[i].idSeen)), response) < 0) {
  872. continue;
  873. };
  874. break;
  875. case 3: // Value 3 and we do not print unless also defined for LOCAL_SERVER
  876. default:
  877. #if _DUSB>=1
  878. Serial.println("Unknow value for gwayConfig.trusted");
  879. #endif
  880. break;
  881. }
  882. #else // _TRUSTED_NODES
  883. printHEX((char *)(& (listSeen[i].idSeen)),' ',response);
  884. #endif // _TRUSTED_NODES
  885. response += "</td>";
  886. response += String() + "<td class=\"cell\">" + listSeen[i].cntSeen + "</td>"; // Counter
  887. response += String() + "<td class=\"cell\">" + listSeen[i].chnSeen + "</td>"; // Channel
  888. response += String() + "<td class=\"cell\">" + listSeen[i].sfSeen + "</td>"; // SF
  889. server.sendContent(response);
  890. }
  891. server.sendContent("</table>");
  892. }
  893. #endif //_SEENMAX
  894. } // nodeHistory()
  895. // --------------------------------------------------------------------------------
  896. // SEND WEB PAGE()
  897. // Call the webserver and send the standard content and the content that is
  898. // passed by the parameter. Each time a variable is changed, this function is
  899. // called to display the webpage again/
  900. //
  901. // NOTE: This is the only place where yield() or delay() calls are used.
  902. //
  903. // --------------------------------------------------------------------------------
  904. void sendWebPage(const char *cmd, const char *arg)
  905. {
  906. openWebPage(); yield(); // Do the initial website setup
  907. wwwButtons(); // Display buttons such as Documentation, Mode, Logfiles
  908. setVariables(cmd,arg); yield(); // Read Webserver commands from line
  909. statisticsData(); yield(); // Node statistics
  910. messageHistory(); yield(); // Display the sensor history, message statistics
  911. nodeHistory(); yield(); // Display the lastSeen array
  912. gatewaySettings(); yield(); // Display web configuration
  913. wifiConfig(); yield(); // WiFi specific parameters
  914. systemStatus(); yield(); // System statistics such as heap etc.
  915. interruptData(); yield(); // Display interrupts only when debug >= 2
  916. websiteFooter(); yield();
  917. server.client().stop();
  918. }
  919. // --------------------------------------------------------------------------------
  920. // setupWWW is the main function for webserver functions/
  921. // SetupWWW function called by main setup() program to setup webserver
  922. // It does actually not much more than installing all the callback handlers
  923. // for messages sent to the webserver
  924. //
  925. // Implemented is an interface like:
  926. // http://<server>/<Variable>=<value>
  927. //
  928. // --------------------------------------------------------------------------------
  929. void setupWWW()
  930. {
  931. server.begin(); // Start the webserver
  932. // -----------------
  933. // BUTTONS, define what should happen with the buttons we press on the homepage
  934. server.on("/", []() {
  935. sendWebPage("",""); // Send the webPage string
  936. server.sendHeader("Location", String("/"), true);
  937. server.send ( 302, "text/plain", "");
  938. });
  939. server.on("/HELP", []() {
  940. sendWebPage("HELP",""); // Send the webPage string
  941. server.sendHeader("Location", String("/"), true);
  942. server.send ( 302, "text/plain", "");
  943. });
  944. // Format the filesystem
  945. server.on("/FORMAT", []() {
  946. Serial.print(F("FORMAT ..."));
  947. SPIFFS.format(); // Normally disabled. Enable only when SPIFFS corrupt
  948. initConfig(&gwayConfig);
  949. writeConfig( CONFIGFILE, &gwayConfig);
  950. writeSeen( _SEENFILE, listSeen); // Write the last time record is seen
  951. #if _DUSB>=1
  952. Serial.println(F("DONE"));
  953. #endif
  954. server.sendHeader("Location", String("/"), true);
  955. server.send ( 302, "text/plain", "");
  956. });
  957. // Reset the statistics
  958. server.on("/RESET", []() {
  959. Serial.println(F("RESET"));
  960. startTime= now() - 1; // Reset all timers too
  961. statc.msg_ttl = 0; // Reset package statistics
  962. statc.msg_ok = 0;
  963. statc.msg_down = 0;
  964. #if _STATISTICS >= 3
  965. statc.msg_ttl_0 = 0;
  966. statc.msg_ttl_1 = 0;
  967. statc.msg_ttl_2 = 0;
  968. statc.msg_ok_0 = 0;
  969. statc.msg_ok_1 = 0;
  970. statc.msg_ok_2 = 0;
  971. statc.msg_down_0 = 0;
  972. statc.msg_down_1 = 0;
  973. statc.msg_down_2 = 0;
  974. #endif
  975. #if _STATISTICS >= 1
  976. for (int i=0; i<MAX_STAT; i++) { statr[i].sf = 0; }
  977. #if _STATISTICS >= 2
  978. statc.sf7 = 0;
  979. statc.sf8 = 0;
  980. statc.sf9 = 0;
  981. statc.sf10= 0;
  982. statc.sf11= 0;
  983. statc.sf12= 0;
  984. statc.resets= 0;
  985. writeGwayCfg(CONFIGFILE);
  986. #if _STATISTICS >= 3
  987. statc.sf7_0 = 0; statc.sf7_1 = 0; statc.sf7_2 = 0;
  988. statc.sf8_0 = 0; statc.sf8_1 = 0; statc.sf8_2 = 0;
  989. statc.sf9_0 = 0; statc.sf9_1 = 0; statc.sf9_2 = 0;
  990. statc.sf10_0= 0; statc.sf10_1= 0; statc.sf10_2= 0;
  991. statc.sf11_0= 0; statc.sf11_1= 0; statc.sf11_2= 0;
  992. statc.sf12_0= 0; statc.sf12_1= 0; statc.sf12_2= 0;
  993. #endif
  994. #endif
  995. #endif
  996. server.sendHeader("Location", String("/"), true);
  997. server.send ( 302, "text/plain", "");
  998. });
  999. // Reset the boot counter
  1000. server.on("/BOOT", []() {
  1001. #if _STATISTICS >= 2
  1002. gwayConfig.boots = 0;
  1003. gwayConfig.wifis = 0;
  1004. gwayConfig.views = 0;
  1005. gwayConfig.ntpErr = 0; // NTP errors
  1006. gwayConfig.ntpErrTime = 0; // NTP last error time
  1007. gwayConfig.ntps = 0; // Number of NTP calls
  1008. #endif
  1009. gwayConfig.reents = 0; // Re-entrance
  1010. writeGwayCfg(CONFIGFILE);
  1011. #if _DUSB>=1
  1012. Serial.println(F("BOOT, config written"));
  1013. #endif
  1014. server.sendHeader("Location", String("/"), true);
  1015. server.send ( 302, "text/plain", "");
  1016. });
  1017. server.on("/NEWSSID", []() {
  1018. sendWebPage("NEWSSID",""); // Send the webPage string
  1019. server.sendHeader("Location", String("/"), true);
  1020. server.send ( 302, "text/plain", "");
  1021. });
  1022. // Set debug parameter
  1023. server.on("/DEBUG=-1", []() { // Set debug level 0-2
  1024. debug = (debug+3)%4;
  1025. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1026. #if _DUSB>=1
  1027. Serial.println(F("DEBUG -1: config written"));
  1028. #endif
  1029. server.sendHeader("Location", String("/"), true);
  1030. server.send ( 302, "text/plain", "");
  1031. });
  1032. server.on("/DEBUG=1", []() {
  1033. debug = (debug+1)%4;
  1034. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1035. #if _DUSB>=1
  1036. Serial.println(F("DEBUG +1: config written"));
  1037. #endif
  1038. server.sendHeader("Location", String("/"), true);
  1039. server.send ( 302, "text/plain", "");
  1040. });
  1041. // Set PDEBUG parameter
  1042. //
  1043. server.on("/PDEBUG=SCAN", []() { // Set debug level 0-2
  1044. pdebug ^= P_SCAN;
  1045. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1046. server.sendHeader("Location", String("/"), true);
  1047. server.send ( 302, "text/plain", "");
  1048. });
  1049. server.on("/PDEBUG=CAD", []() { // Set debug level 0-2
  1050. pdebug ^= P_CAD;
  1051. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1052. server.sendHeader("Location", String("/"), true);
  1053. server.send ( 302, "text/plain", "");
  1054. });
  1055. server.on("/PDEBUG=RX", []() { // Set debug level 0-2
  1056. pdebug ^= P_RX;
  1057. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1058. server.sendHeader("Location", String("/"), true);
  1059. server.send ( 302, "text/plain", "");
  1060. });
  1061. server.on("/PDEBUG=TX", []() { // Set debug level 0-2
  1062. pdebug ^= P_TX;
  1063. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1064. server.sendHeader("Location", String("/"), true);
  1065. server.send ( 302, "text/plain", "");
  1066. });
  1067. server.on("/PDEBUG=PRE", []() { // Set debug level 0-2
  1068. pdebug ^= P_PRE;
  1069. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1070. server.sendHeader("Location", String("/"), true);
  1071. server.send ( 302, "text/plain", "");
  1072. });
  1073. server.on("/PDEBUG=MAIN", []() { // Set debug level 0-2
  1074. pdebug ^= P_MAIN;
  1075. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1076. server.sendHeader("Location", String("/"), true);
  1077. server.send ( 302, "text/plain", "");
  1078. });
  1079. server.on("/PDEBUG=GUI", []() { // Set debug level 0-2
  1080. pdebug ^= P_GUI;
  1081. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1082. server.sendHeader("Location", String("/"), true);
  1083. server.send ( 302, "text/plain", "");
  1084. });
  1085. server.on("/PDEBUG=RADIO", []() { // Set debug level 0-2
  1086. pdebug ^= P_RADIO;
  1087. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1088. server.sendHeader("Location", String("/"), true);
  1089. server.send ( 302, "text/plain", "");
  1090. });
  1091. // Set delay in microseconds
  1092. server.on("/DELAY=1", []() {
  1093. gwayConfig.txDelay+=5000;
  1094. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1095. #if _DUSB>=1
  1096. Serial.println(F("DELAY +, config written"));
  1097. #endif
  1098. server.sendHeader("Location", String("/"), true);
  1099. server.send ( 302, "text/plain", "");
  1100. });
  1101. server.on("/DELAY=-1", []() {
  1102. gwayConfig.txDelay-=5000;
  1103. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1104. #if _DUSB>=1
  1105. Serial.println(F("DELAY +, config written"));
  1106. #endif
  1107. server.sendHeader("Location", String("/"), true);
  1108. server.send ( 302, "text/plain", "");
  1109. });
  1110. // Set Trusted Node Parameter
  1111. server.on("/TRUSTED=1", []() {
  1112. gwayConfig.trusted = (gwayConfig.trusted +1)%4;
  1113. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1114. #if _DUSB>=2
  1115. Serial.println(F("TRUSTED +, config written"));
  1116. #endif
  1117. server.sendHeader("Location", String("/"), true);
  1118. server.send ( 302, "text/plain", "");
  1119. });
  1120. server.on("/TRUSTED=-1", []() {
  1121. gwayConfig.trusted = (gwayConfig.trusted -1)%4;
  1122. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1123. #if _DUSB>=2
  1124. Serial.println(F("TRUSTED +, config written"));
  1125. #endif
  1126. server.sendHeader("Location", String("/"), true);
  1127. server.send ( 302, "text/plain", "");
  1128. });
  1129. // Spreading Factor setting
  1130. server.on("/SF=1", []() {
  1131. if (sf>=SF12) sf=SF7; else sf= (sf_t)((int)sf+1);
  1132. server.sendHeader("Location", String("/"), true);
  1133. server.send ( 302, "text/plain", "");
  1134. });
  1135. server.on("/SF=-1", []() {
  1136. if (sf<=SF7) sf=SF12; else sf= (sf_t)((int)sf-1);
  1137. server.sendHeader("Location", String("/"), true);
  1138. server.send ( 302, "text/plain", "");
  1139. });
  1140. // Set Frequency of the GateWay node
  1141. server.on("/FREQ=1", []() {
  1142. uint8_t nf = sizeof(freqs)/sizeof(freqs[0]); // Number of elements in array
  1143. #if _DUSB>=2
  1144. Serial.print("FREQ==1:: For freq[0] sizeof vector=");
  1145. Serial.print(sizeof(freqs[0]));
  1146. Serial.println();
  1147. #endif
  1148. if (ifreq==(nf-1)) ifreq=0; else ifreq++;
  1149. server.sendHeader("Location", String("/"), true);
  1150. server.send ( 302, "text/plain", "");
  1151. });
  1152. server.on("/FREQ=-1", []() {
  1153. uint8_t nf = sizeof(freqs)/sizeof(freqs[0]); // Number of elements in array
  1154. if (ifreq==0) ifreq=(nf-1); else ifreq--;
  1155. server.sendHeader("Location", String("/"), true);
  1156. server.send ( 302, "text/plain", "");
  1157. });
  1158. // Set CAD function off/on
  1159. server.on("/CAD=1", []() {
  1160. _cad=(bool)1;
  1161. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1162. server.sendHeader("Location", String("/"), true);
  1163. server.send ( 302, "text/plain", "");
  1164. });
  1165. server.on("/CAD=0", []() {
  1166. _cad=(bool)0;
  1167. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1168. server.sendHeader("Location", String("/"), true);
  1169. server.send ( 302, "text/plain", "");
  1170. });
  1171. // GatewayNode
  1172. server.on("/NODE=1", []() {
  1173. #if GATEWAYNODE==1
  1174. gwayConfig.isNode =(bool)1;
  1175. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1176. #endif
  1177. server.sendHeader("Location", String("/"), true);
  1178. server.send ( 302, "text/plain", "");
  1179. });
  1180. server.on("/NODE=0", []() {
  1181. #if GATEWAYNODE==1
  1182. gwayConfig.isNode =(bool)0;
  1183. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1184. #endif
  1185. server.sendHeader("Location", String("/"), true);
  1186. server.send ( 302, "text/plain", "");
  1187. });
  1188. #if GATEWAYNODE==1
  1189. // Framecounter of the Gateway node
  1190. server.on("/FCNT", []() {
  1191. frameCount=0;
  1192. rxLoraModem(); // Reset the radio with the new frequency
  1193. writeGwayCfg(CONFIGFILE);
  1194. //sendWebPage("",""); // Send the webPage string
  1195. server.sendHeader("Location", String("/"), true);
  1196. server.send ( 302, "text/plain", "");
  1197. });
  1198. #endif
  1199. // WWW Page refresh function
  1200. server.on("/REFR=1", []() { // WWW page auto refresh ON
  1201. #if A_REFRESH==1
  1202. gwayConfig.refresh =1;
  1203. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1204. #endif
  1205. server.sendHeader("Location", String("/"), true);
  1206. server.send ( 302, "text/plain", "");
  1207. });
  1208. server.on("/REFR=0", []() { // WWW page auto refresh OFF
  1209. #if A_REFRESH==1
  1210. gwayConfig.refresh =0;
  1211. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1212. #endif
  1213. server.sendHeader("Location", String("/"), true);
  1214. server.send ( 302, "text/plain", "");
  1215. });
  1216. // Switch off/on the HOP functions
  1217. server.on("/HOP=1", []() {
  1218. _hop=true;
  1219. server.sendHeader("Location", String("/"), true);
  1220. server.send ( 302, "text/plain", "");
  1221. });
  1222. server.on("/HOP=0", []() {
  1223. _hop=false;
  1224. ifreq=0;
  1225. setFreq(freqs[ifreq].upFreq);
  1226. rxLoraModem();
  1227. server.sendHeader("Location", String("/"), true);
  1228. server.send ( 302, "text/plain", "");
  1229. });
  1230. #if !defined ESP32_ARCH
  1231. // Change speed to 160 MHz
  1232. server.on("/SPEED=80", []() {
  1233. system_update_cpu_freq(80);
  1234. server.sendHeader("Location", String("/"), true);
  1235. server.send ( 302, "text/plain", "");
  1236. });
  1237. server.on("/SPEED=160", []() {
  1238. system_update_cpu_freq(160);
  1239. server.sendHeader("Location", String("/"), true);
  1240. server.send ( 302, "text/plain", "");
  1241. });
  1242. #endif
  1243. // Display Documentation pages
  1244. server.on("/DOCU", []() {
  1245. server.sendHeader("Location", String("/"), true);
  1246. buttonDocu();
  1247. server.send ( 302, "text/plain", "");
  1248. });
  1249. // Display LOGging information
  1250. server.on("/LOG", []() {
  1251. server.sendHeader("Location", String("/"), true);
  1252. #if _DUSB>=2
  1253. Serial.println(F("LOG button"));
  1254. #endif
  1255. buttonLog();
  1256. server.send ( 302, "text/plain", "");
  1257. });
  1258. // Display Expert mode or Simple mode
  1259. server.on("/EXPERT", []() {
  1260. server.sendHeader("Location", String("/"), true);
  1261. gwayConfig.expert = bool(1 - (int) gwayConfig.expert) ;
  1262. server.send ( 302, "text/plain", "");
  1263. });
  1264. // Display the SEEN statistics
  1265. server.on("/SEEN", []() {
  1266. server.sendHeader("Location", String("/"), true);
  1267. #if _DUSB>=1
  1268. Serial.println(F("SEEN button"));
  1269. printSeen(listSeen);
  1270. #endif
  1271. buttonSeen();
  1272. server.send ( 302, "text/plain", "");
  1273. });
  1274. // Update the sketch. Not yet implemented
  1275. server.on("/UPDATE=1", []() {
  1276. #if A_OTA==1
  1277. updateOtaa();
  1278. #endif
  1279. server.sendHeader("Location", String("/"), true);
  1280. server.send ( 302, "text/plain", "");
  1281. });
  1282. // -----------
  1283. // This section from version 4.0.7 defines what PART of the
  1284. // webpage is shown based on the buttons pressed by the user
  1285. // Maybe not all information should be put on the screen since it
  1286. // may take too much time to serve all information before a next
  1287. // package interrupt arrives at the gateway
  1288. Serial.print(F("WWW Server started on port "));
  1289. Serial.println(A_SERVERPORT);
  1290. return;
  1291. } // setupWWW
  1292. // --------------------------------------------------------------------------------
  1293. // WIFI CONFIG
  1294. // wifiConfig() displays the most important Wifi parameters gathered
  1295. //
  1296. // --------------------------------------------------------------------------------
  1297. static void wifiConfig()
  1298. {
  1299. if (gwayConfig.expert) {
  1300. String response="";
  1301. response +="<h2>WiFi Config</h2>";
  1302. response +="<table class=\"config_table\">";
  1303. response +="<tr><th class=\"thead\">Parameter</th><th class=\"thead\">Value</th></tr>";
  1304. response +="<tr><td class=\"cell\">WiFi host</td><td class=\"cell\">";
  1305. #if ESP32_ARCH==1
  1306. response +=WiFi.getHostname(); response+="</tr>";
  1307. #else
  1308. response +=wifi_station_get_hostname(); response+="</tr>";
  1309. #endif
  1310. response +="<tr><td class=\"cell\">WiFi SSID</td><td class=\"cell\">";
  1311. response +=WiFi.SSID(); response+="</tr>";
  1312. response +="<tr><td class=\"cell\">IP Address</td><td class=\"cell\">";
  1313. printIP((IPAddress)WiFi.localIP(),'.',response);
  1314. response +="</tr>";
  1315. response +="<tr><td class=\"cell\">IP Gateway</td><td class=\"cell\">";
  1316. printIP((IPAddress)WiFi.gatewayIP(),'.',response);
  1317. response +="</tr>";
  1318. response +="<tr><td class=\"cell\">NTP Server</td><td class=\"cell\">"; response+=NTP_TIMESERVER; response+="</tr>";
  1319. response +="<tr><td class=\"cell\">LoRa Router</td><td class=\"cell\">"; response+=_TTNSERVER; response+="</tr>";
  1320. response +="<tr><td class=\"cell\">LoRa Router IP</td><td class=\"cell\">";
  1321. printIP((IPAddress)ttnServer,'.',response);
  1322. response +="</tr>";
  1323. #ifdef _THINGSERVER
  1324. response +="<tr><td class=\"cell\">LoRa Router 2</td><td class=\"cell\">"; response+=_THINGSERVER;
  1325. response += String() + ":" + _THINGPORT + "</tr>";
  1326. response +="<tr><td class=\"cell\">LoRa Router 2 IP</td><td class=\"cell\">";
  1327. printIP((IPAddress)thingServer,'.',response);
  1328. response +="</tr>";
  1329. #endif
  1330. response +="</table>";
  1331. server.sendContent(response);
  1332. } // gwayConfig.expert
  1333. } // wifiConfig
  1334. // --------------------------------------------------------------------------------
  1335. // H2 systemStatus
  1336. // systemStatus is additional and only available in the expert mode.
  1337. // It provides a number of system specific data such as heap size etc.
  1338. // --------------------------------------------------------------------------------
  1339. static void systemStatus()
  1340. {
  1341. if (gwayConfig.expert) {
  1342. String response="";
  1343. response +="<h2>System Status</h2>";
  1344. response +="<table class=\"config_table\">";
  1345. response +="<tr>";
  1346. response +="<th class=\"thead\">Parameter</th>";
  1347. response +="<th class=\"thead\">Value</th>";
  1348. response +="<th colspan=\"2\" class=\"thead\">Set</th>";
  1349. response +="</tr>";
  1350. response +="<tr><td style=\"border: 1px solid black; width:120px;\">Gateway ID</td>";
  1351. response +="<td class=\"cell\">";
  1352. if (MAC_array[0]< 0x10) response +='0'; response +=String(MAC_array[0],HEX); // The MAC array is always returned in lowercase
  1353. if (MAC_array[1]< 0x10) response +='0'; response +=String(MAC_array[1],HEX);
  1354. if (MAC_array[2]< 0x10) response +='0'; response +=String(MAC_array[2],HEX);
  1355. response +="FFFF";
  1356. if (MAC_array[3]< 0x10) response +='0'; response +=String(MAC_array[3],HEX);
  1357. if (MAC_array[4]< 0x10) response +='0'; response +=String(MAC_array[4],HEX);
  1358. if (MAC_array[5]< 0x10) response +='0'; response +=String(MAC_array[5],HEX);
  1359. response+="</tr>";
  1360. response +="<tr><td class=\"cell\">Free heap</td><td class=\"cell\">"; response+=ESP.getFreeHeap(); response+="</tr>";
  1361. // XXX We Shoudl find an ESP32 alternative
  1362. #if !defined ESP32_ARCH
  1363. response +="<tr><td class=\"cell\">ESP speed</td><td class=\"cell\">"; response+=ESP.getCpuFreqMHz();
  1364. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"SPEED=80\"><button>80</button></a></td>";
  1365. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"SPEED=160\"><button>160</button></a></td>";
  1366. response+="</tr>";
  1367. response +="<tr><td class=\"cell\">ESP Chip ID</td><td class=\"cell\">"; response+=ESP.getChipId(); response+="</tr>";
  1368. #endif
  1369. response +="<tr><td class=\"cell\">OLED</td><td class=\"cell\">"; response+=OLED; response+="</tr>";
  1370. #if _STATISTICS >= 1
  1371. response +="<tr><td class=\"cell\">WiFi Setups</td><td class=\"cell\">"; response+=gwayConfig.wifis; response+="</tr>";
  1372. response +="<tr><td class=\"cell\">WWW Views</td><td class=\"cell\">"; response+=gwayConfig.views; response+="</tr>";
  1373. #endif
  1374. response +="</table>";
  1375. server.sendContent(response);
  1376. } // gwayConfig.expert
  1377. } // systemStatus
  1378. // --------------------------------------------------------------------------------
  1379. // H2 System State and Interrupt
  1380. // Display interrupt data, but only for debug >= 2
  1381. //
  1382. // --------------------------------------------------------------------------------
  1383. static void interruptData()
  1384. {
  1385. if (gwayConfig.expert) {
  1386. uint8_t flags = readRegister(REG_IRQ_FLAGS);
  1387. uint8_t mask = readRegister(REG_IRQ_FLAGS_MASK);
  1388. String response="";
  1389. response +="<h2>System State and Interrupt</h2>";
  1390. response +="<table class=\"config_table\">";
  1391. response +="<tr>";
  1392. response +="<th class=\"thead\">Parameter</th>";
  1393. response +="<th class=\"thead\">Value</th>";
  1394. response +="<th colspan=\"2\" class=\"thead\">Set</th>";
  1395. response +="</tr>";
  1396. response +="<tr><td class=\"cell\">_state</td>";
  1397. response +="<td class=\"cell\">";
  1398. switch (_state) { // See loraModem.h
  1399. case S_INIT: response +="INIT"; break;
  1400. case S_SCAN: response +="SCAN"; break;
  1401. case S_CAD: response +="CAD"; break;
  1402. case S_RX: response +="RX"; break;
  1403. case S_TX: response +="TX"; break;
  1404. default: response +="unknown"; break;
  1405. }
  1406. response +="</td></tr>";
  1407. response +="<tr><td class=\"cell\">_STRICT_1CH</td>";
  1408. response +="<td class=\"cell\">" ;
  1409. response += String() + _STRICT_1CH;
  1410. response +="</td></tr>";
  1411. response +="<tr><td class=\"cell\">flags (8 bits)</td>";
  1412. response +="<td class=\"cell\">0x";
  1413. if (flags <16) response += "0";
  1414. response +=String(flags,HEX); response+="</td></tr>";
  1415. response +="<tr><td class=\"cell\">mask (8 bits)</td>";
  1416. response +="<td class=\"cell\">0x";
  1417. if (mask <16) response += "0";
  1418. response +=String(mask,HEX); response+="</td></tr>";
  1419. response +="<tr><td class=\"cell\">Re-entrant cntr</td>";
  1420. response +="<td class=\"cell\">";
  1421. response += String() + gwayConfig.reents;
  1422. response +="</td></tr>";
  1423. response +="<tr><td class=\"cell\">ntp call cntr</td>";
  1424. response +="<td class=\"cell\">";
  1425. response += String() + gwayConfig.ntps;
  1426. response+="</td></tr>";
  1427. response +="<tr><td class=\"cell\">ntpErr cntr</td>";
  1428. response +="<td class=\"cell\">";
  1429. response += String() + gwayConfig.ntpErr;
  1430. response +="</td>";
  1431. response +="<td colspan=\"2\" style=\"border: 1px solid black;\">";
  1432. stringTime(gwayConfig.ntpErrTime, response);
  1433. response +="</td>";
  1434. response +="</tr>";
  1435. response +="</table>";
  1436. server.sendContent(response);
  1437. }// if gwayConfig.expert
  1438. } // interruptData
  1439. // --------------------------------------------------------------------------------
  1440. // websiteFooter
  1441. //
  1442. // Thi function displays the last messages without header on the webpage and then
  1443. // closes the webpage.
  1444. // --------------------------------------------------------------------------------
  1445. static void websiteFooter()
  1446. {
  1447. // Close the client connection to server
  1448. server.sendContent(String() + "<br><br /><p style='font-size:10px'>Click <a href=\"/HELP\">here</a> to explain Help and REST options</p><br>");
  1449. server.sendContent(String() + "</BODY></HTML>");
  1450. server.sendContent(""); yield();
  1451. }
  1452. #endif // A_SERVER==1