Przeglądaj źródła

Работа над ошибками.

Vladimir N. Shilov 9 lat temu
rodzic
commit
90e2c8b240
5 zmienionych plików z 43 dodań i 54 usunięć
  1. 6 0
      README.md
  2. 0 45
      app/application.cpp
  3. 1 1
      app/configuration.cpp
  4. 31 3
      app/webserver.cpp
  5. 5 5
      web/config.html

+ 6 - 0
README.md

@@ -116,3 +116,9 @@ UDP Server тоже влез. Если я всё правильно понял,
  	} else {
 		MAX7219br = BMid
 	}
+
+Выкинул FTP Server -- какой-то он странный, скачать ничего не вышло,
+закачть уже и не пытался.
+
+Выкинул UDP Server -- запросы принимает, ответа от него не видно...
+Или я что-то не понимаю, или одно из двух...

+ 0 - 45
app/application.cpp

@@ -26,17 +26,10 @@ void connectOk();
 void connectFail();
 void showTime();
 
-// UDP server
-void onReceive(UdpConnection& connection, char *data, int size, IPAddress remoteIP, uint16_t remotePort); // Declaration
-const uint16_t EchoPort = 777;
-UdpConnection udp(onReceive);
-
 // NTP Client
 void onNtpReceive(NtpClient& client, time_t timestamp);
 NtpClient ntpClient ("ntps1-0.cs.tu-berlin.de", 300, onNtpReceive);
 
-// FTP Server;
-FTPServer ftp;
 
 void init()
 {
@@ -190,16 +183,6 @@ void process()
 	}
 }
 
-
-void startFTP()
-{
-	// Start FTP server
-	ftp.listen(21);
-	ftp.addUser("user", "resu"); // FTP account
-	// You can also use special FTP comand: "fsformat" for clearing file system (for example from TotalCMD)
-}
-
-
 void connectOk()
 {
 	WifiAccessPoint.enable(false);
@@ -207,10 +190,6 @@ void connectOk()
 	Serial.println(WifiStation.getIP().toString());
 
 	startWebServer();
-
-	startFTP();
-
-	udp.listen(EchoPort);
 }
 
 /*
@@ -239,27 +218,3 @@ void onNtpReceive(NtpClient& client, time_t timestamp) {
 	NTPLastUpdate = SystemClock.now();
 	Serial.println("*** Time synchronized OK! ***"); // DEBUG
 }
-
-/*
- * UDP Server
- */
-void onReceive(UdpConnection& connection, char *data, int size, IPAddress remoteIP, uint16_t remotePort)
-{
-	debugf("UDP Sever callback from %s:%d, %d bytes", remoteIP.toString().c_str(), remotePort, size);
-
-	// We implement string mode server for example
-	Serial.print(">\t");
-	Serial.print(data);
-
-	if (data == "get_sensors")
-	{
-		String text = String("Temperature: ") + String(SensorT, 2) + String("\rHumidity: ") + String(SensorH, 2) + String("\r");
-		udp.sendStringTo(remoteIP, EchoPort, text);
-	}
-	else
-	{
-		// Send echo to remote sender
-		String text = String("echo: ") + data;
-		udp.sendStringTo(remoteIP, EchoPort, text);
-	}
-}

+ 1 - 1
app/configuration.cpp

@@ -24,7 +24,7 @@ ClockConfig loadConfig()
 
 		JsonObject& light = root["light"];
 		cfg.LightTrhLow = light["low"];
-		cfg.LightTrhLow = light["high"];
+		cfg.LightTrhHigh = light["high"];
 
 		JsonObject& bright = root["bright"];
 		cfg.BrightnessLow = bright["low"];

+ 31 - 3
app/webserver.cpp

@@ -47,32 +47,60 @@ void onConfiguration(HttpRequest &request, HttpResponse &response)
 
 		if (request.getPostParameter("TZ").length() > 0) // Correction
 		{
-			cfg.AddTZ = request.getPostParameter("TZ").toFloat();
+			float tz = request.getPostParameter("TZ").toFloat();
+			if (cfg.AddTZ != tz)
+			{
+				cfg.AddTZ = tz;
+				SystemClock.setTimeZone(cfg.AddTZ);
+				if (cfg.AddTZ<0 || cfg.AddTZ>23)
+				{
+					cfg.AddTZ = 0;
+				}
+			}
 		}
 
 		if (request.getPostParameter("BLow").length() > 0) // Low brightness level.
 		{
 			cfg.BrightnessLow = request.getPostParameter("BLow").toInt();
+			if (cfg.BrightnessLow<0 || cfg.BrightnessLow>15)
+			{
+				cfg.BrightnessLow = 0;
+			}
 		}
 		if (request.getPostParameter("BMid").length() > 0) // Middle brightness level.
 		{
 			cfg.BrightnessMiddle = request.getPostParameter("BMid").toInt();
+			if (cfg.BrightnessMiddle<0 || cfg.BrightnessMiddle>15)
+			{
+				cfg.BrightnessMiddle = 7;
+			}
 		}
 		if (request.getPostParameter("BHigh").length() > 0) // High brightness level.
 		{
 			cfg.BrightnessHigh = request.getPostParameter("BHigh").toInt();
+			if (cfg.BrightnessHigh<0 || cfg.BrightnessHigh>15)
+			{
+				cfg.BrightnessHigh = 15;
+			}
 		}
 
 		if (request.getPostParameter("LLow").length() > 0) // Low light level trh.
 		{
 			cfg.LightTrhLow = request.getPostParameter("LLow").toInt();
+			if (cfg.LightTrhLow<0 || cfg.LightTrhLow>1023)
+			{
+				cfg.LightTrhLow = 0;
+			}
 		}
 		if (request.getPostParameter("LHigh").length() > 0) // High light level trh.
 		{
 			cfg.LightTrhHigh = request.getPostParameter("LHigh").toInt();
+			if (cfg.LightTrhHigh<0 || cfg.LightTrhHigh>1023)
+			{
+				cfg.LightTrhHigh = 1023;
+			}
 		}
 		saveConfig(cfg);
-		SystemClock.setTimeZone(cfg.AddTZ);
 		response.redirect();
 	}
 
@@ -119,7 +147,7 @@ void onApiDoc(HttpRequest &request, HttpResponse &response)
 }
 
 /*
- * Gt json data
+ * Get json data
  * äàííûå ñ äàò÷èêîâ âûäà¸ì ñ ìàêñèìàëüíûì ðàçðåøåíèåì.
  */
 void onApiSensors(HttpRequest &request, HttpResponse &response)

+ 5 - 5
web/config.html

@@ -71,24 +71,24 @@
 				  <form method="POST">
 					  <div class="form-group">
 						<label>Low light level threshold, 0 &mdash; 1023</label>
-						<input type="text" name="LLow" class="form-control" value="{LLow}">
+						<input type="number" min="0" max="1023" name="LLow" class="form-control" value="{LLow}">
 					  </div>
 					  <div class="form-group">
 						<label>High light level threshold, 0 &mdash; 1023</label>
-						<input type="text" name="LHihg" class="form-control" value="{LHihg}">
+						<input type="number" min="0" max="1023" name="LHigh" class="form-control" value="{LHigh}">
 					  </div>
 
 					  <div class="form-group">
 						<label>Brightness Low level, 0 &mdash; 15</label>
-						<input type="text" name="BLow" class="form-control" value="{BLow}">
+						<input type="number" min="0" max="15" name="BLow" class="form-control" value="{BLow}">
 					  </div>
 					  <div class="form-group">
 						<label>Brightness Middle level, 0 &mdash; 15</label>
-						<input type="text" name="BMid" class="form-control" value="{BMid}">
+						<input type="number" min="0" max="15" name="BMid" class="form-control" value="{BMid}">
 					  </div>
 					  <div class="form-group">
 						<label>Brightness High level, 0 &mdash; 14</label>
-						<input type="text" name="BHigh" class="form-control" value="{BHigh}">
+						<input type="number" min="0" max="15" name="BHigh" class="form-control" value="{BHigh}">
 					  </div>
 
 					  <div class="form-group">