I'm trying to connect my NodeMCU to wifi. It isn't finishing because software serial is interrupting it.
Sort of like Software serial conflict with WiFi on ESP8266.
Here's my code:
#include <SoftwareSerial.h>
#include "ESP8266WiFi.h"
const char* ssid = "mywifi";
const char* password = "password123";
void setup() {
Serial.begin(9600);
Serial.println("");
connectWifi();
SoftwareSerial pinSerial(1, 3);
pinSerial.begin(9600);
}
void loop() {
// send data received from serial port
}
// in separate function so I can reconnect in the loop
bool connectWifi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
if( WiFi.status() == WL_CONNECTED) {
return true;
} else {
Serial.println("wifi connection failed");
}
}
The console outputs the periods as it's connecting but never prints the IP and instead prints the serial data it received while trying to connect.
Can I delay the activation of the software serial port? Should I use another serial library?
Please don't focus on basic code errors, I'm still learning.
Serial
SoftwareSerial pinSerial(1, 3);
insetup()
is strange as it 1) uses the hardware serial pins, 2) is never used other thanbegin()
, and 3) is destructed when returning. What are you trying to do exactly?