Man-in-the-middle Raspi


I thought I would make an attempt at inserting a Raspberry Pi Zero W into the serial communications line between the Raspberry Pi 3 and the RAMPS board. "Why would you do such a thing?", you might ask. Well, that's a good question...

If I can get this serial-to-serial gateway to work, then I hope to do some interesting things with it. The Raspberry Pi Zero W isn't too expensive at $10 plus the perhaps $8 for the microSD card and another perhaps $5 for a USB cable. And yet, why would I want to spend another $25 on my rig like this?

Because it will be interesting, I suppose. Maybe something big could come out of this.

[x] Get a Raspi Zero W, micro USB cable, 4GB microSD card and Raspbian Stretch Lite image
[x] Set it up in dwc2 mode, remote in, configure things initially, setup wi-fi and change hostname
[x] Get a Raspberry Pi 3 B as test rig, power adapter, 16GB microSD card and OctoPi image
[x] Set it up, remote in, configure things initially, setup wi-fi
[x] Connect the two via GPIO pins and test with minicom to verify that this part works
[x] Add screen so that I can setup a monitor to watch the Zero's output and adjust the resolution
[x] Adjust the settings manually in ~/.octoprint/config.yaml to select /dev/ttyAMA0
[x] Confirm that OctoPrint will attempt to connect to the Zero when the Connect button is pressed and that the Zero sees this in the minicom session
[x] Install Node v8 on Zero and express-generator
[x] Scaffold Node JS app with raspi and raspi-serial as dependencies, console.log()'ing inbound serial
[x] Send serial data from Raspi3 via GPIO pins 8/10 to the new service
[x] Connect in the RAMPS board and do and end-to-end test with OctoPrint
[x] Move the rig to the printer for a full test while printing
[x] Created encryption/decryption methods in JavaScript for obfuscating the extrusion amounts in a GCODE stream using hashes generated with Keccak-256
[x] Modified encryption method to accept Ethereum transaction hash and MAC address of recipient, modified decryption method to read transaction hash from file and to determine its own MAC address, both methods now generate new combined hashes for the cryptography involved
[x] Introduced new GCODE M888 command for communicating transaction ID

Not bad so far. I seem to have the Zero as a communications endpoint for OctoPrint, at least.

Raspi3 Zero RAMPS <-- 24V Power Adapter
PWR <-- ------------------------------ -- 5V pins
GPIO <-- --> GPIO
"USB" <-- adapter <-- --- Type B cable
USB ----- -------> "PWR"
micro HDMI --> display

With the barest code of all, it appears to be working.

Perhaps you can tell from the wiring what's going on. At the moment, I have to throttle the GPIO-based serial to 9600 but that's not a big problem, to be honest since this is just a prototype.

There's a small glitch in that when OctoPrint disconnects it just basically ignores the RAMPS board rather than to issue an "M155 S0" before doing so. Other than that, it's reasonably well behaved.

I just moved the rig to the printer and it successfully printed a six-minute part. I worked on the web interface a little but it's nothing too fancy.


Depending on what you want to do there, you might want to rather look into a micro controller instead of a Zero W. I think you really want real time processing for any kind of proxy/man-in-the-middle work instead of having to wait for the underlying OS to give your process priority. Throw in an ESP32 (or even use that as the µC) and you also get WiFi and at less cost.

But again, depends on what exactly you are thinking about doing.


Whatever you're doing sounds like it might be fun :smile:

I've got a spare Pi3b, and I just ordered another pi0w and an arduino board, and I've also got one spare pair of L293 controllers waiting for a purpose. Oh, and some fans and some other stuff. Probably need another box of Tic Tacs too

I'll be your guinea pig

I'll let ya know when the parts come in


I'm thinking that this needs to be super user-friendly. As in, there's something like a Raspi Zero with an enclosure with the two cables already connected and sticking out both ends. You'd put the Type B side into the RAMPS board and the Type A side into the Raspberry Pi 3. And then, it just works (with startup scripting to make things seem easy).

I'm sure the same could be created out of other components like the ESP32, though.


Ok, I'm thinking this is gonna have to be bigger than a Tic Tac box

I just looked at the ESP32, they've only got one USB port.


Just run a couple of Arduino micros (32u4's) with an adapter, connect them to each other via one SPI bus and to the RPi via the other. The code is easy to write and then you get real-time passthrough with on-die USB in both cases (use LUFA to write your USB code), and you have the processing power of the RPi, such as it is, to supply any kind of analysis and UI for visualization. If you want to productize it, stick 2 32u4's on a hat with the right connectors, et voila!


Why not use an esp8266? Cheap and easy.
Projects like this (github) already have solved that problem.
Try googling for "serial wifi bridge".


Actually, the development is coming right along. Here's the rig I'm working with today and attempting to go for the through-test to the RAMPS board from OctoPrint. I'm using Node JS for the man-in-the-middle service. Hopefully this table makes sense.

Raspi3 Zero RAMPS <-- 24V Power Adapter
PWR <-- ------------------------------ -- 5V pins
GPIO <-- --> GPIO
"USB" <-- adapter <-- --- Type B cable
USB ----- -------> "PWR"
micro HDMI --> display



Pushing part of this communication to wifi might save the GPIO cabling, come to think of it. I can imagine dropping the cumbersome GPIO-GPIO setup for what I'm working with.


Hey !

I just got a box of... stuff. It's not the whole thing I ordered, but it's a bunch of it, including the new ATX power supply that I suspect I'm going to be spending the next few hours wiring and soldering and rewiring, and resoldering, and then realizing that I screwed it up and should have done something completely different cuz I overcomplicated the whole thing


Oh, I also got the arduino, but no Raspberry Pi 0 W yet, and no idea when that one is coming

I'm headed down to the lab right now to try and electrocute myself, cuz that's always fun


Let me know if you need help wiring a switch to make the power supply turn on. (Unless it sees a closed circuit to the non-existent motherboard's ON switch, the power supply will stay off.)


Well, actually, I'm planning on replacing the existing (original firestarting) power supply on the Anet A8 with the one I just got, and I was hoping that the RAMPS board would provide enough of a load to enable a software on

And as to the software on, I was also planning on using the gcode Systems Command thingy to create another OCTO command, like, maybe OCTO101 for on and OCTO100 for off, or something equally as hopefully logical that I could also access by another program, if you get my drift... :wink: One that would leave the Pi itself active, but only turn off the printer itself

I'm gonna leave the Pi on a separate circuit cuz I can't remotely turn the printer on if the Pi isn't already on in the first place to send it the signal to turn on in the second place


Yeah, I was about the mention the chicken-and-egg with respect to trying to throw an OCTO801 from a computer which is technically off.


Right, thanks for pointing that out :wink:

I'll keep that in mind while I'm busy trying to electrocute myself

Just as a point of interest, I DO have a fire extinguisher placed strategically right in between both printers.

Not that I ever expect to use it mind you, especially if I get electrocuted first

I'd probably be too busy at that point I think


If you get electrocuted, give us "the sign" by which here means to fall on the ground and twitch. /LemonySnicket


I have to burn myself with the soldering iron first so that the wires are in proper order, THEN I can at least be in a position to have a reason to start twitching

If you don't hear from me by tomorrow, you'll know why

If something does happen, I want my body donated to science

The carbon dating alone should keep them confused for years


@Spyder As Indiana Jones once said "it's not the years, it's the mileage..."


I got a couple of parsecs of rugged road here pal...

Interesting development. It looks like one of the 5 volt rails stays on when you do a software off. Obviously not when you hit the actual power switch, but, I'm thinking I could use THAT to run the Pi...

We'll see


Well, it's finished. I couldn't find anything to copy, so I did something completely ridiculous

But it works. I can power the printer on and off while the Pi is being powered by the same power supply as the printer, and I can use Octoprint to remotely control the power

All items (except the firmware upgrade) have been checked off the list :slight_smile:


Well, there you go. I wasn't aware that an ATX power supply kept the 5V logic bus on at all times but you learn something new every day. :+1: