Hallo Zusammen
Ich habe ein Problem und komme einfach nicht weiter. Es geht um folgenden Code:
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <time.h>
IPAddress ip(192,168,2,1); //Node static IP
IPAddress gateway(192,168,2,1);
IPAddress subnet(255,255,255,0);
IPAddress ip2(192,168,1,100); //Node static IP
IPAddress gateway2(192,168,1,1);
IPAddress subnet2(255,255,255,0);
/* Set these to your desired credentials. */
const char *ssid = "Gabriel";
const char *password = "Gabriel123";
const char* ssid2 = "WLAN-Nesslau";
const char* password2 = "axuncowoinne";
char *stringOne;
WiFiUDP Udp;
WiFiUDP Udp2;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char packetBuffer2[UDP_TX_PACKET_MAX_SIZE];//buffer to hold incoming packet,
ESP8266WebServer server(80);
/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
char temp[1000];
snprintf ( temp, 1000,
"<html>\
<head>\
<meta http-equiv='refresh' content='3'>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #F7FF00; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from ESP8266!</h1>\
<p>SSID: %s</p>\
<p>Passwort: %s</p>\
<p>Temperatur: %s Grad</p>\
<p>Feuchtigkeit: %s %</p>\
<p>Zeit: %s </p>\
<div style=\"width:180px;height:180px; border: 1px solid black;\">\
<a href=\"http://alarm.meteocentrale.ch/index.html\" alt=\"Aktuelle Unwetterwarnungen für die Schweiz\" title=\"Aktuelle Unwetterwarnungen für die Schweiz\">\
<img src=\"http://alarm.meteocentrale.ch/images/map/schweiz_preview.png\"> \
</a>\
</div>\
</body>\
</html>",
ssid, password, packetBuffer, packetBuffer2, stringOne
);
server.send ( 200, "text/html", temp );
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(ip, gateway, subnet);
WiFi.begin ( ssid2, password2 );
WiFi.config(ip2, gateway2, subnet2);
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
WiFi.mode(WIFI_AP_STA);
Udp.begin(8888);
Udp2.begin(8889);
configTime(2 * 3600, 0, "ntp-public.uit.no");
Serial.println("\nWaiting for time");
while (!time(nullptr)) {
delay(3000);
Serial.print(".");
}
Serial.println("");
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize)
{
for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
Serial.println(stringOne);
}
int packetSize2 = Udp2.parsePacket();
if(packetSize2)
{
for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer2[i] = 0;
Serial.print("Received packet of size ");
Serial.println(packetSize2);
Serial.print("From ");
IPAddress remote = Udp2.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp2.remotePort());
// read the packet into packetBufffer
Udp2.read(packetBuffer2,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer2);
Serial.println(stringOne);
}
server.handleClient();
time_t now = time(nullptr);
stringOne = ctime(&now);
}
Nun will ich die Zeit speichern und anschliessend anzeigen, wann die letzten Daten angekommen sind. Also habe ich das eingefügt:
Oberhalb vom Setup:
char *stringTwo;
char *stringThree;
stringTwo = stringOne;
Serial.println(stringTwo);
stringThree= stringOne;
Serial.println(stringThree);[/code]
=
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <time.h>
IPAddress ip(192,168,2,1); //Node static IP
IPAddress gateway(192,168,2,1);
IPAddress subnet(255,255,255,0);
IPAddress ip2(192,168,1,100); //Node static IP
IPAddress gateway2(192,168,1,1);
IPAddress subnet2(255,255,255,0);
/* Set these to your desired credentials. */
const char *ssid = "Gabriel";
const char *password = "Gabriel123";
const char* ssid2 = "WLAN-Nesslau";
const char* password2 = "axuncowoinne";
char *stringOne;
char *stringTwo;
char *stringThree;
WiFiUDP Udp;
WiFiUDP Udp2;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char packetBuffer2[UDP_TX_PACKET_MAX_SIZE];//buffer to hold incoming packet,
ESP8266WebServer server(80);
/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
char temp[1000];
snprintf ( temp, 1000,
"<html>\
<head>\
<meta http-equiv='refresh' content='3'>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #F7FF00; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from ESP8266!</h1>\
<p>SSID: %s</p>\
<p>Passwort: %s</p>\
<p>Temperatur: %s Grad</p>\
<p>Feuchtigkeit: %s %</p>\
<p>Zeit: %s </p>\
<div style=\"width:180px;height:180px; border: 1px solid black;\">\
<a href=\"http://alarm.meteocentrale.ch/index.html\" alt=\"Aktuelle Unwetterwarnungen für die Schweiz\" title=\"Aktuelle Unwetterwarnungen für die Schweiz\">\
<img src=\"http://alarm.meteocentrale.ch/images/map/schweiz_preview.png\"> \
</a>\
</div>\
</body>\
</html>",
ssid, password, packetBuffer, packetBuffer2, stringOne
);
server.send ( 200, "text/html", temp );
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(ip, gateway, subnet);
WiFi.begin ( ssid2, password2 );
WiFi.config(ip2, gateway2, subnet2);
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
WiFi.mode(WIFI_AP_STA);
Udp.begin(8888);
Udp2.begin(8889);
configTime(2 * 3600, 0, "ntp-public.uit.no");
Serial.println("\nWaiting for time");
while (!time(nullptr)) {
delay(3000);
Serial.print(".");
}
Serial.println("");
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize)
{
for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
Serial.println(stringOne);
stringTwo = stringOne;
Serial.println(stringTwo);
}
int packetSize2 = Udp2.parsePacket();
if(packetSize2)
{
for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer2[i] = 0;
Serial.print("Received packet of size ");
Serial.println(packetSize2);
Serial.print("From ");
IPAddress remote = Udp2.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp2.remotePort());
// read the packet into packetBufffer
Udp2.read(packetBuffer2,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer2);
Serial.println(stringOne);
stringThree= stringOne;
Serial.println(stringThree);
}
server.handleClient();
time_t now = time(nullptr);
stringOne = ctime(&now);
}
Aber anstatt die Zeit zu speichern, zählt die Zeit immer weiter. D.h wenn ich ein Datenpaket um 15:30 Uhr sende und um 16.00 Uhr in den Serialmonitor schaue, steht dort 16:00 Uhr. Kann mir jemand helfen?