Skip to content

Commit 5a16292

Browse files
committed
Prefer Serial1 logging in examples
As suggested by esp8266#8915 (comment)
1 parent de1029f commit 5a16292

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030
/*
3131
SWAP_PINS:
32-
0: use Serial1 for logging (legacy example)
32+
0: use Serial1 for logging
3333
1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15
34-
and use EspSoftwareSerial for logging on
34+
and then use EspSoftwareSerial for logging on
3535
standard Serial pins RX:GPIO3 and TX:GPIO1
3636
*/
3737

@@ -90,6 +90,8 @@ void setup() {
9090
logger->enableIntTx(false);
9191
logger->println("\n\nUsing EspSoftwareSerial for logging");
9292
#else
93+
// Hardware serial0 is on RX(3)/TX(1)
94+
// Hardware serial1 is on (no RX)/TX(2)
9395
logger->begin(BAUD_LOGGER);
9496
logger->println("\n\nUsing Serial1 for logging");
9597
#endif

libraries/esp8266/examples/SerialStress/SerialStress.ino

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11

22
/*
33
Serial read/write/verify/benchmark
4-
Using internal loopback
5-
Using EspSoftwareSerial library for logging
4+
Using internal loopback on Serial0
5+
Logging to Serial1
66
77
Sketch meant for debugging only
88
Released to public domain
99
*/
1010

1111
#include <ESP8266WiFi.h>
12-
#include <SoftwareSerial.h>
1312

14-
#define SSBAUD 115200 // logger on console for humans
13+
#define LOGBAUD 115200 // logger on console for humans
1514
#define BAUD 3000000 // hardware serial stress test
1615
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
1716
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()
@@ -21,6 +20,9 @@
2120
#define TIMEOUT 5000
2221
#define DEBUG(x...) // x
2322

23+
#define READING_PIN 4
24+
#define TIMEOUT_PIN 5
25+
2426
uint8_t buf[BUFFER_SIZE];
2527
uint8_t temp[BUFFER_SIZE];
2628
bool reading = true;
@@ -51,18 +53,18 @@ void error(const char* what) {
5153
void setup() {
5254
pinMode(LED_BUILTIN, OUTPUT);
5355

56+
pinMode(READING_PIN, INPUT);
57+
pinMode(TIMEOUT_PIN, INPUT);
58+
5459
Serial.begin(BAUD);
5560
Serial.swap(); // RX=GPIO13 TX=GPIO15
5661
Serial.setRxBufferSize(SERIAL_SIZE_RX);
5762

58-
// using HardwareSerial0 pins,
59-
// so we can still log to the regular usbserial chips
60-
SoftwareSerial* ss = new SoftwareSerial(3, 1);
61-
ss->begin(SSBAUD);
62-
ss->enableIntTx(false);
63-
logger = ss;
63+
Serial1.begin(LOGBAUD); // RX=NONE TX=GPIO2
64+
logger = &Serial1;
65+
6466
logger->println();
65-
logger->printf("\n\nOn Software Serial for logging\n");
67+
logger->printf("\n\nOn Serial1 for logging\n");
6668

6769
int baud = Serial.baudRate();
6870
logger->printf(ESP.getFullVersion().c_str());
@@ -140,15 +142,13 @@ void loop() {
140142
timeout = (last_ms = now_ms) + TIMEOUT;
141143
}
142144

143-
if (logger->available()) switch (logger->read()) {
144-
case 's':
145-
logger->println("now stopping reading, keeping writing");
146-
reading = false;
147-
break;
148-
case 't':
149-
testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE;
150-
logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout);
151-
break;
152-
default:;
153-
}
145+
if (reading && (digitalRead(READING_PIN) == 0)) {
146+
logger->println("now stopping reading, keeping writing");
147+
reading = false;
148+
}
149+
150+
if (digitalRead(TIMEOUT_PIN) == 0) {
151+
testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE;
152+
logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout);
153+
}
154154
}

libraries/esp8266/examples/TestEspApi/TestEspApi.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ extern "C" {
1515
}
1616
#endif
1717

18-
// Set up output serial port (could be a SoftwareSerial
19-
// if really wanted).
18+
// Set up output on the first serial port
19+
// (can be any Stream, if needed)
2020

2121
Stream& ehConsolePort(Serial);
2222

libraries/lwIP_PPP/examples/PPPServer/PPPServer.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <lwip/dns.h>
2121
#include <PPPServer.h>
2222
#include <ESP8266WiFi.h>
23-
#include <SoftwareSerial.h>
2423

2524
#ifndef STASSID
2625
#define STASSID "your-ssid"
@@ -36,8 +35,8 @@
3635
#define RX 13 // d1mini D7
3736
#define TX 15 // d1mini D8
3837

39-
SoftwareSerial ppplink(RX, TX);
40-
HardwareSerial& logger = Serial;
38+
HardwareSerial& ppplink = Serial;
39+
HardwareSerial& logger = Serial1;
4140
PPPServer ppp(&ppplink);
4241

4342
void PPPConnectedCallback(netif* nif) {
@@ -74,7 +73,8 @@ void setup() {
7473
logger.printf("\nSTA: %s (dns: %s / %s)\n", WiFi.localIP().toString().c_str(), WiFi.dnsIP(0).toString().c_str(), WiFi.dnsIP(1).toString().c_str());
7574

7675
ppplink.begin(PPPLINKBAUD);
77-
ppplink.enableIntTx(true);
76+
ppplink.swap(); // RX=GPIO13 TX=GPIO15
77+
7878
logger.println();
7979
logger.printf("\n\nhey, trying to be a PPP server here\n\n");
8080
logger.printf("Now try this on your linux host:\n\n");

0 commit comments

Comments
 (0)