P1-Meter-ESP8266-MQTT icon indicating copy to clipboard operation
P1-Meter-ESP8266-MQTT copied to clipboard

esp8266 board manager ver 2.60 change

Open bill-orange opened this issue 4 years ago • 2 comments

Recently the ESP8266 board manager ver. 2.6.0 was released. Several changes that had been in the works regarding SoftwareSerial were implemented. As a result the sample code for this project will no longer compile. @dok-net provided this explanation:


Software serial can handle the diagnostics to USB quite well, whereas using the HW UART for the real application is in almost any scenario the superior option. I can’t even begin to imagine why all those libraries never considered

Serial.swap();

Now, if you’re faced with this situation, it’s only fair that I give you the simple change that needs to be done to the sources:

Before, somewhere in the sketch, provided that RX and TX are defines for the RX and TX pin numbers respectively:

SoftwareSerial swSer1(RX, TX); // non-inverted physical protocol, buffer size 256
swSer1.begin(115200);

Now, for quite awhile:

SoftwareSerial swSer1;
swSer1.begin(115200, RX, TX);

Where for the HW UART things would be:

Serial.swap();
Serial.begin(115200);

I hope you see the beauty of it – it makes it simpler to switch to HW UART, and it’s a bit easier on the eye. Plus, switching bitrate at runtime should not involve the constructor!


As a result, I believe that example code should be revised as shown below. Please note, I was not able to test it other than making sure it compiled!

//Infrastructure stuff
const int MAXLINELENGTH = 64;
char telegram[MAXLINELENGTH];
SoftwareSerial mySerial;
constexpr SoftwareSerialConfig swSerialConfig = SWSERIAL_8N1;
constexpr int IUTBITRATE = 115200;
WiFiClient espClient;
PubSubClient client(espClient);

void setup()
{
  Serial.begin(115200);
  mySerial.begin (IUTBITRATE,SERIAL_RX, -1, swSerialConfig,true, MAXLINELENGTH); 
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.waitForConnectResult() != WL_CONNECTED)
  {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }
  // mySerial.begin(115200); removed
  ArduinoOTA.setHostname(hostName);

bill-orange avatar Nov 11 '19 01:11 bill-orange