ESP support (connection over wifi)

Hi! Is there a way to use ESP8266 with klipper? I can add to my printer just a small ESP-12E (or similar) and connect it to my home server (where klipper and other services are) via wifi and my printer became wireless. I tried ESP-link and socat but it was unsuccessfully. Anyone wandered about this feature?

Not too sure what you are trying to do. Please define “…and my printer became wireless…”

Do you want to replace the printer’s control board with the ESP8266 ?
Do you want to substitute the Raspberry Pi with a ESP8266?
Or do you want to control the power supply of your printer with the ESP8266?

The first option might be possible with a lot of work, for the second option forget about it.
The third option is easily doable with a relay.

1 Like

Sorry for misunderstanding.

I have:

  • Ender 3 with stock control board;
  • ESP 8266
  • Server (not raspberry) running debian with klipper on it and many other programs.

I need to establish the following connection:
Printer control board - ESP - wifi - TCPtoSerial - klipper.

With this connection I get:

  • No need to buy additional raspberry to run klipper on it (because I have home server that can carry klipper and many other things);
  • No need to keep my server near the printer (no usb cable);
  • Printer becomes more mobile: I can take it wherever I want within wifi coverage area and presence of an outlet.

Ah! ok now I understand.

Although I am sceptical on the reliability of such a setup, you might want to have a look at Esp-Link project. GitHub - jeelabs/esp-link: esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer . and this youtube video Using ESP-LINK (ESP8266 Wi-Fi to Serial Bridge) to program an Arduino UNO over Wi-Fi - YouTube

I am very interested so, please keep us informed of your progress.

1 Like

I’m also skeptical of the reliability of this setup, and I would note that a Pi Zero W is not that much more expensive than an ESP8266. It also solves the other 2 goals you have in mind. The Pi eliminates the need to use your server at all, and it makes the printer accessible via wifi.

Look at Espeasy / serial link. On the server side you could use socat.
But this is not guaranteed to work over wifi, timinings are really important.

@lawashnik I’m curious how you got on with this idea?

Im curious aswell. Have you tried Serial-to-WiFi Tutorial using ESP8266

?

This sounds interesting! Can we brainstorm on how this can be implemented on serial without even touching Klipper if that is an initial step of possiblity?

Greetings.
In fact, this scheme works great. Personally for myself, I made my 3D printer controlled by klipper via Wifi.
The initial data are as follows: FlyingBear Ghost 5 as a 3D printer with a native board (MKS Robin Nano 1.2) and a native Wifi module (Mks robin wifi) flashed with its own firmware (analogue of Serial2Wifi).
As a machine with klipper, a server based on SuperMicro X8DTL-I (two Xeon E5630) with a simple wifi adapter (like this) is used. You can use the usual PC because, the load is extremely small.
Wifi module works in station mode.

Of the changes:

  1. It was necessary to modify the MCU firmware so that it will automatically enable the Wifi module on the board.
  2. for a server with klipper, socat was used to redirect traffic to the MCU. For good, you need to add another type of connection to the MCU - over the network.

Printing is stable. The last big seal lasted 9 hours.
If interested, I can send more information.

Hi! Thank you for your post. I start this topic about 2 years ago, the configuration of my printer changed since then. But I think this question should be answered. So if you want you can provide us a step by step tutorial, this will be a good work. I think the main questions are:

  • how to set up socat on server side (because when I tried socat I couldn’t get a good result);
  • how did you modified the firmware (if modifying is necessary);
  • what is your printing speed? Is connection stability depends on printing speed?
    -are you using wifi router or direct connection?

It’s great that my work is still relevant.
In fact, I took an already existing idea as a basis [How To] Wireless Klipper Printing - YouTube
The only thing that did not work well for the author of this video was the communication channel in station mode.
It seemed strange to me. this mode is implemented at the hardware level.
The problem turned out to be in the esp8266 mode enabled by default (i.e. in the call to WiFi.setSleepMode(WIFI_NONE_SLEEP);).

Okay, let’s go sequentially.
I used MKS Robin Nano 1.2 (from FlyingBear Ghost 5) as MCU. The 3D printer came with the MKS Robin WiFi WiFi module.
Pins PA9 / PA10 were chosen as the port of interaction with Klipper (which is logical).
In order for the WiFi module to work and transmit data, it must be turned on. The corresponding code was torn out of the Marlin firmware and put into the UART initialization procedure. (see Attachment)

Next, you need firmware for the WiFi module itself, which would establish an accurate WiFi connection and raise a tcp server to send data to the UART.
I was interested in researching esp8266 and wrote this firmware myself (see attachment). The firmware was written using the Arduino IDE.
There is a lot of information on how to assemble the firmware using the Arduino IDE and flash it into esp8266 on the Internet - I will not repeat it.
Will I clarify one moment - so far this firmware is just a sketch, which still needs to be completed but in a more normal state.

Now about the counterpart on the PC. Klipper works primarily with the serial port. Based on the total, we use socat as a classic serial2tcp translator.
I ran it through the systemd service, on which the klipper service depends.
The speed of interaction with klipper left by default. The documentation for klipper says that this is enough.

Socat’s startup options are as follows:
socat -dd pty,link=/home/klipper/printer_fb5_data/comms/virtualcom,ispeed=b250000,ospeed=b250000,raw,echo=0 TCP4-CONNECT:192.168.2.34:8888,nodelay,forever,interval=1

Now a little about the stand itself.
There is no router in the room where the 3D printer and PC are located. It is simply not needed there and its role is partially performed by the same PC. Thus, the PC itself acts as a WiFi access point.
WiFi is distributed via a small USB adapter (written above) without a visible antenna. The distance from the printer to the PC in a straight line is about 3 meters.
Based on the fact that nothing happened with the printing of the model in 9 hours, we can conclude that WiFi itself works without problems.

However, there are subtleties in my current implementation.
When a WiFi module is connected to an access point on a PC, it is given an IP address via DHCP.
In my current configuration, this address is not static (yet), but it can be done, and in various ways.
One of them is to make sure that the module’s WiFi address is written in it itself or configured somehow (via http for example).
This has not been done yet, but I plan to do so in the near future.

It seems to have answered all the questions.
klipper_over_wifi.zip (3.2 KB)

1 Like

Hi all, I am newby on klipper world and I am trying to connect my Pc running Ubuntu on WSL to mcu on MKS robin nano v1.2 with a MKS wifi module too. By now, it is working by USB but I have decided to give this topic a try.
I have flashed firmware on MKS wifi module and seems to be working as it connects to my home wifi while attached to a breadboard.
Also I have modified original “serial.c” file by patching it with the file attached file.
However I am now stucked obtaining firmware.bin. Hence, when I run “make” on Ubuntu some compilation problems raise (see attached picture), related with “udelay” function non declared and some type mismatching errors on struct forms.
As firmware.bin is finally assembled on klipper/out folder, I flash my printer with SDcard, nonetheless, printer enters in loop-booting status.
Can anyone here give me a hand on that? I would really appreciate because my programming aknowlegde in C nor python is quite bad, just the simpler commands.

Thanks in advance

Hello @Caiman !

It appears that you missing the point of this thread.

This is about running Klipper on a ESP8266 MCU.

You run Klipper on a PC and an MKS board.

Please open a new thread with all the requested information.

BTW: You will have issues getting connected to a printer board from an OS within a virtual machine. It’s about real time communication.

Hi, thanks for your quick reply.
I thought this configuration should work as mks wifi module is esp8266 based and Apollo commented few lines above that It should run on a PC as It has low resources consumption.
If that is not the proper thread sorry for the missunderstanding.
Taking advance on this, Does anyone know if there is any kind of thread or tutorial that could fit with my purposes?
I have been searching for a long time but no good results,
Cheers

I’m not sure what you are trying to achieve. Is it:

Printer-board → esp8266 WIFI → Windows → WSL → Klipper host?

If yes, then I’m pretty sure that this is not going to work:

  • As indicated by @EddyMI3D: Klipper does not support virtual machines. Can work, but likely strange issues
  • Klipper host software relies on very strict timing between board and host. This setup (even without VM) is very unlikely to fulfil this requirement

IMO, this is unnecessary complexity compared to a dedicated Klipper SBC that in the end will offer no real added value but a lot of issues. YMMV

Hello Sineos,
Basically this is the idea, yes.
My actual configuration is:
Printer-board → USB → Windows → WSL → Klipper host
and wanted to replace it with the sketch you commented:
Printer-board → esp8266 WIFI → Windows → WSL → Klipper host

By your comments I assume this idea is not as easy as I thought initially, thanks for clarifying.
I will give this config a last chance and if not iI´ll consider SBC option.
Thanks all,

Well, finally is working and I tested homing, stepper motion, heating bed and extruder good expectatives (not more features tested since now because I am currently with some hardware modifications on my printer)
In my case, problem was programming issue, due to compiler was taking wrong “gpio.h” file.
I will work in this mode and let´s see how it behaves.

Hi all.
Posted the source on GitHub - apollo80/wireless-klipper: Firmware for MKS Robin WiFi (esp8266) - organizing a klipper <-> wifi <-> mcu bridge

  • Added Web-interface for module configuration. It is only available when no one is connected to the module.
  • The firmware can update itself - you need to click on the firmware version. There is no beautiful interactive update process - JavaScript is not trained.

Medium tested - works and updates on my Flying Bear Ghost 5.

Please send me all the info, where to get the info, firmware I have been trying to figure this out for months, I’m just a big dummy though, I’m building a 10" touchscreen tablet for the rpi4 and I almost gave up until now, my board isn’t recognizing usb anyway so if I can get this to run I would just about die from actually finishing what I thought was a lost cause, have a mks wifi chip on a btt octopus v1.1, and an rp4b, but also have a btt pi with the can bus connector so I can hopefully get klipper to see mcu, usb no worky… can bus to usb, maybe, but I have 2 usart connections on the wifi chip so I figured there had to be a way to make this happen… any help would drastically needed and I will worship you forever as my savior… thanks in advance