Hallo Zusammen,
ich habe ein kleines Problem mit meinem ESP. Und zwar wird so wie ich
das umgesetzt habe keine wifi Verbindung hergestellt, bzw. es gibt einen
Timeout und dann greift der WD....
Wenn ich Setup_Wifi im Setup() aufrufe funktioniert das wifi. Ich
vermute das Problem liegt an der Millis() im Loop und dem Timer der
zusätzlich läuft und das Setup_wifi aufruft. Könnt ihr mir bei der
Lösung helfen?
1 | Ticker standBy;
|
2 |
|
3 | unsigned long interval=30000;
|
4 | unsigned long lastMillis=0;
|
5 | int rpm=0;
|
6 |
|
7 | void setup() {
|
8 | Serial.begin(115200);
|
9 | attachInterrupt(digitalPinToInterrupt(4), ISR_Round,FALLING);
|
10 | standBy.attach(600, goToSleep);
|
11 | }
|
12 |
|
13 | void setup_wifi() {
|
14 |
|
15 | delay(10);
|
16 | // We start by connecting to a WiFi network
|
17 | Serial.println();
|
18 | Serial.print("Connecting to ");
|
19 | Serial.println(ssid);
|
20 |
|
21 | WiFi.begin(ssid, password);
|
22 |
|
23 | while (WiFi.status() != WL_CONNECTED) {
|
24 | delay(500);
|
25 | Serial.print(".");
|
26 | }
|
27 |
|
28 | randomSeed(micros());
|
29 |
|
30 | Serial.println("");
|
31 | Serial.println("WiFi connected");
|
32 | Serial.println("IP address: ");
|
33 | Serial.println(WiFi.localIP());
|
34 | }
|
35 |
|
36 | void goToSleep(void)
|
37 | {
|
38 | Serial.println("Publish Data and Go to sleep now");
|
39 | setup_wifi();
|
40 |
|
41 | //Publish MQTT
|
42 |
|
43 | ESP.deepSleep()
|
44 |
|
45 | }
|
46 |
|
47 | void loop() {
|
48 |
|
49 | if(millis()-lastMillis > interval)
|
50 | {
|
51 | Serial.println("Hallo");
|
52 | rpm=((roundCounter*2)/60);
|
53 | lastMillis=millis();
|
54 | }
|
55 | }
|
Vielleicht hab ich die Lösung schon gefunden. Sitz nur auf der Arbeit
und kanns nicht testen. Aber würde das so helfen?
1 | void goToSleep(void)
|
2 | {
|
3 | TimerFlag=1;
|
4 |
|
5 |
|
6 | }
|
7 |
|
8 | void loop() {
|
9 |
|
10 | if(millis()-lastMillis > interval)
|
11 | {
|
12 | Serial.println("Hallo");
|
13 | rpm=((roundCounter*2)/60);
|
14 | lastMillis=millis();
|
15 | }
|
16 | if(TimerFlag==1)
|
17 | {
|
18 | Serial.println("Publish Data and Go to sleep now");
|
19 | setup_wifi();
|
20 |
|
21 | //Publish MQTT
|
22 | ESP.deepSleep()
|
23 | }
|
24 | }
|