Skip to content

Using pinMode, attachInterrupts() and Wifi Access Point breaks #5033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
WolfBSail opened this issue Aug 13, 2018 · 2 comments
Closed
6 tasks done

Using pinMode, attachInterrupts() and Wifi Access Point breaks #5033

WolfBSail opened this issue Aug 13, 2018 · 2 comments

Comments

@WolfBSail
Copy link

WolfBSail commented Aug 13, 2018

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12E]
  • Core Version: [latest git hash or date]
  • Development Env: [Arduino IDE]
  • Operating System: [MacOS]

Settings in IDE

  • Module: [Nodemcu]
  • Flash Mode: [no idea]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [115200] (serial upload only)

Problem Description

I have a similar issue as #1020, using ESP12E board. When I am declaring certain pins, using attachInterrupts() and setting up Access Point WiFi in the same void setup() the wifi stops working. I have tested out that if I only declare pins D0, D1, D2, D3, D4, A0 and set up WiFi without the interrupts it does work. Please seen my setup code below!
I have tried detachInterrupt(), but it did not work.

Does anyone have the same problem? Is there a solution to this problem?

Thank you in advance.

MCVE Sketch

#include <WebSocketsServer.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266WiFi.h>
#include <Wire.h>       //I2C library
#include <RtcDS3231.h>  //RTC library

WebSocketsServer webSocket = WebSocketsServer(81); // websocket instance

void setup() {
  pinMode(4, INPUT);
  pinMode(3, INPUT);
  pinMode(2, INPUT);  
  pinMode(1, OUTPUT);  
  pinMode(0, OUTPUT);
  
  Serial.begin(9600);

  rtcObject.Begin();  
  attachInterrupt(digitalPinToInterrupt(secPin), secondReceive, FALLING);
  attachInterrupt(digitalPinToInterrupt(voltagePin), voltageDrop, FALLING);

  // Init EEPROM
  EEPROM.begin(512);

  // look at whether power-cut time correction is neccessary
  if(EEPROM.read(addr[3])==1){
        
    clockEnabled=1;
    startTime=millis();
    Serial.println();
    Serial.println("Blackout has happened, time correction...");
    Serial.println();
    getRtcTime();
    EEPROM.write(addr[6], rtcHour);    
    EEPROM.write(addr[7], rtcMinute);    
    EEPROM.write(addr[8], rtcSecond);    
    powerCutTimeCorrection();    
    EEPROM.write(addr[3], 0);   
    EEPROM.commit();
    loopTime=millis();
  }
  else{
    configRTC(ntpYear, ntpMonth, ntpDay,ntpHour, ntpMinute, ntpSecond);     
    RtcDateTime currentTime = rtcObject.GetDateTime();
    rtcObject.SetDateTime(currentTime);
  }

  //init rtc functions
  rtcObject.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
  rtcObject.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz); //SQW set to 1Hz

  detachInterrupt(digitalPinToInterrupt(secPin));
  detachInterrupt(digitalPinToInterrupt(voltagePin));

  //creating the ESP's own network
  
  WiFi.disconnect();
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  WiFi.softAP(ssidESP, passwordESP);
  Serial.print("Connected to ");
  Serial.println(ssidESP);
  Serial.print("Access Point IP address = ");
  Serial.println(WiFi.softAPIP());
  Serial.println("");
 

  handleWebsite();   // crating html string;
  dnsServer.start(DNS_PORT, "*", apIP);
  server.on("/", handleWebsite);
  server.on("/generate_204", handleWebsite); // for android captive
  server.on("/fwlink", handleWebsite);       // windows captive
  server.begin();

  server.onNotFound([]() {
    server.send(200, "text/html", webSite); 
  });

  webSocket.begin();
  webSocket.onEvent(webSocketEvent);
  
}

void loop() {  
  dnsServer.processNextRequest(); //maintains webserver status  
  server.handleClient();   
  webSocket.loop();
  jsonReq();//JSON Request function  
  clockWorkOrange();              //Main clock function                      
}
@devyte
Copy link
Collaborator

devyte commented Aug 13, 2018

You mention D numbering, but your code uses GPIO numbering, and they're not the same.
E.g.: on a nodemcu board, D1 is GPIO5 and GPIO1 is TX.
Your code is using GPIO0-4, and some of those are not allowed for user applications. I suggest you study the board pinout and how it connects to the ESP12 pinout.
Closing as user error.

@devyte devyte closed this as completed Aug 13, 2018
@WolfBSail
Copy link
Author

WolfBSail commented Aug 13, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants