_wwwServer.ino 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. // 1-channel LoRa Gateway for ESP8266
  2. // Copyright (c) 2016, 2017, 2018, 2019 Maarten Westenberg version for ESP8266
  3. // Version 6.1.3
  4. // Date: 2019-11-20
  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 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\" 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. }
  796. #else // _TRUSTED_NODES
  797. printHEX((char *)(& (statr[i].node)),' ',response);
  798. #endif // _TRUSTED_NODES
  799. response += "</td>";
  800. #if _LOCALSERVER==1
  801. response += String() + "<td class=\"cell\">"; // Data
  802. for (int j=0; j<statr[i].datal; j++) {
  803. if (statr[i].data[j] <0x10) response+= "0";
  804. response += String(statr[i].data[j],HEX) + " ";
  805. }
  806. response += "</td>";
  807. #endif
  808. response += String() + "<td class=\"cell\">" + statr[i].ch + "</td>";
  809. response += String() + "<td class=\"cell\">" + freqs[statr[i].ch].upFreq + "</td>";
  810. response += String() + "<td class=\"cell\">" + statr[i].sf + "</td>";
  811. response += String() + "<td class=\"cell\">" + statr[i].prssi + "</td>";
  812. #if RSSI==1
  813. if (debug >= 2) {
  814. response += String() + "<td class=\"cell\">" + statr[i].rssi + "</td>";
  815. }
  816. #endif
  817. response += "</tr>";
  818. server.sendContent(response);
  819. }
  820. server.sendContent("</table>");
  821. #endif
  822. }
  823. // --------------------------------------------------------------------------------
  824. // H2 NODE SEEN HISTORY
  825. // If enabled, display the sensor last Seen history.
  826. // This setting ,pves togetjer with the "expert" mode.
  827. // If that mode is enabled than the node seen intory is displayed
  828. //
  829. // Parameters:
  830. // - <none>
  831. // Returns:
  832. // - <none>
  833. // --------------------------------------------------------------------------------
  834. static void nodeHistory()
  835. {
  836. #if _SEENMAX > 0
  837. if (gwayConfig.expert) {
  838. // First draw the headers
  839. String response="";
  840. response += "<h2>Node Last Seen History</h2>";
  841. response += "<table class=\"config_table\">";
  842. response += "<tr>";
  843. response += "<th class=\"thead\" style=\"width: 220px;\">Time</th>";
  844. response += "<th class=\"thead\">Node</th>";
  845. //#if _LOCALSERVER==1
  846. // response += "<th class=\"thead\">Data</th>";
  847. //#endif
  848. response += "<th class=\"thead\" style=\"width: 20px;\">C</th>";
  849. response += "<th class=\"thead\" style=\"width: 40px;\">SF</th>";
  850. response += "</tr>";
  851. server.sendContent(response);
  852. // Now start the contents
  853. int i;
  854. for (i=0; i<_SEENMAX; i++) {
  855. if (listSeen[i].idSeen == 0) break;
  856. response = "";
  857. response += String() + "<tr><td class=\"cell\">"; // Tmst
  858. stringTime((listSeen[i].timSeen), response);
  859. response += "</td>";
  860. response += String() + "<td class=\"cell\">"; // Node
  861. #ifdef _TRUSTED_NODES // DO nothing with TRUSTED NODES
  862. switch (gwayConfig.trusted) {
  863. case 0: printHEX((char *)(& (listSeen[i].idSeen)),' ',response);
  864. break;
  865. case 1: if (SerialName((char *)(& (listSeen[i].idSeen)), response) < 0) {
  866. printHEX((char *)(& (listSeen[i].idSeen)),' ',response);
  867. };
  868. break;
  869. case 2: if (SerialName((char *)(& (listSeen[i].idSeen)), response) < 0) {
  870. continue;
  871. };
  872. break;
  873. case 3: // Value 3 and we do not print unless also defined for LOCAL_SERVER
  874. default:
  875. #if _DUSB>=1
  876. Serial.println("Unknow value for gwayConfig.trusted");
  877. #endif
  878. }
  879. #else // _TRUSTED_NODES
  880. printHEX((char *)(& (listSeen[i].idSeen)),' ',response);
  881. #endif // _TRUSTED_NODES
  882. response += "</td>";
  883. response += String() + "<td class=\"cell\">" + 0 + "</td>"; // Channel
  884. response += String() + "<td class=\"cell\">" + listSeen[i].sfSeen + "</td>";
  885. server.sendContent(response);
  886. }
  887. server.sendContent("</table>");
  888. }
  889. #endif //_SEENMAX
  890. } // nodeHistory()
  891. // --------------------------------------------------------------------------------
  892. // SEND WEB PAGE()
  893. // Call the webserver and send the standard content and the content that is
  894. // passed by the parameter. Each time a variable is changed, this function is
  895. // called to display the webpage again/
  896. //
  897. // NOTE: This is the only place where yield() or delay() calls are used.
  898. //
  899. // --------------------------------------------------------------------------------
  900. void sendWebPage(const char *cmd, const char *arg)
  901. {
  902. openWebPage(); yield(); // Do the initial website setup
  903. wwwButtons(); // Display buttons such as Documentation, Mode, Logfiles
  904. setVariables(cmd,arg); yield(); // Read Webserver commands from line
  905. statisticsData(); yield(); // Node statistics
  906. messageHistory(); yield(); // Display the sensor history, message statistics
  907. nodeHistory(); yield(); // Display the lastSeen array
  908. gatewaySettings(); yield(); // Display web configuration
  909. wifiConfig(); yield(); // WiFi specific parameters
  910. systemStatus(); yield(); // System statistics such as heap etc.
  911. interruptData(); yield(); // Display interrupts only when debug >= 2
  912. websiteFooter(); yield();
  913. server.client().stop();
  914. }
  915. // --------------------------------------------------------------------------------
  916. // setupWWW is the main function for webserver functions/
  917. // SetupWWW function called by main setup() program to setup webserver
  918. // It does actually not much more than installing all the callback handlers
  919. // for messages sent to the webserver
  920. //
  921. // Implemented is an interface like:
  922. // http://<server>/<Variable>=<value>
  923. //
  924. // --------------------------------------------------------------------------------
  925. void setupWWW()
  926. {
  927. server.begin(); // Start the webserver
  928. // -----------------
  929. // BUTTONS, define what should happen with the buttons we press on the homepage
  930. server.on("/", []() {
  931. sendWebPage("",""); // Send the webPage string
  932. server.sendHeader("Location", String("/"), true);
  933. server.send ( 302, "text/plain", "");
  934. });
  935. server.on("/HELP", []() {
  936. sendWebPage("HELP",""); // Send the webPage string
  937. server.sendHeader("Location", String("/"), true);
  938. server.send ( 302, "text/plain", "");
  939. });
  940. // Format the filesystem
  941. server.on("/FORMAT", []() {
  942. Serial.print(F("FORMAT ..."));
  943. SPIFFS.format(); // Normally disabled. Enable only when SPIFFS corrupt
  944. initConfig(&gwayConfig);
  945. writeConfig( CONFIGFILE, &gwayConfig);
  946. writeSeen( _SEENFILE, listSeen); // Write the last time record is seen
  947. #if _DUSB>=1
  948. Serial.println(F("DONE"));
  949. #endif
  950. server.sendHeader("Location", String("/"), true);
  951. server.send ( 302, "text/plain", "");
  952. });
  953. // Reset the statistics
  954. server.on("/RESET", []() {
  955. Serial.println(F("RESET"));
  956. startTime= now() - 1; // Reset all timers too
  957. statc.msg_ttl = 0; // Reset package statistics
  958. statc.msg_ok = 0;
  959. statc.msg_down = 0;
  960. #if _STATISTICS >= 3
  961. statc.msg_ttl_0 = 0;
  962. statc.msg_ttl_1 = 0;
  963. statc.msg_ttl_2 = 0;
  964. statc.msg_ok_0 = 0;
  965. statc.msg_ok_1 = 0;
  966. statc.msg_ok_2 = 0;
  967. statc.msg_down_0 = 0;
  968. statc.msg_down_1 = 0;
  969. statc.msg_down_2 = 0;
  970. #endif
  971. #if _STATISTICS >= 1
  972. for (int i=0; i<MAX_STAT; i++) { statr[i].sf = 0; }
  973. #if _STATISTICS >= 2
  974. statc.sf7 = 0;
  975. statc.sf8 = 0;
  976. statc.sf9 = 0;
  977. statc.sf10= 0;
  978. statc.sf11= 0;
  979. statc.sf12= 0;
  980. statc.resets= 0;
  981. writeGwayCfg(CONFIGFILE);
  982. #if _STATISTICS >= 3
  983. statc.sf7_0 = 0; statc.sf7_1 = 0; statc.sf7_2 = 0;
  984. statc.sf8_0 = 0; statc.sf8_1 = 0; statc.sf8_2 = 0;
  985. statc.sf9_0 = 0; statc.sf9_1 = 0; statc.sf9_2 = 0;
  986. statc.sf10_0= 0; statc.sf10_1= 0; statc.sf10_2= 0;
  987. statc.sf11_0= 0; statc.sf11_1= 0; statc.sf11_2= 0;
  988. statc.sf12_0= 0; statc.sf12_1= 0; statc.sf12_2= 0;
  989. #endif
  990. #endif
  991. #endif
  992. server.sendHeader("Location", String("/"), true);
  993. server.send ( 302, "text/plain", "");
  994. });
  995. // Reset the boot counter
  996. server.on("/BOOT", []() {
  997. #if _STATISTICS >= 2
  998. gwayConfig.boots = 0;
  999. gwayConfig.wifis = 0;
  1000. gwayConfig.views = 0;
  1001. gwayConfig.ntpErr = 0; // NTP errors
  1002. gwayConfig.ntpErrTime = 0; // NTP last error time
  1003. gwayConfig.ntps = 0; // Number of NTP calls
  1004. #endif
  1005. gwayConfig.reents = 0; // Re-entrance
  1006. writeGwayCfg(CONFIGFILE);
  1007. #if _DUSB>=1
  1008. Serial.println(F("BOOT, config written"));
  1009. #endif
  1010. server.sendHeader("Location", String("/"), true);
  1011. server.send ( 302, "text/plain", "");
  1012. });
  1013. server.on("/NEWSSID", []() {
  1014. sendWebPage("NEWSSID",""); // Send the webPage string
  1015. server.sendHeader("Location", String("/"), true);
  1016. server.send ( 302, "text/plain", "");
  1017. });
  1018. // Set debug parameter
  1019. server.on("/DEBUG=-1", []() { // Set debug level 0-2
  1020. debug = (debug+3)%4;
  1021. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1022. #if _DUSB>=1
  1023. Serial.println(F("DEBUG -1: config written"));
  1024. #endif
  1025. server.sendHeader("Location", String("/"), true);
  1026. server.send ( 302, "text/plain", "");
  1027. });
  1028. server.on("/DEBUG=1", []() {
  1029. debug = (debug+1)%4;
  1030. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1031. #if _DUSB>=1
  1032. Serial.println(F("DEBUG +1: config written"));
  1033. #endif
  1034. server.sendHeader("Location", String("/"), true);
  1035. server.send ( 302, "text/plain", "");
  1036. });
  1037. // Set PDEBUG parameter
  1038. //
  1039. server.on("/PDEBUG=SCAN", []() { // Set debug level 0-2
  1040. pdebug ^= P_SCAN;
  1041. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1042. server.sendHeader("Location", String("/"), true);
  1043. server.send ( 302, "text/plain", "");
  1044. });
  1045. server.on("/PDEBUG=CAD", []() { // Set debug level 0-2
  1046. pdebug ^= P_CAD;
  1047. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1048. server.sendHeader("Location", String("/"), true);
  1049. server.send ( 302, "text/plain", "");
  1050. });
  1051. server.on("/PDEBUG=RX", []() { // Set debug level 0-2
  1052. pdebug ^= P_RX;
  1053. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1054. server.sendHeader("Location", String("/"), true);
  1055. server.send ( 302, "text/plain", "");
  1056. });
  1057. server.on("/PDEBUG=TX", []() { // Set debug level 0-2
  1058. pdebug ^= P_TX;
  1059. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1060. server.sendHeader("Location", String("/"), true);
  1061. server.send ( 302, "text/plain", "");
  1062. });
  1063. server.on("/PDEBUG=PRE", []() { // Set debug level 0-2
  1064. pdebug ^= P_PRE;
  1065. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1066. server.sendHeader("Location", String("/"), true);
  1067. server.send ( 302, "text/plain", "");
  1068. });
  1069. server.on("/PDEBUG=MAIN", []() { // Set debug level 0-2
  1070. pdebug ^= P_MAIN;
  1071. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1072. server.sendHeader("Location", String("/"), true);
  1073. server.send ( 302, "text/plain", "");
  1074. });
  1075. server.on("/PDEBUG=GUI", []() { // Set debug level 0-2
  1076. pdebug ^= P_GUI;
  1077. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1078. server.sendHeader("Location", String("/"), true);
  1079. server.send ( 302, "text/plain", "");
  1080. });
  1081. server.on("/PDEBUG=RADIO", []() { // Set debug level 0-2
  1082. pdebug ^= P_RADIO;
  1083. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1084. server.sendHeader("Location", String("/"), true);
  1085. server.send ( 302, "text/plain", "");
  1086. });
  1087. // Set delay in microseconds
  1088. server.on("/DELAY=1", []() {
  1089. gwayConfig.txDelay+=5000;
  1090. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1091. #if _DUSB>=1
  1092. Serial.println(F("DELAY +, config written"));
  1093. #endif
  1094. server.sendHeader("Location", String("/"), true);
  1095. server.send ( 302, "text/plain", "");
  1096. });
  1097. server.on("/DELAY=-1", []() {
  1098. gwayConfig.txDelay-=5000;
  1099. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1100. #if _DUSB>=1
  1101. Serial.println(F("DELAY +, config written"));
  1102. #endif
  1103. server.sendHeader("Location", String("/"), true);
  1104. server.send ( 302, "text/plain", "");
  1105. });
  1106. // Set Trusted Node Parameter
  1107. server.on("/TRUSTED=1", []() {
  1108. gwayConfig.trusted = (gwayConfig.trusted +1)%4;
  1109. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1110. #if _DUSB>=2
  1111. Serial.println(F("TRUSTED +, config written"));
  1112. #endif
  1113. server.sendHeader("Location", String("/"), true);
  1114. server.send ( 302, "text/plain", "");
  1115. });
  1116. server.on("/TRUSTED=-1", []() {
  1117. gwayConfig.trusted = (gwayConfig.trusted -1)%4;
  1118. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1119. #if _DUSB>=2
  1120. Serial.println(F("TRUSTED +, config written"));
  1121. #endif
  1122. server.sendHeader("Location", String("/"), true);
  1123. server.send ( 302, "text/plain", "");
  1124. });
  1125. // Spreading Factor setting
  1126. server.on("/SF=1", []() {
  1127. if (sf>=SF12) sf=SF7; else sf= (sf_t)((int)sf+1);
  1128. server.sendHeader("Location", String("/"), true);
  1129. server.send ( 302, "text/plain", "");
  1130. });
  1131. server.on("/SF=-1", []() {
  1132. if (sf<=SF7) sf=SF12; else sf= (sf_t)((int)sf-1);
  1133. server.sendHeader("Location", String("/"), true);
  1134. server.send ( 302, "text/plain", "");
  1135. });
  1136. // Set Frequency of the GateWay node
  1137. server.on("/FREQ=1", []() {
  1138. uint8_t nf = sizeof(freqs)/sizeof(freqs[0]); // Number of elements in array
  1139. #if _DUSB==2
  1140. Serial.print("FREQ==1:: For freq[0] sizeof vector=");
  1141. Serial.print(sizeof(freqs[0]));
  1142. Serial.println();
  1143. #endif
  1144. if (ifreq==(nf-1)) ifreq=0; else ifreq++;
  1145. server.sendHeader("Location", String("/"), true);
  1146. server.send ( 302, "text/plain", "");
  1147. });
  1148. server.on("/FREQ=-1", []() {
  1149. uint8_t nf = sizeof(freqs)/sizeof(freqs[0]); // Number of elements in array
  1150. if (ifreq==0) ifreq=(nf-1); else ifreq--;
  1151. server.sendHeader("Location", String("/"), true);
  1152. server.send ( 302, "text/plain", "");
  1153. });
  1154. // Set CAD function off/on
  1155. server.on("/CAD=1", []() {
  1156. _cad=(bool)1;
  1157. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1158. server.sendHeader("Location", String("/"), true);
  1159. server.send ( 302, "text/plain", "");
  1160. });
  1161. server.on("/CAD=0", []() {
  1162. _cad=(bool)0;
  1163. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1164. server.sendHeader("Location", String("/"), true);
  1165. server.send ( 302, "text/plain", "");
  1166. });
  1167. // GatewayNode
  1168. server.on("/NODE=1", []() {
  1169. #if GATEWAYNODE==1
  1170. gwayConfig.isNode =(bool)1;
  1171. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1172. #endif
  1173. server.sendHeader("Location", String("/"), true);
  1174. server.send ( 302, "text/plain", "");
  1175. });
  1176. server.on("/NODE=0", []() {
  1177. #if GATEWAYNODE==1
  1178. gwayConfig.isNode =(bool)0;
  1179. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1180. #endif
  1181. server.sendHeader("Location", String("/"), true);
  1182. server.send ( 302, "text/plain", "");
  1183. });
  1184. #if GATEWAYNODE==1
  1185. // Framecounter of the Gateway node
  1186. server.on("/FCNT", []() {
  1187. frameCount=0;
  1188. rxLoraModem(); // Reset the radio with the new frequency
  1189. writeGwayCfg(CONFIGFILE);
  1190. //sendWebPage("",""); // Send the webPage string
  1191. server.sendHeader("Location", String("/"), true);
  1192. server.send ( 302, "text/plain", "");
  1193. });
  1194. #endif
  1195. // WWW Page refresh function
  1196. server.on("/REFR=1", []() { // WWW page auto refresh ON
  1197. #if A_REFRESH==1
  1198. gwayConfig.refresh =1;
  1199. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1200. #endif
  1201. server.sendHeader("Location", String("/"), true);
  1202. server.send ( 302, "text/plain", "");
  1203. });
  1204. server.on("/REFR=0", []() { // WWW page auto refresh OFF
  1205. #if A_REFRESH==1
  1206. gwayConfig.refresh =0;
  1207. writeGwayCfg(CONFIGFILE); // Save configuration to file
  1208. #endif
  1209. server.sendHeader("Location", String("/"), true);
  1210. server.send ( 302, "text/plain", "");
  1211. });
  1212. // Switch off/on the HOP functions
  1213. server.on("/HOP=1", []() {
  1214. _hop=true;
  1215. server.sendHeader("Location", String("/"), true);
  1216. server.send ( 302, "text/plain", "");
  1217. });
  1218. server.on("/HOP=0", []() {
  1219. _hop=false;
  1220. ifreq=0;
  1221. setFreq(freqs[ifreq].upFreq);
  1222. rxLoraModem();
  1223. server.sendHeader("Location", String("/"), true);
  1224. server.send ( 302, "text/plain", "");
  1225. });
  1226. #if !defined ESP32_ARCH
  1227. // Change speed to 160 MHz
  1228. server.on("/SPEED=80", []() {
  1229. system_update_cpu_freq(80);
  1230. server.sendHeader("Location", String("/"), true);
  1231. server.send ( 302, "text/plain", "");
  1232. });
  1233. server.on("/SPEED=160", []() {
  1234. system_update_cpu_freq(160);
  1235. server.sendHeader("Location", String("/"), true);
  1236. server.send ( 302, "text/plain", "");
  1237. });
  1238. #endif
  1239. // Display Documentation pages
  1240. server.on("/DOCU", []() {
  1241. server.sendHeader("Location", String("/"), true);
  1242. buttonDocu();
  1243. server.send ( 302, "text/plain", "");
  1244. });
  1245. // Display LOGging information
  1246. server.on("/LOG", []() {
  1247. server.sendHeader("Location", String("/"), true);
  1248. #if _DUSB>=2
  1249. Serial.println(F("LOG button"));
  1250. #endif
  1251. buttonLog();
  1252. server.send ( 302, "text/plain", "");
  1253. });
  1254. // Display Expert mode or Simple mode
  1255. server.on("/EXPERT", []() {
  1256. server.sendHeader("Location", String("/"), true);
  1257. gwayConfig.expert = bool(1 - (int) gwayConfig.expert) ;
  1258. server.send ( 302, "text/plain", "");
  1259. });
  1260. // Display the SEEN statistics
  1261. server.on("/SEEN", []() {
  1262. server.sendHeader("Location", String("/"), true);
  1263. #if _DUSB>=1
  1264. Serial.println(F("SEEN button"));
  1265. printSeen(listSeen);
  1266. #endif
  1267. buttonSeen();
  1268. server.send ( 302, "text/plain", "");
  1269. });
  1270. // Update the sketch. Not yet implemented
  1271. server.on("/UPDATE=1", []() {
  1272. #if A_OTA==1
  1273. updateOtaa();
  1274. #endif
  1275. server.sendHeader("Location", String("/"), true);
  1276. server.send ( 302, "text/plain", "");
  1277. });
  1278. // -----------
  1279. // This section from version 4.0.7 defines what PART of the
  1280. // webpage is shown based on the buttons pressed by the user
  1281. // Maybe not all information should be put on the screen since it
  1282. // may take too much time to serve all information before a next
  1283. // package interrupt arrives at the gateway
  1284. Serial.print(F("WWW Server started on port "));
  1285. Serial.println(A_SERVERPORT);
  1286. return;
  1287. } // setupWWW
  1288. // --------------------------------------------------------------------------------
  1289. // WIFI CONFIG
  1290. // wifiConfig() displays the most important Wifi parameters gathered
  1291. //
  1292. // --------------------------------------------------------------------------------
  1293. static void wifiConfig()
  1294. {
  1295. if (gwayConfig.expert) {
  1296. String response="";
  1297. response +="<h2>WiFi Config</h2>";
  1298. response +="<table class=\"config_table\">";
  1299. response +="<tr><th class=\"thead\">Parameter</th><th class=\"thead\">Value</th></tr>";
  1300. response +="<tr><td class=\"cell\">WiFi host</td><td class=\"cell\">";
  1301. #if ESP32_ARCH==1
  1302. response +=WiFi.getHostname(); response+="</tr>";
  1303. #else
  1304. response +=wifi_station_get_hostname(); response+="</tr>";
  1305. #endif
  1306. response +="<tr><td class=\"cell\">WiFi SSID</td><td class=\"cell\">";
  1307. response +=WiFi.SSID(); response+="</tr>";
  1308. response +="<tr><td class=\"cell\">IP Address</td><td class=\"cell\">";
  1309. printIP((IPAddress)WiFi.localIP(),'.',response);
  1310. response +="</tr>";
  1311. response +="<tr><td class=\"cell\">IP Gateway</td><td class=\"cell\">";
  1312. printIP((IPAddress)WiFi.gatewayIP(),'.',response);
  1313. response +="</tr>";
  1314. response +="<tr><td class=\"cell\">NTP Server</td><td class=\"cell\">"; response+=NTP_TIMESERVER; response+="</tr>";
  1315. response +="<tr><td class=\"cell\">LoRa Router</td><td class=\"cell\">"; response+=_TTNSERVER; response+="</tr>";
  1316. response +="<tr><td class=\"cell\">LoRa Router IP</td><td class=\"cell\">";
  1317. printIP((IPAddress)ttnServer,'.',response);
  1318. response +="</tr>";
  1319. #ifdef _THINGSERVER
  1320. response +="<tr><td class=\"cell\">LoRa Router 2</td><td class=\"cell\">"; response+=_THINGSERVER;
  1321. response += String() + ":" + _THINGPORT + "</tr>";
  1322. response +="<tr><td class=\"cell\">LoRa Router 2 IP</td><td class=\"cell\">";
  1323. printIP((IPAddress)thingServer,'.',response);
  1324. response +="</tr>";
  1325. #endif
  1326. response +="</table>";
  1327. server.sendContent(response);
  1328. } // gwayConfig.expert
  1329. } // wifiConfig
  1330. // --------------------------------------------------------------------------------
  1331. // H2 systemStatus
  1332. // systemStatus is additional and only available in the expert mode.
  1333. // It provides a number of system specific data such as heap size etc.
  1334. // --------------------------------------------------------------------------------
  1335. static void systemStatus()
  1336. {
  1337. if (gwayConfig.expert) {
  1338. String response="";
  1339. response +="<h2>System Status</h2>";
  1340. response +="<table class=\"config_table\">";
  1341. response +="<tr>";
  1342. response +="<th class=\"thead\">Parameter</th>";
  1343. response +="<th class=\"thead\">Value</th>";
  1344. response +="<th colspan=\"2\" class=\"thead\">Set</th>";
  1345. response +="</tr>";
  1346. response +="<tr><td style=\"border: 1px solid black; width:120px;\">Gateway ID</td>";
  1347. response +="<td class=\"cell\">";
  1348. if (MAC_array[0]< 0x10) response +='0'; response +=String(MAC_array[0],HEX); // The MAC array is always returned in lowercase
  1349. if (MAC_array[1]< 0x10) response +='0'; response +=String(MAC_array[1],HEX);
  1350. if (MAC_array[2]< 0x10) response +='0'; response +=String(MAC_array[2],HEX);
  1351. response +="FFFF";
  1352. if (MAC_array[3]< 0x10) response +='0'; response +=String(MAC_array[3],HEX);
  1353. if (MAC_array[4]< 0x10) response +='0'; response +=String(MAC_array[4],HEX);
  1354. if (MAC_array[5]< 0x10) response +='0'; response +=String(MAC_array[5],HEX);
  1355. response+="</tr>";
  1356. response +="<tr><td class=\"cell\">Free heap</td><td class=\"cell\">"; response+=ESP.getFreeHeap(); response+="</tr>";
  1357. // XXX We Shoudl find an ESP32 alternative
  1358. #if !defined ESP32_ARCH
  1359. response +="<tr><td class=\"cell\">ESP speed</td><td class=\"cell\">"; response+=ESP.getCpuFreqMHz();
  1360. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"SPEED=80\"><button>80</button></a></td>";
  1361. response +="<td style=\"border: 1px solid black; width:40px;\"><a href=\"SPEED=160\"><button>160</button></a></td>";
  1362. response+="</tr>";
  1363. response +="<tr><td class=\"cell\">ESP Chip ID</td><td class=\"cell\">"; response+=ESP.getChipId(); response+="</tr>";
  1364. #endif
  1365. response +="<tr><td class=\"cell\">OLED</td><td class=\"cell\">"; response+=OLED; response+="</tr>";
  1366. #if _STATISTICS >= 1
  1367. response +="<tr><td class=\"cell\">WiFi Setups</td><td class=\"cell\">"; response+=gwayConfig.wifis; response+="</tr>";
  1368. response +="<tr><td class=\"cell\">WWW Views</td><td class=\"cell\">"; response+=gwayConfig.views; response+="</tr>";
  1369. #endif
  1370. response +="</table>";
  1371. server.sendContent(response);
  1372. } // gwayConfig.expert
  1373. } // systemStatus
  1374. // --------------------------------------------------------------------------------
  1375. // H2 System State and Interrupt
  1376. // Display interrupt data, but only for debug >= 2
  1377. //
  1378. // --------------------------------------------------------------------------------
  1379. static void interruptData()
  1380. {
  1381. if (gwayConfig.expert) {
  1382. uint8_t flags = readRegister(REG_IRQ_FLAGS);
  1383. uint8_t mask = readRegister(REG_IRQ_FLAGS_MASK);
  1384. String response="";
  1385. response +="<h2>System State and Interrupt</h2>";
  1386. response +="<table class=\"config_table\">";
  1387. response +="<tr>";
  1388. response +="<th class=\"thead\">Parameter</th>";
  1389. response +="<th class=\"thead\">Value</th>";
  1390. response +="<th colspan=\"2\" class=\"thead\">Set</th>";
  1391. response +="</tr>";
  1392. response +="<tr><td class=\"cell\">_state</td>";
  1393. response +="<td class=\"cell\">";
  1394. switch (_state) { // See loraModem.h
  1395. case S_INIT: response +="INIT"; break;
  1396. case S_SCAN: response +="SCAN"; break;
  1397. case S_CAD: response +="CAD"; break;
  1398. case S_RX: response +="RX"; break;
  1399. case S_TX: response +="TX"; break;
  1400. default: response +="unknown"; break;
  1401. }
  1402. response +="</td></tr>";
  1403. response +="<tr><td class=\"cell\">_STRICT_1CH</td>";
  1404. response +="<td class=\"cell\">" ;
  1405. response += String() + _STRICT_1CH;
  1406. response +="</td></tr>";
  1407. response +="<tr><td class=\"cell\">flags (8 bits)</td>";
  1408. response +="<td class=\"cell\">0x";
  1409. if (flags <16) response += "0";
  1410. response +=String(flags,HEX); response+="</td></tr>";
  1411. response +="<tr><td class=\"cell\">mask (8 bits)</td>";
  1412. response +="<td class=\"cell\">0x";
  1413. if (mask <16) response += "0";
  1414. response +=String(mask,HEX); response+="</td></tr>";
  1415. response +="<tr><td class=\"cell\">Re-entrant cntr</td>";
  1416. response +="<td class=\"cell\">";
  1417. response += String() + gwayConfig.reents;
  1418. response +="</td></tr>";
  1419. response +="<tr><td class=\"cell\">ntp call cntr</td>";
  1420. response +="<td class=\"cell\">";
  1421. response += String() + gwayConfig.ntps;
  1422. response+="</td></tr>";
  1423. response +="<tr><td class=\"cell\">ntpErr cntr</td>";
  1424. response +="<td class=\"cell\">";
  1425. response += String() + gwayConfig.ntpErr;
  1426. response +="</td>";
  1427. response +="<td colspan=\"2\" style=\"border: 1px solid black;\">";
  1428. stringTime(gwayConfig.ntpErrTime, response);
  1429. response +="</td>";
  1430. response +="</tr>";
  1431. response +="</table>";
  1432. server.sendContent(response);
  1433. }// if gwayConfig.expert
  1434. } // interruptData
  1435. // --------------------------------------------------------------------------------
  1436. // websiteFooter
  1437. //
  1438. // Thi function displays the last messages without header on the webpage and then
  1439. // closes the webpage.
  1440. // --------------------------------------------------------------------------------
  1441. static void websiteFooter()
  1442. {
  1443. // Close the client connection to server
  1444. server.sendContent(String() + "<br><br /><p style='font-size:10px'>Click <a href=\"/HELP\">here</a> to explain Help and REST options</p><br>");
  1445. server.sendContent(String() + "</BODY></HTML>");
  1446. server.sendContent(""); yield();
  1447. }
  1448. #endif // A_SERVER==1