Created
December 16, 2017 07:38
-
-
Save kheminw/1e1632006456fbc22b76b2af0b2239ed to your computer and use it in GitHub Desktop.
NodeMCU UART Snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(5, 4); // RX, TX | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(38400, SERIAL_8N1); | |
mySerial.begin(38400); | |
Serial.println("[NODE] Started"); | |
// String mySerialStart = "[STM] Node is now connected to STM!\r\n"; | |
// for(int i = 0; i < mySerialStart.length(); i++){ | |
// mySerial.write(mySerialStart[i]); | |
// } | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if(Serial.available()){ | |
String buffer = Serial.readString(); | |
String log = "[NODE] " + buffer; | |
Serial.println(log); | |
for(int i = 0; i < buffer.length(); i++){ | |
mySerial.write(buffer[i]); | |
} | |
} | |
if(mySerial.available()){ | |
char buffer2[32]; | |
// for(uint64_t time = millis(); time + 10000 > millis();){ | |
// buffer2 += (char) mySerial.read(); | |
// yield(); | |
// } | |
mySerial.readBytes(buffer2, sizeof(buffer2)); | |
Serial.print("[STM] "); | |
Serial.print(buffer2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment