瀏覽代碼

Version 6.1.1.c

platenspeler 5 年之前
父節點
當前提交
5ff10295c9

+ 11 - 3
CHANGELOG.md

@@ -16,10 +16,18 @@ Maintained by Maarten Westenberg (mw12554@hotmail.com)
 
 # Release Notes
 
+Features release 6.1.1 (November 6, 2019)
+- Added "last seen" for a node. Am overview when each known node has last been seen by the gateway,
+	This would mean that a node that does not fit in the regular history overview would still be visible
+	even when it has been seen three days ago.
+- Changed name of the ESP-sc-gway.h file into configGway.h and removed most privacy info. 
+  This way, whis fie does need less editing and allows faster releasing. 
+ - Also moved sensor.h into configNode.h and devided between both configXXX.h file.
+- Added the documentation for release 6.1.1 and correctd a number of typos.
+
 Features release 6.1.0 (October 20, 2019)
 - Changed name of the ESP-sc-gway.h file into configGway.h and removed most privacy info. 
-  This way, whis fie does need less editing 
-and allows faster releasing
+  This way, whis fie does need less editing and allows faster releasing
 - Removed lib from the library directory for libs that are present in the library manager of the node.
 - Changed name of sensor.h file into configNode.h and added all privacy configuration info such as SSID, 
   WiFi password, node data etc.
@@ -29,7 +37,7 @@ So please keep on the line if you do not know your IP.
 - Change the country/region setting of the Gateway (As a result you probably have to update most of 
   the package).
 - Upon connecting over WiFi, display the address for 4 seconds before starting the Gateway function.
-- Made a (not complete) list of lib info in teh README.md document.
+- Made a (not complete) list of lib info in the README.md document.
 - Correct (again) some typos
 
 New features in version 5.3.4 (March 25, 2019)

+ 4 - 4
ESP-sc-gway/ESP-sc-gway.ino

@@ -581,7 +581,7 @@ void setup() {
     // display results of getting hardware address
 	//
 
-    Serial.print("Gateway ID: ");
+    Serial.print(F("Gateway ID: "));
 	printHexDigit(MAC_array[0]);
     printHexDigit(MAC_array[1]);
     printHexDigit(MAC_array[2]);
@@ -591,9 +591,9 @@ void setup() {
     printHexDigit(MAC_array[4]);
     printHexDigit(MAC_array[5]);
 
-    Serial.print(", Listening at SF");
+    Serial.print(F(", Listening at SF"));
 	Serial.print(sf);
-	Serial.print(" on ");
+	Serial.print(F(" on "));
 	Serial.print((double)freqs[ifreq].upFreq/1000000);
 	Serial.println(" MHz.");
 
@@ -692,7 +692,7 @@ void setup() {
 		attachInterrupt(pins.dio1, Interrupt_1, RISING);	// Separate interrupts		
 	}
 	
-	writeConfig( CONFIGFILE, &gwayConfig);					// Write config
+	writeConfig(CONFIGFILE, &gwayConfig);					// Write config
 
 	// activate OLED display
 #if OLED>=1

+ 124 - 2
ESP-sc-gway/_loraFiles.ino

@@ -415,6 +415,128 @@ void printLog()
 } //printLog
 
 
+#if _SEENMAX>0
+
+// ----------------------------------------------------------------------------
+// writeSeen
+// - Once every few messages, update the SPIFFS file and write the array.
+//
+// ----------------------------------------------------------------------------
+int writeSeen(struct nodeSeen *listSeen) {
+
+	return(1);
+}
+
+// ----------------------------------------------------------------------------
+// printSeen
+// - Once every few messages, update the SPIFFS file and write the array.
+// ----------------------------------------------------------------------------
+int printSeen(struct nodeSeen *listSeen) {
+
+#if _DUSB>=1
+	if (( debug>=0 ) && ( pdebug & P_MAIN )) {
+		Serial.print(F("printSeen:: print list"));
+		Serial.println();
+	}
+#endif
+    int i;
+#if _DUSB>=1
+	if (( debug>=0 ) && ( pdebug & P_MAIN )) {
+		for (i=0; i<_SEENMAX; i++) {
+			if (listSeen[i].idSeen != 0) {
+				String response;
+				
+				Serial.print(i);
+				Serial.print(F(", TM="));
+
+				stringTime(listSeen[i].timSeen, response);
+				Serial.print(response);
+								
+				Serial.print(F(", addr=0x"));
+				Serial.print(listSeen[i].idSeen,HEX);
+				Serial.print(F(", SF=0x"));
+				Serial.print(listSeen[i].sfSeen,HEX);
+				Serial.println();
+			}
+		}
+	}
+#endif
+	return(1);
+}
+
+// ----------------------------------------------------------------------------
+// addSeen
+//	With every new message received:
+// - Look whether the message is already in the array, if so update existing 
+//	message. If not, create new record.
+// - With this record, update the SF settings
+// ----------------------------------------------------------------------------
+int addSeen(struct nodeSeen *listSeen, uint32_t idSeen, uint8_t sfSeen, unsigned long timSeen) {
+	int i;
+	
+//	( message[4]<<24 | message[3]<<16 | message[2]<<8 | message[1] )
+	
+#if _DUSB>=1
+	if (( debug>=0 ) && ( pdebug & P_MAIN )) {
+		Serial.print(F("addSeen:: "));
+//		Serial.print(F(" listSeen[0]="));
+//		Serial.print(listSeen[0].idSeen,HEX);
+		Serial.print(F(", tim="));
+		Serial.print(timSeen);
+		Serial.print(F(", idSeen="));
+		Serial.print(idSeen,HEX);
+		Serial.print(F(", sfSeen="));
+		Serial.print(sfSeen,HEX);
+		Serial.println();
+	}
+#endif
+
+	for (i=0; i< _SEENMAX; i++) {
+		if ((listSeen[i].idSeen==idSeen) ||
+			(listSeen[i].idSeen==0))
+		{
+			break;
+		}
+	}
+	
+	if (i>=_SEENMAX) {
+#if _DUSB>=1
+	if (( debug>=0 ) && ( pdebug & P_MAIN )) {
+		Serial.print(F("addSeen:: exit=0, index="));
+		Serial.println(i);
+	}
+#endif
+		return(0);
+	}
+#if _DUSB>=2
+	if (( debug>=0 ) && ( pdebug & P_MAIN )) {
+		Serial.print(F("addSeen:: index="));
+		Serial.print(i);
+	}
+#endif
+	listSeen[i].idSeen = idSeen;
+	listSeen[i].sfSeen |= sfSeen;
+	listSeen[i].timSeen = timSeen;
+	
+	return(1);
+}
+
+// ----------------------------------------------------------------------------
+// initSeen
+// Init the lisrScreen array
+// ----------------------------------------------------------------------------
+int initSeen(struct nodeSeen *listSeen) {
+	int i;
+	for (i=0; i< _SEENMAX; i++) {
+		listSeen[i].idSeen=0;
+		listSeen[i].sfSeen=0;
+		listSeen[i].timSeen=0;
+	}
+	return(1);
+}
+
+
+
 // ----------------------------------------------------------------------------
 // listDir
 //	List the directory and put it in
@@ -422,7 +544,7 @@ void printLog()
 void listDir(char * dir) 
 {
 #if _DUSB>=1
-	
+	// Nothing here
 #endif
 }
-
+#endif //_SEENMAX>0

+ 1 - 0
ESP-sc-gway/_sensor.ino

@@ -533,6 +533,7 @@ int sensorPacket() {
 	// In order to save the memory, we only write the framecounter
 	// to EEPROM every 10 values. It also means that we will invalidate
 	// 10 value when restarting the gateway.
+	// NOTE: This means that preferences are NOT saved unless >=10 messages have been received.
 	//
 	if (( frameCount % 10)==0) writeGwayCfg(CONFIGFILE);
 	

+ 9 - 1
ESP-sc-gway/_txRx.ino

@@ -305,7 +305,7 @@ int buildPacket(uint32_t tmst, uint8_t *buff_up, struct LoraUp LoraUp, bool inte
 	//
 	for (int m=( MAX_STAT -1); m>0; m--) statr[m]=statr[m-1];
 	
-	// From now on we can fill start[0] with sensor data
+	// From now on we can fill statr[0] with sensor data
 #if _LOCALSERVER==1
 	statr[0].datal=0;
 	int index;
@@ -369,6 +369,8 @@ int buildPacket(uint32_t tmst, uint8_t *buff_up, struct LoraUp LoraUp, bool inte
 	}
 #endif // _STATISTICS >= 2
 
+
+
 #if _STATISTICS >= 3
 	if (statr[0].ch == 0) {
 		statc.msg_ttl_0++;
@@ -596,6 +598,12 @@ int buildPacket(uint32_t tmst, uint8_t *buff_up, struct LoraUp LoraUp, bool inte
 
 	addLog( (unsigned char *)(buff_up), buff_index );
 #endif	
+
+// When we have the node address and the SF, fill the array
+// listSeen with the required data. SEENMAX must be >0 for this ro happen.
+#if  _SEENMAX > 0
+	addSeen(listSeen, statr[0].node, statr[0].sf, now());
+#endif
 	
 #if _DUSB>=1
 	if (( debug>=2 ) && ( pdebug & P_RX )) {

+ 78 - 18
ESP-sc-gway/_wwwServer.ino

@@ -194,7 +194,7 @@ void buttonDocu()
 void buttonLog() 
 {
 	
-	String response = "";
+//	String response = "";
 	String fn = "";
 	int i = 0;
 	
@@ -204,28 +204,28 @@ void buttonLog()
 		i++;
 	}
 	
-	server.sendContent(response);
+//	server.sendContent(response);
 }
 
 // --------------------------------------------------------------------------------
-// BUTTONNODE
+// BUTTONSEEN
+// List the listSeen array.
 // Read the logfiles and display info about nodes (last seend, SF used etc).
 // This is a button on the top of the GUI screen
 // --------------------------------------------------------------------------------
-void buttonNode() 
+void buttonSeen() 
 {
 	
-//	String response = "";
 	String fn = "";
 	int i = 0;
 	
-	while (i< LOGFILEMAX ) {
-		fn = "/log-" + String(gwayConfig.logFileNo - i);
-		wwwFile(fn);									// Display the file contents in the browser
-		i++;
+	printSeen(listSeen);
+#if _DUSB>=1
+	if (( debug>=1 ) && ( pdebug & P_MAIN )) {
+		Serial.println(F("buttonSeen:: printSeen called"));
 	}
-	
-//	server.sendContent(response);
+#endif	
+
 }
 
 // --------------------------------------------------------------------------------
@@ -244,7 +244,7 @@ static void wwwButtons()
 	response += "<input type=\"button\" value=\"Documentation\" onclick=\"showDocu()\" >";
 	
 	response += "<a href=\"EXPERT\" download><button type=\"button\">" + mode + "</button></a>";
-	response += "<a href=\"NODE\" download><button type=\"button\">Nodes Seen</button></a>";
+	response += "<a href=\"SEEN\" download><button type=\"button\">Nodes Seen</button></a>";
 	response += "<a href=\"LOG\" download><button type=\"button\">Log Files</button></a>";
 
 	server.sendContent(response);							// Send to the screen
@@ -873,6 +873,65 @@ static void messageHistory()
 #endif
 }
 
+// --------------------------------------------------------------------------------
+// H2 NODE SEEN HISTORY
+// If enabled, display the sensor last Seen history.
+// This setting ,pves togetjer with the "expert" mode.
+//  If that mode is enabled than the node seen intory is displayed
+//
+// Parameters:
+//	- <none>
+// Returns:
+//	- <none>
+// --------------------------------------------------------------------------------
+static void nodeHistory() 
+{
+#if _SEENMAX > 0
+	if (gwayConfig.expert) {
+		// First draw the headers
+		String response="";
+	
+		response += "<h2>Node Last Seen History</h2>";
+		response += "<table class=\"config_table\">";
+		response += "<tr>";
+		response += "<th class=\"thead\" style=\"width: 220px;\">Time</th>";
+		response += "<th class=\"thead\">Node</th>";
+//#if _LOCALSERVER==1
+//		response += "<th class=\"thead\">Data</th>";
+//#endif
+		response += "<th class=\"thead\" style=\"width: 20px;\">C</th>";
+		response += "<th class=\"thead\" style=\"width: 40px;\">SF</th>";
+
+		response += "</tr>";
+		server.sendContent(response);
+		
+		// Now start the contents
+		
+		int i;
+		for (i=0; i<_SEENMAX; i++) {
+			if (listSeen[i].idSeen == 0) break;
+			response = "";
+		
+			response += String() + "<tr><td class=\"cell\">";					// Tmst
+			stringTime((listSeen[i].timSeen), response);
+			response += "</td>";
+		
+			response += String() + "<td class=\"cell\">"; 						// Node
+			if (SerialName((char *)(& (listSeen[i].idSeen)), response) < 0) {	// works with TRUSTED_NODES >= 1
+				printHEX((char *)(& (listSeen[i].idSeen)),' ',response);		// else
+			}
+			response += "</td>";
+
+			response += String() + "<td class=\"cell\">" + 0 + "</td>";			// Channel
+			
+			response += String() + "<td class=\"cell\">" + listSeen[i].sfSeen + "</td>";
+			
+			server.sendContent(response);
+		}
+		server.sendContent("</table>");
+	}
+#endif
+}
 
 // --------------------------------------------------------------------------------
 // SEND WEB PAGE() 
@@ -893,6 +952,7 @@ void sendWebPage(const char *cmd, const char *arg)
 
 	statisticsData(); yield();		 			// Node statistics
 	messageHistory(); yield();					// Display the sensor history, message statistics
+	nodeHistory(); yield();						// Display the lastSeen array
 
 	gatewaySettings(); yield();					// Display web configuration
 	wifiConfig(); yield();						// WiFi specific parameters
@@ -1237,7 +1297,7 @@ void setupWWW()
 	// Display LOGging information
 	server.on("/LOG", []() {
 		server.sendHeader("Location", String("/"), true);
-#if _DUSB>=1
+#if _DUSB>=2
 		Serial.println(F("LOG button"));
 #endif
 		buttonLog();
@@ -1251,13 +1311,13 @@ void setupWWW()
 		server.send ( 302, "text/plain", "");
 	});
 	
-	// Display the NODE statistics
-	server.on("/NODE", []() {
+	// Display the SEEN statistics
+	server.on("/SEEN", []() {
 		server.sendHeader("Location", String("/"), true);
-#if _DUSB>=1
-		Serial.println(F("NODE button"));
+#if _DUSB>=2
+		Serial.println(F("SEEN button"));
 #endif
-		buttonNode();
+		buttonSeen();
 		server.send ( 302, "text/plain", "");
 	});
 

+ 14 - 6
ESP-sc-gway/configGway.h

@@ -28,7 +28,7 @@
 // really matter.
 // ----------------------------------------------------------------------------------------
 
-#define VERSION "V.6.1.1.E.EU868; 191106a"
+#define VERSION "V.6.1.1.E.EU868; 191106c"
 
 // This value of DEBUG determines whether some parts of code get compiled.
 // Also this is the initial value of debug parameter. 
@@ -182,13 +182,21 @@
 #define GATEWAYMGT 0
 
 
-// Do extensive loggin
+// Do extensive logging
 // Use the ESP8266 SPIFS filesystem to do extensive logging.
 // We must take care that the filesystem never(!) is full, and for that purpose we
 // rather have new records/line of statistics than very old.
 // Of course we must store enough records to make the filesystem work
 #define STAT_LOG 1
 
+// We will log a list of LoRa nodes that was forwarded using this gateway.
+// For eacht node we record:
+//	- node Number, or known node name
+//	- Last seen 'seconds since 1/1/1970'
+//	- SF seen (8-bit integer with SF per bit)
+// The initial version _NUMMAX stores max so many nodes:
+#define _SEENMAX 100
+#define _SEENFILE "/gwayNum.txt"
 
 // Name of he configfile in SPIFFs	filesystem
 // In this file we store the configuration and other relevant info that should
@@ -218,7 +226,7 @@
 // Port is UDP port in this program
 //
 // Default for testing: Switched off
-#define _THINGSERVER "your.domain.org"		// Server URL of the LoRa-udp.js handler
+#define _THINGSERVER "your,webserver.com"		// Server URL of the LoRa-udp.js handler
 #define _THINGPORT 1700						// Port 1700 is old compatibility
 
 
@@ -231,7 +239,7 @@
 
 // Gateway Ident definitions
 #define _DESCRIPTION "ESP Gateway"			// Name of the gateway
-#define _EMAIL "your@email.com"				// Owner
+#define _EMAIL "your@mail.com"				// Owner
 #define _PLATFORM "ESP8266"
 #define _LAT 52.0
 #define _LON 5.0
@@ -240,7 +248,7 @@
 // ntp
 // Please add daylight saving time to NTP_TIMEZONES when desired
 #define NTP_TIMESERVER "nl.pool.ntp.org"	// Country and region specific
-#define NTP_TIMEZONES	2					// How far is our Timezone from UTC (excl daylight saving/summer time)
+#define NTP_TIMEZONES	1					// How far is our Timezone from UTC (excl daylight saving/summer time)
 #define SECS_IN_HOUR	3600
 #define NTP_INTR 0							// Do NTP processing with interrupts or in loop();
 
@@ -275,7 +283,7 @@
 //		forwarded or counted! (not yet fully implemented)
 #define _TRUSTED_NODES 1
 #define _TRUSTED_DECODE 1
-// See configNode.h for more info
+
 
 
 

+ 22 - 1
ESP-sc-gway/loraFiles.h

@@ -45,6 +45,7 @@
 #define P_GUI		0x40
 #define P_RADIO		0x80
 
+
 // Definition of the configuration record that is read at startup and written
 // when settings are changed.
 
@@ -90,4 +91,24 @@ struct espGwayConfig {
 #define LOGFILEMAX 10
 #define LOGFILEREC 100
 
-#endif
+#endif // STAT_LOG
+
+// Define the node list structure
+//
+#define nSF6	0x01
+#define nSF7	0x02
+#define nSF8	0x04
+#define nSF9	0x08
+#define nSF10	0x10
+#define nSF11	0x20
+#define nSF12	0x40
+#define nFSK	0x80
+
+struct nodeSeen {
+	uint32_t idSeen;
+	uint8_t sfSeen;
+	unsigned long timSeen;
+};
+struct nodeSeen listSeen[_SEENMAX];
+
+

+ 1 - 1
ESP-sc-gway/loraModem.h

@@ -350,7 +350,7 @@ struct stat_c statc;
 
 
 
-// History of received uplink messages from nodes
+// History of received uplink and downlink messages from nodes
 struct stat_t statr[MAX_STAT];