Parcourir la source

Version 6.1.1 with txDelay and expert settings in file

platenspeler il y a 5 ans
Parent
commit
48aeffca07

+ 7 - 3
ESP-sc-gway/ESP-sc-gway.ino

@@ -223,9 +223,9 @@ void SerialStat(uint8_t intr);								// _utils.ino
 void printHexDigit(uint8_t digit);							// _utils.ino
 int inDecodes(char * id);									// _utils.ino
 
-void init_oLED();											// oLED.ino
-void acti_oLED();											// oLED.ino
-void addr_oLED();											// oLED.ino
+void init_oLED();											// _oLED.ino
+void acti_oLED();											// _oLED.ino
+void addr_oLED();											// _oLED.ino
 
 void setupOta(char *hostname);								// _otaServer.ino
 
@@ -475,7 +475,11 @@ void setup() {
 #endif
 #endif
 	delay(500);
+	
 	// Read the config file for all parameters not set in the setup() or configGway.h file
+	// This file should be read just after SPIFFS is initializen and before
+	// other configuration parameters are used.
+	//
 	readConfig(CONFIGFILE, &gwayConfig);
 
 	Serial.print(F("Assert="));

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

@@ -58,7 +58,7 @@ int initConfig(struct espGwayConfig *c) {
 // Read the gateway configuration file
 // ----------------------------------------------------------------------------
 int readConfig(const char *fn, struct espGwayConfig *c) {
-
+	
 	int tries = 0;
 #if _DUSB>=1
 	Serial.println(F("readConfig:: Starting "));
@@ -70,7 +70,7 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 		Serial.println(F(" does not exist .. Formatting"));
 #endif
 		SPIFFS.format();
-		initConfig(c);
+		initConfig(c);					// If we cannot read teh config, at least init known values
 		return(-1);
 	}
 
@@ -233,6 +233,8 @@ int readConfig(const char *fn, struct espGwayConfig *c) {
 // Write the current gateway configuration to SPIFFS. First copy all the
 // separate data items to the gwayConfig structure
 //
+// 	Note: gwayConfig.expert contains the expert setting already
+//				gwayConfig.txDelay
 // ----------------------------------------------------------------------------
 int writeGwayCfg(const char *fn) {
 
@@ -244,6 +246,7 @@ int writeGwayCfg(const char *fn) {
 	gwayConfig.pdebug = pdebug;
 	gwayConfig.cad = _cad;
 	gwayConfig.hop = _hop;
+
 #if GATEWAYNODE==1
 	gwayConfig.fcnt = frameCount;
 #endif
@@ -297,8 +300,8 @@ int writeConfig(const char *fn, struct espGwayConfig *c) {
 	f.print("FILEREC");  f.print('='); f.print((*c).logFileRec); f.print('\n');
 	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.print("EXPERT");  f.print('='); f.print((*c).expert); f.print('\n');
 	
 	f.close();
 	return(1);
@@ -317,7 +320,7 @@ int writeConfig(const char *fn, struct espGwayConfig *c) {
 // Returns:
 //		<none>
 // ----------------------------------------------------------------------------
-void addLog(const unsigned char * line, int cnt) 
+int addLog(const unsigned char * line, int cnt) 
 {
 #if STAT_LOG==1
 	char fn[16];
@@ -368,7 +371,7 @@ void addLog(const unsigned char * line, int cnt)
 			Serial.println(fn);
 		}
 #endif
-		return;									// If file open failed, return
+		return(0);								// If file open failed, return
 	}
 	
 	int i;
@@ -396,11 +399,12 @@ void addLog(const unsigned char * line, int cnt)
 	//	f.print(line[i],HEX);
 		f.print('*');
 	}
-	f.write(&(line[i]), cnt-12);				// write/append the line to the file
+	f.write(&(line[i]), cnt-12);			// write/append the line to the file
 	f.print('\n');
 	f.close();								// Close the file after appending to it
 
 #endif //STAT_LOG
+	return(1);
 }
 
 // ----------------------------------------------------------------------------

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

@@ -668,7 +668,7 @@ void loraWait(const uint32_t timestamp)
 #endif
 		break;
 	}
-	tmst = tmst + txDelay + adjust;						// tmst based on txDelay and spreading factor
+	tmst = tmst + gwayConfig.txDelay + adjust;			// tmst based on txDelay and spreading factor
 	uint32_t waitTime = tmst - micros();				// Or make waitTime an unsigned and change next statement
 	if (micros()>tmst) {								// to (waitTime<0)
 		Serial.println(F("loraWait:: Error wait time < 0"));
@@ -700,7 +700,7 @@ void loraWait(const uint32_t timestamp)
 		Serial.print(F(", waited: "));
 		Serial.print(tmst - startMics);
 		Serial.print(F(", delay="));
-		Serial.print(txDelay);
+		Serial.print(gwayConfig.txDelay);
 		Serial.println();
 		if (debug>=2) Serial.flush();
 	}

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

@@ -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
-// Date: 2019-11-06	
+// Date: 2019-11-12	
 //
 //
 // All rights reserved. This program and the accompanying materials
@@ -35,7 +35,7 @@ void setupOta(char *hostname) {
 #if _DUSB>=1
 	Serial.println(F("setupOta:: Started"));
 #endif	
-	// Hostname defaults to esp8266-[ChipID]
+	// Hostname defaults to esp8266-[ChipID] for ESP8266 nodes
 	ArduinoOTA.setHostname(hostname);
 	
 	ArduinoOTA.onStart([]() {
@@ -111,10 +111,11 @@ void setupOta(char *hostname) {
 void updateOtaa() {
 
 	String response="";
+	Serial.print(F("updateOtaa:: <unimplemented> IP="));
 	printIP((IPAddress)WiFi.localIP(),'.',response);
+	Serial.println(response);
 	
-	ESPhttpUpdate.update(response, 80, "/arduino.bin");
-
+//	ESPhttpUpdate.update(response, 80, "/arduino.bin");
 }
 
 

+ 19 - 5
ESP-sc-gway/_wwwServer.ino

@@ -252,7 +252,7 @@ static void wwwButtons()
 
 
 // --------------------------------------------------------------------------------
-// SET ESP8266 WEB SERVER VARIABLES
+// SET ESP8266/ESP32 WEB SERVER VARIABLES
 //
 // This funtion implements the WiFi Webserver (very simple one). The purpose
 // of this server is to receive simple admin commands, and execute these
@@ -297,10 +297,12 @@ static void setVariables(const char *cmd, const char *arg) {
 	}
 	
 	if (strcmp(cmd, "DELAY")==0) {									// Set delay usecs
-		txDelay+=atoi(arg)*1000;
+		gwayConfig.txDelay+=atoi(arg)*1000;
+		writeGwayCfg(CONFIGFILE);									// Save configuration to file
 	}
 	
 	// SF; Handle Spreading Factor Settings
+	//
 	if (strcmp(cmd, "SF")==0) {
 		uint8_t sfi = sf;
 		if (atoi(arg) == 1) {
@@ -314,6 +316,7 @@ static void setVariables(const char *cmd, const char *arg) {
 	}
 	
 	// FREQ; Handle Frequency  Settings
+	//
 	if (strcmp(cmd, "FREQ")==0) {
 		uint8_t nf = sizeof(freqs)/ sizeof(freqs[0]);				// Number of frequency elements in array
 		
@@ -331,17 +334,24 @@ static void setVariables(const char *cmd, const char *arg) {
 	}
 
 	//if (strcmp(cmd, "GETTIME")==0) { Serial.println(F("gettime tbd")); }	// Get the local time
+	//
 	
 	//if (strcmp(cmd, "SETTIME")==0) { Serial.println(F("settime tbd")); }	// Set the local time
+	//
 	
+	// Help
+	//
 	if (strcmp(cmd, "HELP")==0)    { Serial.println(F("Display Help Topics")); }
 	
+	// Node
+	//
 #if GATEWAYNODE==1
 	if (strcmp(cmd, "NODE")==0) {									// Set node on=1 or off=0
 		gwayConfig.isNode =(bool)atoi(arg);
 		writeGwayCfg(CONFIGFILE);									// Save configuration to file
 	}
 	
+	// File Counter//
 	if (strcmp(cmd, "FCNT")==0)   { 
 		frameCount=0; 
 		rxLoraModem();												// Reset the radio with the new frequency
@@ -349,6 +359,8 @@ static void setVariables(const char *cmd, const char *arg) {
 	}
 #endif
 	
+	// WiFi Manager
+	//
 #if _WIFIMANAGER==1
 	if (strcmp(cmd, "NEWSSID")==0) { 
 		WiFiManager wifiManager;
@@ -359,10 +371,12 @@ static void setVariables(const char *cmd, const char *arg) {
 	}
 #endif
 
+	// Update the software (from User Interface)
 #if A_OTA==1
 	if (strcmp(cmd, "UPDATE")==0) {
 		if (atoi(arg) == 1) {
 			updateOtaa();
+			writeGwayCfg(CONFIGFILE);
 		}
 	}
 #endif
@@ -526,7 +540,7 @@ static void gatewaySettings()
 	// Time Correction
 	if (gwayConfig.expert) {
 		response +="<tr><td class=\"cell\">Time Correction (uSec)</td><td class=\"cell\" colspan=\"2\">"; 
-		response += txDelay; 
+		response += gwayConfig.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>";
@@ -1172,7 +1186,7 @@ void setupWWW()
 	
 	// Set delay in microseconds
 	server.on("/DELAY=1", []() {
-		txDelay+=5000;
+		gwayConfig.txDelay+=5000;
 		writeGwayCfg(CONFIGFILE);				// Save configuration to file
 #if _DUSB>=1
 		Serial.println(F("DELAY +, config written"));
@@ -1181,7 +1195,7 @@ void setupWWW()
 		server.send ( 302, "text/plain", "");
 	});
 	server.on("/DELAY=-1", []() {
-		txDelay-=5000;
+		gwayConfig.txDelay-=5000;
 		writeGwayCfg(CONFIGFILE);				// Save configuration to file
 #if _DUSB>=1
 		Serial.println(F("DELAY +, config written"));

+ 0 - 3
ESP-sc-gway/loraModem.h

@@ -51,9 +51,6 @@
 #define DONE_WAIT 1950							// 2000 microseconds (1/500) sec between CDDONE events
 
 
-// Our code should correct the server Tramission delay settings
-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