Is there a Telnet interfacer

Is anyone working on a Telent interfacer for emonHub?

I’m using an esp01 as a serial link over WiFi, to transfer data from one of Robin Emley’s 3 phase PVdivert PCB’s. I can telnet from my PC to the esp01 and receive the data stream.

Currently I’m using a hard serial link and the directserial interfacer to emonHub which gives a 3 phase feed of power and voltage. I’d like to use the esp01 as the serial link by opening a telent link from emonHub.

Chriss

No. It’s not really clear what you mean. “Telnet” is a protocol for running a virtual terminal over a serial link. It includes control codes for things like flow control, screen drawing, cursor movement, etc. It’s not 8-bit clean and is certainly not the right tool for whatever you’re trying to do. Can you describe more specifically what it is you’re trying to achieve?

If you want to transport a serial link over a LAN, maybe over TCP, look into something like socat and the Socket interfacer or the Serial interfacer directly.

1 Like

Hi Bruce, thanks for replying.

The Telnet server I run on the ESP01 is a cut down very simple server, it runs to about a dozen lines of code and a couple of library calls. All i’m interested in is plain printable ascii, no control or flow control, i’m sending 30 odd characters every 2 seconds with an input baud rate of 9600.

I’ve been using this code for a while as a simple way of having a wireless serial monitor, displaying with putty or other terminal display, 3 wire in, it just works.

This is an example of what emonHub receives on node 99.

SerialDirect 267 NEW FRAME : “99 91 417 88 242 244 242

I agree I could set up a socket server on the ESP01 but I doubt I’d do it in a dozen lines of code! SerialDirect would do just fine if there was an ability to open a Telnet link on port 23 rather than just the serial port on /dev/usb0.

I’ll keep playing.

Chris

Does it not just need an interfacer that uses the Telnet Python client to read the data?

Have you looked at the socket interfacer for emonhub? It already sets up a socket server, you would just need to create a socket client.

If you search for socket interfacer here on the forum you will find one liner commands for bash and simple python examples, I’m confident that you could perhaps create a socket client in just a few lines. Although I don’t know that for sure, I don’t use esp’s.

Once you are able to send a string to a port user defined in emonhub you just need a string in the space separated format of (optional) timestamp nodeid val1 val2 etc with a trailing newline and carriage return.

It is by far the simplest way to get data into emonhub from custom scripts and devices. I use this method before progressing to any new interfacer.

Brian, Sorry I’m not a Python guy, my C and C++ is just about passable, I wouldn’t know where to start writing my own interfacer :frowning_face:. But it’s early days, I think I have a python book around here somewhere maybe I’ll try learning a new skill :smiley:

But thanks for the pointer I’ll maybe take a look at the source of one of the other interfacer modules.

Chris

Hi Paul,

Yes I did look at the emonHub socket interfacer but haven’t got any further.

I guess the telnet esp01 code is reversed in that the server is at the other end, it just sits there waiting for a connection, when it gets one it then just sends a line of ascii data every 2 secs, doesn’t really care if the other end reads it.

Currently I’ve just hardwired a serial port from the monitoring hardware to the pi, so I know the transfers are good and I’m getting good graphs. It’d just a pain having the Pi tethered.

More experimenting required :smiley:

Hi Chris,

I’m struggling to follow, but I get the feeling you’re overcomplicating this. It’s either a physical serial line or it’s a simple TCP connection. I really don’t think you need anything more. Emonhub has interfacers for both.

My main point originally was that you almost certainly don’t mean telnet. You might be running the telnet command, but not only are you ignoring the vast majority of features it adds above a raw TCP socket, it will actually go badly wrong in certain circumstances. If you use something like nc or socat can you reproduce what you have? If so, it is trivial to use the Socket interfacer, just give it the IP and port number.

If you are really using telnet, well it’s 2021, you’re on your own… Sorry.

Bruce

I read your posts again (I should really do that before posting, but I’m only human) and I think I have a better understanding and I think you can do this with standard linux tools and emonhub. I ran this:

socat TCP:localhost:8001 TCP:localhost:8000

and then arranged for another socat to listen on port 8000 and a third to send data to 8001. The data appeared on the socat listening on 8000. All you need to do is arrange to run the above socat as a system service (use systemd) and emonhub to listen on an appropriate port.

A service file like this will probably work:

[Unit]
Description=Proxy between emonhub socket and esp01 PVdivert
After=network-online.target emonhub.service

[Service]
Type=exec
ExecStart=/usr/bin/socat TCP:esp01:23 TCP:localhost:8000
Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target

Put it in /etc/systemd/system/socat.service and run sudo systemctl daemon-reload followed by sudo systemctl enable --now socat.service.

You’ll need to set up the emonhub socket interfacer to listen on port 8000 (or whichever port you choose, but it must be >1023).

Hope that helps,
Bruce

Hi Bruce,

Thanks I’ll definitely experiment with socat and check out your suggested solution.

I agree telnet is not a modern protocol, but it is fairly simple and generally just works. Putty and many other terminal emulators support serial, telnet, ssh and other protocols.

If I have and Arduino project where I want to do some serial debugging but don’t want to run the IDE or the target is a long way from my desk its very handy. Just plug in the esp01 in the place of the FTDI and you have a wireless serial port.

Chris

OK, but I still maintain that what you mean is “Raw” protocol, not telnet. From the PuTTY docs:

https://the.earth.li/~sgtatham/putty/0.74/htmldoc/Chapter3.html#using-rawprot

If you need help with socat give us a shout.

Bruce