Browse Source

Version 6.1.1C

platenspeler 5 years ago
parent
commit
cd63851267

+ 5 - 2
ESP-sc-gway/ESP-sc-gway.ino

@@ -322,7 +322,7 @@ int sendNtpRequest(IPAddress timeServerIP) {
 	const int NTP_PACKET_SIZE = 48;							// Fixed size of NTP record
 	byte packetBuffer[NTP_PACKET_SIZE];
 
-	memset(packetBuffer, 0, NTP_PACKET_SIZE);				// Zeroise the buffer.
+	memset(packetBuffer, 0, NTP_PACKET_SIZE);				// Zero the buffer.
 	
 	packetBuffer[0]  = 0b11100011;   						// LI, Version, Mode
 	packetBuffer[1]  = 0;									// Stratum, or type of clock
@@ -470,10 +470,13 @@ void setup() {
 	SPIFFS.format();										// Normally disabled. Enable only when SPIFFS corrupt
 #if _DUSB>=1
 	if (( debug >= 0 ) && ( pdebug & P_MAIN )) {
-		Serial.println(F("Done"));
+		Serial.println(F("Format Done"));
 	}
 #endif
 #endif
+	delay(500);
+	// Read the config file for all parameters not set in the setup() or configGway.h file
+	readConfig(CONFIGFILE, &gwayConfig);
 
 	Serial.print(F("Assert="));
 #if defined CFG_noassert

+ 1 - 1
ESP-sc-gway/_WiFi.ino

@@ -130,7 +130,7 @@ int WlanStatus() {
 // ----------------------------------------------------------------------------
 int WlanReadWpa() {
 	
-	readConfig( CONFIGFILE, &gwayConfig);
+	readConfig(CONFIGFILE, &gwayConfig);
 
 	if (gwayConfig.sf != (uint8_t) 0) sf = (sf_t) gwayConfig.sf;
 	ifreq = gwayConfig.ch;

+ 29 - 10
ESP-sc-gway/_loraFiles.ino

@@ -50,6 +50,7 @@ int initConfig(struct espGwayConfig *c) {
 	(*c).cad = _CAD;
 	(*c).hop = false;
 	(*c).expert = false;
+	(*c).txDelay = 0;					// First Value without saving is 0;
 }
 
 
@@ -64,8 +65,7 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 #endif
 	if (!SPIFFS.exists(fn)) {
 #if _DUSB>=1
-		if (( debug>=0 ) && ( pdebug & P_MAIN ))
-		Serial.print(F("M ERR:: readConfig, file="));
+		Serial.print(F("readConfig ERR:: file="));
 		Serial.print(fn);
 		Serial.println(F(" does not exist .. Formatting"));
 #endif
@@ -76,7 +76,9 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 
 	File f = SPIFFS.open(fn, "r");
 	if (!f) {
+#if _DUSB>=1
 		Serial.println(F("ERROR:: SPIFFS open failed"));
+#endif
 		return(-1);
 	}
 
@@ -101,10 +103,18 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 			f = SPIFFS.open(fn, "r");
 			tries = 0;
 		}
-		
-		String id =f.readStringUntil('=');						// C++ thing
-		String val=f.readStringUntil('\n');
-		
+
+		String id =f.readStringUntil('=');						// Read keyword until '=', C++ thing
+		String val=f.readStringUntil('\n');						// Read value until End of Line (EOL)
+
+#if _DUSB>=1
+		Serial.print(F("readConfig:: reading line="));
+		Serial.print(id);
+		Serial.print(F("="));
+		Serial.print(val);
+		Serial.println();
+#endif	
+
 		if (id == "SSID") {										// WiFi SSID
 			id_print(id, val);
 			(*c).ssid = val;									// val contains ssid, we do NO check
@@ -181,7 +191,7 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 			id_print(id, val);
 			(*c).ntps = (uint8_t) val.toInt();
 		}
-		else if (id == "FILENO") {								// log FILENO setting
+		else if (id == "FILENO") {								// FILENO setting
 			id_print(id, val);
 			(*c).logFileNo = (uint8_t) val.toInt();
 		}
@@ -193,23 +203,31 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 			id_print(id, val);
 			(*c).logFileNum = (uint16_t) val.toInt();
 		}
-		else if (id == "EXPERT") {								// FILEREC setting
+		else if (id == "EXPERT") {								// EXPERT setting
 			id_print(id, val);
 			(*c).expert = (uint8_t) val.toInt();
 		}
+		else if (id == "DELAY") {								// DELAY setting
+			id_print(id, val);
+			(*c).txDelay = (int32_t) val.toInt();
+		}
 		else {
+#if _DUSB>=1
+			Serial.print(F("readConfig:: tries++"));
+#endif
 			tries++;
 		}
 	}
 	f.close();
 #if _DUSB>=1
 	if (debug>=0) {
-		Serial.println('#');
+		Serial.println(F("readConfig:: Fini"));
 	}
 #endif
 	Serial.println();
 	return(1);
-}
+}//readConfig
+
 
 // ----------------------------------------------------------------------------
 // Write the current gateway configuration to SPIFFS. First copy all the
@@ -280,6 +298,7 @@ int writeConfig(const char *fn, struct espGwayConfig *c) {
 	f.print("FILENO");  f.print('='); f.print((*c).logFileNo); f.print('\n');
 	f.print("FILENUM");  f.print('='); f.print((*c).logFileNum); f.print('\n');
 	f.print("EXPERT");  f.print('='); f.print((*c).expert); f.print('\n');
+	f.print("DELAY");  f.print('='); f.print((*c).txDelay); f.print('\n');
 	
 	f.close();
 	return(1);

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

@@ -65,7 +65,7 @@ int sendPacket(uint8_t *buf, uint8_t length)
 	buf[length] = 0;
 	
 #if _DUSB>=1
-	if (debug>=2) {
+	if (( debug>=2) && (pdebug & P_TX)) {
 		Serial.println((char *)buf);
 		Serial.print(F("<"));
 		Serial.flush();
@@ -94,7 +94,7 @@ int sendPacket(uint8_t *buf, uint8_t length)
 	// {"txpk":{"codr":"4/5","data":"YCkEAgIABQABGmIwYX/kSn4Y","freq":868.1,"ipol":true,"modu":"LORA","powe":14,"rfch":0,"size":18,"tmst":1890991792,"datr":"SF7BW125"}}
 
 	// Used in the protocol of Gateway:
-	JsonObject root		= jsonBuffer.to<JsonObject>();
+	JsonObject root		= jsonBuffer.as<JsonObject>();	// 191111 Avoid Crashes
 	
 	const char * data	= root["txpk"]["data"];			// Downstream Payload
 	uint8_t psize		= root["txpk"]["size"];			// Payload size
@@ -142,7 +142,7 @@ int sendPacket(uint8_t *buf, uint8_t length)
 // _STRICT_1CH determines how we will react on downstream messages.
 //
 // If STRICT==1, we will answer (in the RX1 timeslot) on the frequency we receive on.
-// This way, we can bettrer communicate as a single gateway machine
+// This way, we can better communicate as a single gateway machine
 //
 #if _STRICT_1CH == 1
 	// RX1 is requested frequency
@@ -167,7 +167,7 @@ int sendPacket(uint8_t *buf, uint8_t length)
 // And since the Gateway is a single channel gateway, and its nodes are probably
 // single channel too. They will not listen to that frequency at all.
 // Pleae note that this parameter is more for nodes (that cannot change freqs)
- than for gateways.
+// than for gateways.
 //
 	LoraDown.powe = powe;
 

+ 61 - 38
ESP-sc-gway/_wwwServer.ino

@@ -516,13 +516,24 @@ static void gatewaySettings()
 	// Debugging options, only when _DUSB is set, otherwise no
 	// serial activity
 #if _DUSB>=1	
-	response +="<tr><td class=\"cell\">Debug level</td><td class=\"cell\" colspan=\"2\">"; 
+	response +="<tr><td class=\"cell\">Debug Level</td><td class=\"cell\" colspan=\"2\">"; 
 	response +=debug; 
 	response +="</td>";
 	response +="<td class=\"cell\"><a href=\"DEBUG=-1\"><button>-</button></a></td>";
 	response +="<td class=\"cell\"><a href=\"DEBUG=1\"><button>+</button></a></td>";
 	response +="</tr>";
+
+	// Time Correction
+	if (gwayConfig.expert) {
+		response +="<tr><td class=\"cell\">Time Correction (uSec)</td><td class=\"cell\" colspan=\"2\">"; 
+		response += txDelay; 
+		response +="</td>";
+		response +="<td class=\"cell\"><a href=\"DELAY=-1\"><button>-</button></a></td>";
+		response +="<td class=\"cell\"><a href=\"DELAY=1\"><button>+</button></a></td>";
+		response +="</tr>";
+	}
 	
+	// Debug Pattern
 	response +="<tr><td class=\"cell\">Debug pattern</td>"; 
 	
 	bg = ( (pdebug & P_SCAN) ? "LightGreen" : "orange" ); 
@@ -577,7 +588,7 @@ static void gatewaySettings()
 	response +="<button>RDIO</button></a></td>";
 	response +="</tr>";
 #endif
-	// Serial Debugging
+	// USB Debug, Serial Debugging
 	response +="<tr><td class=\"cell\">Usb Debug</td><td class=\"cell\" colspan=\"2\">"; 
 	response += _DUSB; 
 	response +="</td>";
@@ -603,6 +614,7 @@ static void gatewaySettings()
 	response +="</tr>";
 #endif
 
+	/// WWW Refresh
 #if A_REFRESH==1
 	bg = " background-color: ";
 	bg += ( (gwayConfig.refresh == 1) ? "LightGreen" : "orange" );
@@ -1062,7 +1074,6 @@ void setupWWW()
 
 	// Reset the boot counter
 	server.on("/BOOT", []() {
-		Serial.println(F("BOOT"));
 #if _STATISTICS >= 2
 		gwayConfig.boots = 0;
 		gwayConfig.wifis = 0;
@@ -1074,6 +1085,9 @@ void setupWWW()
 		gwayConfig.reents = 0;					// Re-entrance
 
 		writeGwayCfg(CONFIGFILE);
+#if _DUSB>=1
+		Serial.println(F("BOOT, config written"));
+#endif
 		server.sendHeader("Location", String("/"), true);
 		server.send ( 302, "text/plain", "");
 	});
@@ -1088,19 +1102,25 @@ void setupWWW()
 	server.on("/DEBUG=-1", []() {				// Set debug level 0-2						
 		debug = (debug+3)%4;
 		writeGwayCfg(CONFIGFILE);				// Save configuration to file
+#if _DUSB>=1
+		Serial.println(F("DEBUG -1: config written"));
+#endif
 		server.sendHeader("Location", String("/"), true);
 		server.send ( 302, "text/plain", "");
 	});
 	server.on("/DEBUG=1", []() {
 		debug = (debug+1)%4;
 		writeGwayCfg(CONFIGFILE);				// Save configuration to file
+#if _DUSB>=1
+		Serial.println(F("DEBUG +1: config written"));
+#endif
 		server.sendHeader("Location", String("/"), true);
 		server.send ( 302, "text/plain", "");
 	});
 
 	// Set PDEBUG parameter
 	//
-		server.on("/PDEBUG=SCAN", []() {		// Set debug level 0-2						
+	server.on("/PDEBUG=SCAN", []() {		// Set debug level 0-2						
 		pdebug ^= P_SCAN;
 		writeGwayCfg(CONFIGFILE);				// Save configuration to file
 		server.sendHeader("Location", String("/"), true);
@@ -1153,11 +1173,19 @@ void setupWWW()
 	// Set delay in microseconds
 	server.on("/DELAY=1", []() {
 		txDelay+=5000;
+		writeGwayCfg(CONFIGFILE);				// Save configuration to file
+#if _DUSB>=1
+		Serial.println(F("DELAY +, config written"));
+#endif
 		server.sendHeader("Location", String("/"), true);
 		server.send ( 302, "text/plain", "");
 	});
 	server.on("/DELAY=-1", []() {
 		txDelay-=5000;
+		writeGwayCfg(CONFIGFILE);				// Save configuration to file
+#if _DUSB>=1
+		Serial.println(F("DELAY +, config written"));
+#endif
 		server.sendHeader("Location", String("/"), true);
 		server.send ( 302, "text/plain", "");
 	});
@@ -1353,44 +1381,46 @@ void setupWWW()
 static void wifiConfig()
 {
 	if (gwayConfig.expert) {
-	String response="";
-	response +="<h2>WiFi Config</h2>";
+		String response="";
+		response +="<h2>WiFi Config</h2>";
 
-	response +="<table class=\"config_table\">";
+		response +="<table class=\"config_table\">";
 
-	response +="<tr><th class=\"thead\">Parameter</th><th class=\"thead\">Value</th></tr>";
+		response +="<tr><th class=\"thead\">Parameter</th><th class=\"thead\">Value</th></tr>";
 	
-	response +="<tr><td class=\"cell\">WiFi host</td><td class=\"cell\">"; 
+		response +="<tr><td class=\"cell\">WiFi host</td><td class=\"cell\">"; 
 #if ESP32_ARCH==1
-	response +=WiFi.getHostname(); response+="</tr>";
+		response +=WiFi.getHostname(); response+="</tr>";
 #else
-	response +=wifi_station_get_hostname(); response+="</tr>";
+		response +=wifi_station_get_hostname(); response+="</tr>";
 #endif
 
-	response +="<tr><td class=\"cell\">WiFi SSID</td><td class=\"cell\">"; 
-	response +=WiFi.SSID(); response+="</tr>";
+		response +="<tr><td class=\"cell\">WiFi SSID</td><td class=\"cell\">"; 
+		response +=WiFi.SSID(); response+="</tr>";
 	
-	response +="<tr><td class=\"cell\">IP Address</td><td class=\"cell\">"; 
-	printIP((IPAddress)WiFi.localIP(),'.',response); 
-	response +="</tr>";
-	response +="<tr><td class=\"cell\">IP Gateway</td><td class=\"cell\">"; 
-	printIP((IPAddress)WiFi.gatewayIP(),'.',response); 
-	response +="</tr>";
-	response +="<tr><td class=\"cell\">NTP Server</td><td class=\"cell\">"; response+=NTP_TIMESERVER; response+="</tr>";
-	response +="<tr><td class=\"cell\">LoRa Router</td><td class=\"cell\">"; response+=_TTNSERVER; response+="</tr>";
-	response +="<tr><td class=\"cell\">LoRa Router IP</td><td class=\"cell\">"; 
-	printIP((IPAddress)ttnServer,'.',response); 
-	response +="</tr>";
+		response +="<tr><td class=\"cell\">IP Address</td><td class=\"cell\">"; 
+		printIP((IPAddress)WiFi.localIP(),'.',response); 
+		response +="</tr>";
+		response +="<tr><td class=\"cell\">IP Gateway</td><td class=\"cell\">"; 
+		printIP((IPAddress)WiFi.gatewayIP(),'.',response); 
+		response +="</tr>";
+		response +="<tr><td class=\"cell\">NTP Server</td><td class=\"cell\">"; response+=NTP_TIMESERVER; response+="</tr>";
+		response +="<tr><td class=\"cell\">LoRa Router</td><td class=\"cell\">"; response+=_TTNSERVER; response+="</tr>";
+		response +="<tr><td class=\"cell\">LoRa Router IP</td><td class=\"cell\">"; 
+		printIP((IPAddress)ttnServer,'.',response); 
+		response +="</tr>";
 #ifdef _THINGSERVER
-	response +="<tr><td class=\"cell\">LoRa Router 2</td><td class=\"cell\">"; response+=_THINGSERVER; 
-	response += String() + ":" + _THINGPORT + "</tr>";
-	response +="<tr><td class=\"cell\">LoRa Router 2 IP</td><td class=\"cell\">"; 
-	printIP((IPAddress)thingServer,'.',response);
-	response +="</tr>";
+		response +="<tr><td class=\"cell\">LoRa Router 2</td><td class=\"cell\">"; response+=_THINGSERVER; 
+		response += String() + ":" + _THINGPORT + "</tr>";
+		response +="<tr><td class=\"cell\">LoRa Router 2 IP</td><td class=\"cell\">"; 
+		printIP((IPAddress)thingServer,'.',response);
+		response +="</tr>";
 #endif
-	response +="</table>";
 
-	server.sendContent(response);
+
+		response +="</table>";
+
+		server.sendContent(response);
 	} // gwayConfig.expert
 } // wifiConfig
 
@@ -1515,13 +1545,6 @@ static void interruptData()
 		response +="</td>";
 		response +="</tr>";
 		
-		response +="<tr><td class=\"cell\">Time Correction (uSec)</td><td class=\"cell\">"; 
-		response += txDelay; 
-		response +="</td>";
-		response +="<td class=\"cell\"><a href=\"DELAY=-1\"><button>-</button></a></td>";
-		response +="<td class=\"cell\"><a href=\"DELAY=1\"><button>+</button></a></td>";
-		response +="</tr>";
-		
 		response +="</table>";
 		
 		server.sendContent(response);

+ 2 - 2
ESP-sc-gway/configGway.h

@@ -1,7 +1,7 @@
 // 1-channel LoRa Gateway for ESP8266
 // Copyright (c) 2016, 2017, 2018, 2019 Maarten Westenberg version for ESP8266
 // Version 6.1.1 E EU868
-// Date: 2019-11-06
+// Date: 2019-11-11
 //
 // Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway and many others.
 // Contibutions of Dorijan Morelj and Andreas Spies for OLED support.
@@ -28,7 +28,7 @@
 // really matter.
 // ----------------------------------------------------------------------------------------
 
-#define VERSION "V.6.1.1.E.EU868; 191106c"
+#define VERSION "V.6.1.1.E.EU868; 191111a"
 
 // This value of DEBUG determines whether some parts of code get compiled.
 // Also this is the initial value of debug parameter. 

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

@@ -59,6 +59,7 @@ struct espGwayConfig {
 	uint16_t ntpErr;			// Number of UTP requests that failed
 	uint16_t ntps;
 
+	int32_t txDelay;			// Init 0 at setup
 	uint32_t ntpErrTime;		// Record the time of the last NTP error
 	uint8_t ch;					// index to freqs array, freqs[ifreq]=868100000 default
 	uint8_t sf;					// range from SF7 to SF12

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

@@ -52,7 +52,7 @@
 
 
 // Our code should correct the server Tramission delay settings
-long txDelay= 0x00;								// tx delay time on top of server TMST
+int32_t txDelay= 0x00;								// tx delay time on top of server TMST
 
 // SPI setting. 8MHz seems to be the max
 #define SPISPEED 8000000						// Set to 8 * 10E6

+ 2 - 2
ESP-sc-gway/oLED.h

@@ -31,7 +31,7 @@
 
 #if OLED>=1										// If OLED is used
 
-// --------------------------------------------------------	
+// ----------------------------------------------------------------------------------------
 // Define the different PIN's used for SCL/SDA for each arch.
 //
 #if _PIN_OUT==1									// HALLARD
@@ -55,7 +55,7 @@
 #endif
 
 
-// --------------------------------------------------------	
+// ----------------------------------------------------------------------------------------
 // Define the different OLED versions
 //
 #if OLED==1