Dev Diary: What it took to convey Wi-Fi assist to Authentic Prusa MINI+

The 4.4.0 BETA2 firmware for the Authentic Prusa MINI/MINI+ is out on our GitHub web page and a very powerful new characteristic is the assist for Wi-Fi connections. And there’s no different option to put it: It took us a very long time to ship what was promised. It’s been a protracted sophisticated journey. We hit a number of useless ends, we needed to discover workarounds for {hardware} limitations – and we’re nonetheless not completed but. Nonetheless, the assist for wi-fi add of G-codes and distant administration of the MINI is working and we will lastly speak about what we needed to do to get it to this stage.

Including Wi-Fi to the MINI+

The Authentic Prusa MINI+ is an reasonably priced but very succesful machine. When the {hardware} staff was designing it, the important thing was to discover a steadiness between the variety of options and value. Additionally, supporting all of the encryption fashions of recent entry factors can be inconceivable on the present CPU of the MINI. For this reason the Wi-Fi chip wasn’t embedded within the motherboard.

So as an alternative, we went with the thought to add a easy header onto the motherboard that may enable the connection of an inexpensive ESP-01 board, turning the exterior microcontroller right into a bridge between the wi-fi community and the USB drive. We did the analysis and located a number of open-source tasks coping with the networking capabilities of the ESP-01, so the mission was a go.

What’s an ESP-01? It’s a cheap Wi-fi module consisting of a TCP/IP stack together with a built-in microcontroller. Its major perform is to convey wi-fi communication to embedded tasks. It acts as a standalone microcontroller so it doesn’t require some other microcontroller (like Arduino or Atmel) to be able to use its I/O pins. Mainly, it’s a wireless-to-serial bridge with 1MB flash reminiscence, a low-power 32-bit CPU and assist for 802.11 b/g/n Wi-Fi networks. It’s been an extremely widespread and reasonably priced answer since 2014. The Authentic Prusa MINI/MINI+ helps each the ESP-01 and the marginally modified model ESP-01S – extra info could be discovered within the changelog.

We began engaged on the MINI’s Wi-Fi assist close to the tip of 2020 with the intention to do the programming half correctly from the start as an alternative of simply slapping a bunch of code collectively and releasing it in a rush as a result of that may imply we must rewrite all the pieces from scratch anyway, ultimately. We assembled a devoted staff that was tasked with a correct evaluation of the complete mission and prototyping of the wi-fi answer.

Let’s do it correctly

From the beginning, we have been in search of a fancy answer that may assist not simply easy transfers of G-codes through the native community however would even be suitable with our (then upcoming) PrusaLink and Prusa Join farm administration software program. The plan was to create a steady TCP/IP stack for Ethernet and Wi-Fi, have the choice to make use of BSD sockets and use an utility layer – a web site with remote-control capabilities operating on an HTTP server instantly on the printer. The staff acquired the complete task and began working.

One of many key concepts was to hold the present firmware of the ESP-01 intact. There are a selection of various ESP-01 variations and programming (and sustaining) our personal firmware for these microcontrollers was assumed to be an overkill. There’s already an LwIP stack for the ESP-01, which takes care of SLIP (Serial Line IP through UARTs), NTP and static routing. First, we tried including a parallel IP stack and LwESP, which is a light-weight ESP AT command parser library. Utilizing an open-source answer appeared like the suitable method.

Nonetheless, that is the place we began hitting useless ends. There are numerous firmware variations for the ESP-01, every with a barely totally different set of functionalities and ranging ranges of high quality/reliability. It additionally meant we needed to add a large quantity of code within the Buddy’s (MINI motherboard’s) firmware due to the LwESP library. Ultimately, it will imply to have two parallel IP stacks (one LwIP for ethernet and one other one cut up between Buddy and ESP) and change between them as needed.

And there have been extra issues – solely 5 connections, lacking assist for a UDP server and numerous different points. In concept, we may make it work in some way, however testing and debugging it will be a nightmare. Nonetheless, our colleague from the SLA staff discovered a reasonably ingenious answer – he put collectively a particular, light-weight custom-made firmware for the ESP-01.

The Eureka! Second

So, lastly, we had a prototype of a tiny particular firmware that turned the ESP-01 right into a community interface, one thing just like the Ethernet chip on the Buddy motherboard. It was one thing we actually wanted: a step in the suitable course.

After which, our staff acquired a brand new reinforcement. To cite a basic film: an individual who has forgotten extra about networking than all of us will ever know. And in addition a extremely expert C++ architect! He picked up the place the earlier makes an attempt ended and began with a model new evaluation. It took him merely a month to implement a versatile and efficient HTTP server that’s able to streaming request responses (i.e., it suits the restricted RAM irrespective of how lengthy the response is).

His colleague picked up the custom-made firmware and began evolving the ESP-acting-like-a-network-card prototype. First, he began with the wi-fi connection and related the ESP through UART (serial interface) to a regular laptop computer. This fashion, we achieved speeds of as much as 9/6 Mbit (obtain/add). We lastly had a dependable wi-fi reference to a pace surpassing the max throughput of the MINI’s UART interface, which is 4.6 Mbaud.

Connecting the ESP to the bodily layer interface within the LwIP stack of the Buddy firmware introduced not solely code financial savings, but in addition eradicated the aforementioned schizophrenia of combined IP stacks for 2 totally different interfaces. Issues began wanting actually good.

Cursed USB drives

We have been making nice progress. The HTTP server was coming alongside properly and we began including extra options – like importing G-codes from PrusaSlicer and downloading G-codes from the printer. We added a brand new file browser with thumbnails within the internet interface and applied print begin/cease features (and several other others).

By April 2022, we had a steady wi-fi connection and the firmware was virtually prepared for launch. There was just one factor left to unravel. It was, sadly, a serious difficulty: guaranteeing the soundness and compatibility of assorted USB drives – from the most cost effective Chinese language no-name fashions to branded USB disks. Just a bit curiosity: most of the low-cost Chinese language no-name disks really labored extra reliably than dearer fashions. 🙂 Both method, we needed to clear up incorrect timeouts within the USB driver first. We managed to deal with that in cooperation with STM. However then there was the opposite factor, one thing really diabolical. Whereas SD playing cards have very clearly specified response occasions, USB disks haven’t any such factor. They will go “silent” even for dozens of seconds, plus there’s one other factor referred to as “housekeeping”.

To place it merely: USB drives are made to work principally with customary computer systems – like laptops, media gamers and online game consoles. These machines have insane quantities of RAM (greater than 1 MB :-)), so if you begin to copy recordsdata onto a USB drive and it stops responding for a number of seconds, there’s nonetheless a big buffer that helps to beat this delay. “Housekeeping” is one thing the USB drive does robotically, it’s a routine answerable for the inner copying of knowledge blocks to unfold the extent of damage roughly evenly throughout the flash reminiscence to lengthen the lifetime of the storage system. Nonetheless, this “sorting” takes a while.

Sure USB drives are so badly designed that they’ll cease responding for as much as 10 seconds. We allotted 10 kB of RAM on the Buddy motherboard to function a buffer and thus we suppressed this downside. Whereas it’s theoretically attainable to add G-codes even throughout energetic print jobs, it’s not really useful to make use of this perform attributable to efficiency points.

And eventually, we needed to clear up the problem with the FATfs library. This library is primarily used for embedded gadgets and it tries to hold the filesystem as constant as attainable. Which means each time a fraction of a file is written, the drive’s chip begins updating the principle and backup FAT desk. That is one other efficiency killer which is able to ultimately decrease the lifespan of the USB drive. Fortunately, we discovered an answer: when you begin importing a G-code file, we already know the overall file dimension – so we merely ask the filesystem to order house for the complete file first. As soon as the add is completed, solely then the FAT desk is up to date.

The street forward of us

The present 4.4.0 BETA firmware already gives superior community performance and dependable G-code add. Nonetheless, we nonetheless have some work to do. We’re wanting into whether or not we will reliably stream G-code recordsdata when the MINI/MINI+ is printing. As defined above, we’re restricted by the expertise of USB drives and whereas streaming is theoretically attainable, there are nonetheless a variety of potential points.

We’re nonetheless bettering the code, so the present speeds are simply over 100 kB/s relying on the standard of the wi-fi connection and 300 kB/s on ethernet. There’s nonetheless some headroom left. In concept, we ought to have the ability to obtain about 460 kB/s uncooked pace on the UART/ESP. We anticipate the ultimate pace to be someplace between 250-350 kB/s when optimized correctly.

We might additionally wish to deal with making the complete expertise extra user-friendly. Proper now, you have to copy a particular INI file onto the USB drive which is a considerably barebones answer. It really works, however there’s positively room for enchancment. And we need to implement extra quality-of-life enhancements – like an precise sign energy indicator, for instance. Tell us what else you wish to see!

There are many totally different USB drives and numerous fashions of the ESP-01 module which can have an effect on the pace a method or one other. We’ll be very grateful in the event you resolve to check drive the brand new MINI firmware and tell us what gadgets (ESP and USB) you might be utilizing and what’s your expertise with them!

After all, the whole firmware together with the Wi-Fi ESP expertise is totally open-source and the supply codes are freely out there on GitHub. So, if you wish to mess around with the ESP, be happy to seize the supply codes right here!

And you’ll try the present firmware launch on our Github web page.


Leave a Reply

Your email address will not be published.