|
@@ -21,16 +21,22 @@ String StrCF;
|
|
// Time values
|
|
// Time values
|
|
time_t Time, NTPLastUpdate;
|
|
time_t Time, NTPLastUpdate;
|
|
|
|
|
|
-/* FTPServer ftp; */
|
|
|
|
-
|
|
|
|
void process();
|
|
void process();
|
|
void connectOk();
|
|
void connectOk();
|
|
void connectFail();
|
|
void connectFail();
|
|
-void onNtpReceive(NtpClient& client, time_t timestamp);
|
|
|
|
void showTime();
|
|
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);
|
|
NtpClient ntpClient ("ntps1-0.cs.tu-berlin.de", 300, onNtpReceive);
|
|
|
|
|
|
|
|
+// FTP Server;
|
|
|
|
+FTPServer ftp;
|
|
|
|
|
|
void init()
|
|
void init()
|
|
{
|
|
{
|
|
@@ -172,15 +178,19 @@ void process()
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ /*
|
|
|
|
+ *  ñëó÷àå, åñëè îò äàò÷èêà íè÷åãî íå ïîëó÷èëè, çàïóñòèì ïîâòîðíûé îïðîñ ÷åðåç
|
|
|
|
+ * 10 ñåêóíä, íî íå áîëåå 5 ðàç ïîäðÿä.
|
|
|
|
+ */
|
|
if (status < 6)
|
|
if (status < 6)
|
|
{
|
|
{
|
|
status ++;
|
|
status ++;
|
|
- procTimer.
|
|
|
|
|
|
+ procRTimer.initializeMs(10000, process).startOnce();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
|
|
+
|
|
void startFTP()
|
|
void startFTP()
|
|
{
|
|
{
|
|
// Start FTP server
|
|
// Start FTP server
|
|
@@ -188,7 +198,7 @@ void startFTP()
|
|
ftp.addUser("user", "resu"); // FTP account
|
|
ftp.addUser("user", "resu"); // FTP account
|
|
// You can also use special FTP comand: "fsformat" for clearing file system (for example from TotalCMD)
|
|
// You can also use special FTP comand: "fsformat" for clearing file system (for example from TotalCMD)
|
|
}
|
|
}
|
|
-*/
|
|
|
|
|
|
+
|
|
|
|
|
|
void connectOk()
|
|
void connectOk()
|
|
{
|
|
{
|
|
@@ -198,7 +208,9 @@ void connectOk()
|
|
|
|
|
|
startWebServer();
|
|
startWebServer();
|
|
|
|
|
|
-/* startFTP(); */
|
|
|
|
|
|
+ startFTP();
|
|
|
|
+
|
|
|
|
+ udp.listen(EchoPort);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -227,3 +239,27 @@ void onNtpReceive(NtpClient& client, time_t timestamp) {
|
|
NTPLastUpdate = SystemClock.now();
|
|
NTPLastUpdate = SystemClock.now();
|
|
Serial.println("*** Time synchronized OK! ***"); // DEBUG
|
|
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);
|
|
|
|
+ }
|
|
|
|
+}
|