Skip to content
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

esp8266 board manager ver 2.60 change #5

Open
bill-orange opened this issue Nov 11, 2019 · 2 comments
Open

esp8266 board manager ver 2.60 change #5

bill-orange opened this issue Nov 11, 2019 · 2 comments

Comments

@bill-orange
Copy link

bill-orange commented Nov 11, 2019

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);

@sandervandegeijn
Copy link
Owner

Thanks, I don't have any time the coming weeks to validate your fix. If others post a positive result I'll merge it!

@bill-orange
Copy link
Author

I have not retested but it may no longer be necessary. Since my post The serial library has been revised two more time (one still in the release process). The Intent of the changes were to resolve various compatibility issues.

Fingers crossed.

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