Echo serial.print to telnet

I have added a telnet server to my project so I can monitor the serial output of my esp8266 remotely over wifi.

I have the telnet server and monitor working, correctly and I can print to it and monitor it remotely, and I could just go through the whole program and everywhere there is a serial.print command add a command to print the same thing to the telnet server as well. This is not my ideal solution.

Instead, I would like to add a routine that would check to see if something has been printed to the serial monitor and then echo it to the telnet server, but I am a bit stumped as to how to implement that.

Can anyone point me in the right direction?

Thanks

btkramer:
.......... This is not my ideal solution.

I dare not ask why, but the fact that you are stumped for an alternative to the bleeding obvious might be quite telling.

Why not just replace every instance of serial.print (and serial.println?) with a call to your own routine. In your own routine call serial.print and also your telnet output.

countrypaul:
Why not just replace every instance of serial.print (and serial.println?) with a call to your own routine. In your own routine call serial.print and also your telnet output.

I could do that too, though it would not really be much different than doubling up all the print commands.

My question is really how to monitor when there has been an output to the serial monitor and copy it.

My question is really how to monitor when there has been an output to the serial monitor and copy it.

You have a flag, by which I generally mean a bool variable, like this:

bool sendStuffToTelnet;

Then you have:

if (sendStuffToTelnet) {
  sendStuffToTelnet = false;
  // Some code here to send stuff to telnet;
}

Then everywhere you have a Serial.print you add:

sendStuffToTelnet = true;

You might have to improve on that but it's the general idea.

My question is really how to monitor when there has been an output to the serial monitor and copy it.

No, there isn't.

Nothing to stop you creating your own function that does the same as Serial.print but also includes sending the same thing to the serial monitor and to telnet, then you use your function instead of the Serial.print.

You function would contain Serial.print and some extra code for sending to telnet.

PerryBebbington:
No, there isn't.

Thanks, this is what I wanted to know. I will create a function for it as you mentioned.

I've had another thought, no idea if you can make this work and I consider it to be a bodge, but I very much believe in experimenting and trying stuff.

Serial.print dumps its output in a buffer somewhere (no, I don't know where, you have to look for it), so, maybe, just maybe, you might be able to write some slick code that gets to the buffer before the data is sent to the serial port and copies it, then sends it to telnet. This would rely on the serial port being slow (the serial port is slow compared to the processor) and getting to the data before it's overwritten by new data.

If you try this and manage to get it to work I'd be interested. If you try this and waste a week of your life on something that was never going to work I'd be interested in that too :slight_smile:

PerryBebbington:
Serial.print dumps its output in a buffer somewhere (no, I don't know where, you have to look for it), so, maybe, just maybe, you might be able to write some slick code that gets to the buffer before the data is sent to the serial port and copies it, then sends it to telnet.

This is more in line with what I was wanting to do, but couldn't think of how to go about. You have put me on the track I needed and I will try to figure this out tomorrow when I have some more free time. I doubt I will spend a week trying, though. It interests me, but not that much. :slight_smile:

I will follow up here, regardless.

Thanks again.

You could walk across the street to the Cafe.. Or look! Here is an experimental jet pack diagram. Build that and do it in style!

Really?!

-jim lee

jimLee:
Really?!

Indeed..... Sanity at last.

jimLee:
You could walk across the street to the Cafe.. Or look! Here is an experimental jet pack diagram. Build that and do it in style!

Really?!

-jim lee

You really don't understand the point here. I can easily get the desired result if the result was the only thing I was interested in. I am not just trying to 'make it work' here. I can do that pretty easily a few different ways. However, a specific way had occurred to me, and I wanted to see if I could make that work. This is a hobby for me and I enjoy figuring things out.

Your analogy of building a jet pack only seems silly if your goal is to simply cross the street. If your goal is to build a jet pack, crossing the street is just an application for the jet pack, not the reason for building it.

Well I'd go for the jet pack any day, looks like brilliant fun!!!

Yeah, well...

I never said you couldn't use the jet pack..

-jim lee

btkramer:
However, a specific way had occurred to me, and I wanted to see if I could make that work. This is a hobby for me and I enjoy figuring things out.

You are just trying to justify nonsense, and who should say that that's not OK? If you find that banging your head against the wall is justified because you need the intellectual exercise, go for it. But what you are trying to do here is make a test to prove something you already know, which really is as pointless as you can possibly get. You wrote the code to send data to the monitor, and all you need is in reply#2, so read it again - carefully. Anything more than that will be in code you should never show your mother.

Nick_Pyner:
You are just trying to justify nonsense, and who should say that that’s not OK? If you find that banging your head against the wall is justified because you need the intellectual exercise, go for it. But what you are trying to do here is make a test to prove something you already know, which really is as pointless as you can possibly get. You wrote the code to send data to the monitor, and all you need is in reply#2, so read it again - carefully. Anything more than that will be in code you should never show your mother.

I get that being a jackass is fun for you, and that’s why you’re here making irrelevant posts, but that’s not why I am here.

As mentioned, I already knew how to solve my problem, but I was curious if a certain thing could be done and if so, how would I go about doing it? Not because I think it is the best way to do something or even that I would actually use that method in a ‘real’ program other than to simply do it. It’s not nonsense to want to understand the way something works.

If I do implement it, or at least try, I will learn some things along the way which may or may not be useful in the future, or may or may not be something I can build on into something else more useful, but that is what is fun for me. It’s not about it simply being an intellectual exercise, it’s about learning and gaining a deeper understanding of exactly what is going on in how these things all work. It is why I am interested in this as a hobby. It is what I enjoy. I don’t actually need to do any of this. I don’t do all this simply to get an end result or I would be more limited in my thinking, as you are.

What is baffling is why you are so insistent on whining and complaining about my question. You should think about the reason for that - carefully.

Hi BT. Did you figure it out?

Cheers

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.