-
Notifications
You must be signed in to change notification settings - Fork 13.3k
How can I make copy about UART_TX_FIFO in Arduino skatch? #1551
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
Comments
is it needed to do it register level? HardwareSerial mirror(&Serial);
class SerialMirror: public Stream {
HardwareSerial * _serial;
SerialMirror(Serial * s) {
_serial = s;
}
size_t write(const uint8_t *data, size_t size) {
/// add code for your mirror here
return _serial->write(data, size);
}
size_t write(uint8_t data) {
/// add code for your mirror here
return _serial->write(data);
}
int available() {
return _serial->available();
}
int read() {
return _serial->read();;
}
int peek() {
return _serial->peek();
}
void flush() {
_serial->flush();
}
} usage: mirror.println('test'); |
thx, I will test it |
@Links2004 I think he means that he wants to output at two locations at the same time. |
@me-no-dev yes think so, that is why I write `add code for your mirror here`` as comment in the code ;) |
@Links2004 will this make it possible for instance to stream serial to websockets? got any sample of that somewhere? :) |
@tzapu yes you can write a class that can "print" to websocktes in the same way, or eaven combine them to print to Serial and WS. class SerialMirror: public Stream {
WebSocketsServer* _ws;
SerialMirror(WebSocketsServer * s) { _ws = s; }
size_t write(const uint8_t *data, size_t size) { _ws->broadcastTXT(data, size); return size; }
size_t write(uint8_t data) { return _ws->broadcastTXT(data); return 1; }
int available() { return 0; }
int read() { return -1; }
int peek() { return -1; }
void flush() { }
} |
hi, thank you very much for the hints, i assume i can combine the two above to proxy reading from serial to websockets... need to learn more :D on second thought, do i need the stream interface if i m just reading and passing on to websockets? probably for simplicity it s better and i can just add the sending to the read method, maybe with some buffering ... |
yes for serial to websockets bridge you not need a stream interface for websockets . Serial.setTimeout(200);
String line = Serial.readStringUntil('\n');
if(line.length() > 0) {
// add back line ending
line+='\n';
ws->broadcastTXT(line);
} sends all 200ms (when data is there) or on every line ending. |
how cool is that :D |
@Links2004 this seems to be missing some strings at 115200, is there something i can do to make it more reliable? |
@Links2004 , double checked, it seems it s missing strings when reading from serial. my loop looks like this currently
|
so you not get echoed back all data? you can try: void setup() {
....
Serial.setTimeout(200);
}
void loop() {
webSocket.loop();
if(Serial.available()) {
String line = Serial.readStringUntil('\n');
if(line.length() > 0) {
// add back line ending
line+='\n';
ws->broadcastTXT(line);
}
}
} |
nop, somhow it s eating characters. tried with timeout in setup, still no go
that should have the full url there somewhere and headers, etc |
i have also tried without timeout, larger timeout, still the same. |
this seems to yield some better results on some fast tests, but i m not convinced it would hold as no timeouts, no buffering, etc
|
although i just realised in the latest example i forgot to add the websockets loop... |
hi @Links2004 , took longer than i expected to try this it seems that indeed if i use the serialEvent loop like above, it does not miss characters.... weird /edit i was quick to post... still eating characters
no idea what i could do to it to make it better ... any suggestions welcome |
that you lost the empty lines make sens with your code. you can try to: |
thanks for the hints, will play with it more |
the internal serial hardware buffer is 128Byte with the code above I not see a reason why it can |
i m using a nodemcu as a serial reader of stuff spat out by an esp01 |
Did you give up on serial tx mirror ? I am looking for the same, but not websockets, although that would be nice also. |
well, my repo above does mirroring over websockets to a page, also on github pages |
hmm I thought |
Oh you are using a hardware rx. I am wanting what the op wanted. Mirror all Serial tx to a server stream say telnet write or websockets whatever. Like overloading or interxepting Serial writes. |
sorry for waking the dead with this one @Links2004 , i got around to plugging a real serial adapter into the GND/TX of the sending ESP, and unline the NodeMCU that was reading with the code above, this does not miss any characters. It does seem that somehow serial rx is missing characters, and quite a bit of them |
you can try: how high is you data rate, may you overload the Hardware serial RX buffer. |
hi, baud is set at 115200, data is rather little, should not go over buffer. longest line seems to be around 115 characters, and it seems to eat random parts of the buffer anyway, not always the same one. i will try the sample you kindly provided. thank you. i ll also try slower baud rates |
Ah I reread, hardware buffer is 128 byte. Do you have a reproduction test, I have two boards in my dev, i can try, or try a loopback. I am Assumig you do not have a problem generating data internally , but only when reading hardware serial? |
as an aside And I am guessing Serial is not typedefed or something for the second error.
Nor do I get how mirror() is using the SerialMirror class , or was that all supposed to be handled via the &Serial reference ? Since there is no explicit instantiation of the class... I guess that could have been psuedocode.. |
for #1551 (comment) for a Serial to WS bridge is currently use |
That bridge is what I am using above (screenshot), I was interested in having a stream to websockets/hardwareserial/telnet so i figured a serial mirror like that would be useful for easily pluggin into existing sketches and redirecting to wherever I wanted. Thanks! I guess I will have to read up on classes, since i already changed that, but was having a problem with other errors like non-class member private etc. |
for mirroring the "Serial out" to multible interfaces you need to create a class with the class SerialMirror: public Stream {
size_t write(const uint8_t *data, size_t size) {
ws.broadcastTXT(data, size);
Serial.write(data, size);
Serial1.write(data, size);
return size;
}
size_t write(uint8_t data) {
ws.broadcastTXT(data);
Serial.write(data);
Serial1.write(data);
return 1;
}
int available() { return 0; }
int read() { return -1; }
int peek() { return -1; }
void flush() { }
}
SerialMirror SerialM;
SeriaM.println("print to all interfaces"); |
Sounds easy enough, do i need to alias the print/ln stuff or is that done by the stream class? |
the Stream class will do this for you. but the code may send byte by byte. |
I need to catch and store all of characters coming out UART0 tx pin, and send them to another direction.
It have to do inside ESP, with software, because no free pin on ESP already (read back tx pin).
I think, if I can get every characters when is written to UART_TX_FIFO it can solve this problem.
But I dont know how, any idea?
The text was updated successfully, but these errors were encountered: