Forum: Mikrocontroller und Digitale Elektronik ESP8266 Interrupt wird nicht angenommen


von Benjamin H. (Firma: Bin Student) (beohof)


Lesenswert?

Servus,

bin neu bei Mikrocontrollern.

Habe einen Sonoff S20 mit ESP8266. Aus diesem möchte ich eine 
Zeitschaltuhr mit API machen. Der Button vorne ist dafür da von einem 
manuell aus, zu manuell an und Automatik zu schalten (Kann man auch über 
API). In unregelmäßigen Zeitabständen funktoniert der Button der über 
einen Interrupt definiert ist nicht und nach unregelmäßiger Zeit geht 
wieder alles.

Woran kann das liegen? Danke für eure Hilfe :)

Was ich schon probiert habe:

Alle betroffenen Funktionen mit IRAM_ATTR geflagt.
Mit dem Interrupt nur einen Bool ändern und in der loop die 
Statusänderung ausführen.

Hier ist mein Code, falls ihr über die Klassen was Wissen wollt meldet 
euch.
1
#include <Arduino.h>
2
#include <ESP8266WiFi.h>
3
#include <EEPROM.h>
4
#include <ESPAsyncWebServer.h>
5
#include <AsyncJson.h>
6
#include <ArduinoJson.h>
7
#include <ezTime.h>
8
#include "SonoffS20.h"
9
#include "Timer.h"
10
11
#define EEPROM_SIZE 10
12
13
const char * ssid = "Geheim";
14
const char * pass = "Geheim";
15
const char * ntpServer = "192.168.178.1";
16
const long debouncing_time = 15;
17
18
volatile unsigned long last_micros;
19
20
bool interrupt = false;
21
Timezone * local;
22
SonoffS20 * hardware;
23
Timer * timer;
24
AsyncWebServer server(80);
25
26
27
void IRAM_ATTR ISR() {
28
  if((long)(micros() - last_micros) >= debouncing_time * 1000) {
29
    hardware->setButtonState((hardware->getButtonState() + 1 ) % 3);
30
    last_micros = micros();
31
  }
32
}
33
34
void setup() {
35
  EEPROM.begin(EEPROM_SIZE);
36
37
  hardware = new SonoffS20(0);
38
  attachInterrupt(digitalPinToInterrupt(0), ISR, RISING);
39
  timer = new Timer(2);
40
41
  WiFi.begin(ssid, pass);
42
  while (WiFi.status() != WL_CONNECTED) delay(1000);
43
44
  local = new Timezone();
45
  local->setLocation("Europe/Berlin");
46
  setServer(ntpServer);
47
  waitForSync();
48
49
  // Routes
50
  {
51
   // ... Webserver sachen funktionieren einwandfrei
52
  }
53
54
void loop() {
55
  events();
56
  if (hardware->getButtonState() == 2) {
57
    if (timer->timeBetweenStartAndEnd(local->dateTime("~THi"))) {
58
      if (hardware->getRelay() == LOW) hardware->setRelay(HIGH);
59
    }
60
    else if (hardware->getRelay() == HIGH) {
61
      hardware->setRelay(LOW);
62
      }
63
  }
64
  delay(100);
65
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.