I think I'm trying to implement something very simple, but I'm missing something very simple as well.
I'm trying to implement a vary basic terminal emulator with the Seeed Ethernet Shield v1.1 and an UNO.
The first objective is to append " +OK" to the input, which emulates the response of a very expensive DSP system that lives in a closet somewhere that I don't have access to all the time. The point is to enable debugging of yet ANOTHER control system that hangs without the DSP present.
I started with the ChatServer example in the Tutorials. I won't include the rest of the boilerplate because it seems well documented.
if (client.available() > 0) {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
I want to do something like
server.write(thisChar);
server.println(" +OK);
which looks like this in my terminal
hello
h +OK
e +OK
l +OK
l +OK
o +OK
+OK
+OK
I'm looking for something more like...
hello
hello +OK
I'm pretty rusty with my C, and I never really trained on C++, so I'm kind of lost. I've read a number of examples of string functions to use, and I think what I need to do is read thisChar into a string, but I keep getting fouled up. Is there an easy way to do this with char?
to write back to the telnet session instead of the serial monitor, but this definetly handles better than before. I really need the +OK to be on the same line, though. Any thoughts?
puts the " +OK" after thisChar, since one comes after the other...
It only prints " +OK" if thisChar is a newline. If thisChar is anything but a carriage return, it prints the character. Actually, it probably should have been like this: