Posted

Puh, that was a day.

I was changing things on a drawing and then saved it accidentally as another existing file. And worse, I accepted the dialog for overwriting. Yeah. Fxxk.

Ok. I did a huge mistake. But, still, maybe there is a way to get back the file. Luckily, the software I use for drawing 3d models uses an JSON formatted file and I remembered at least one word that shall be in the file(LedHalterArm).

After a bit of research, I found a way to read out what’s still on the hard disk.
First, I moved the file that I have overwritten and gave it a new name:

mv GameboyBeleuchtungV5.d3ddoc GameboyBeleuchtungV5.d3ddoc.bak

That shall remove the link to the part of the hard disk.

The next task was to find the position on hard disk, for that a unique string should be used and makes the search easier.

grep -a -b "LedHalterArm" /dev/sda3

Unfortunately, I already exported this as STL file so it gave me mostly unrelated results but some of them seemed to be possible. I got some results like
123123123: "name": "LedHalterArm"

Ok, let’s try again with the more specific search term.

grep -a -b "\"name\": \"LedHalterArm\""

Here, we are, I’ve got 3 results and took the last one as starting point.
48020388426:                "name": "LedHalterArm"
94465072989:                "name": "LedHalterArm"
94465073068:            "name": "LedHalterArm",

Let us see what is there:

dd if=/dev/sda3 count=16 skip=$(expr 94465073068 / 512)

Yey :) I’ve got at least the file contents from the point of “LedHalterArm” to the end. From here now I have to go back on the hard disk until I reach the beginning of the file. This process took the most of the time, because I did it step by step.

I reduced the expr value by 512 and increased the count by 1:

dd if=/dev/sda3 count=11 skip=$(expr 94465072556 / 512)

Later on I increased the steps by factor 10 then factor 50 and finally I got the whole text. For easier handling I added a clear command to the front, with that I didn’t need to care about where the beginning is of my result. Just scrolled up.

clear && dd if=/dev/sda3 count=336 skip=$(expr 94464908716 / 512)

So, I copied the relevant part from the console into a file and saved it. It worked.

Author
Categories Linux

Posted

I’m implementing a server based on Kotlin and Ktor. The goal is to send a gcode file which the receiver, a raspberry pi 1B, shall transmit to my ender 3 printer. To see the current state I used WebSockets at first. This went really well but to be honest I don’t need the overhead which comes with WebSockets because I only want to send states to whomever listen. So, the next possibility was Server Sent Events.

Server Sent Events are available for years now but not really present in people minds, so in my. However, there are a few tutorials and references to that and it was not hard to implement such events beside of one thing: Custom Message IDs.

The most tutorials to such scenarios propagate that you can pick whatever Identifier you want and just add a message listener for that. But that doesn’t work as easy as it sounds. Maybe, there is a way by implementing an own EventSource class but for that I am not experienced with JavaScript.

Just to have a bit more context. The EventSource class is in highlevel responsible to create the connection and wrap the events to a MessageEvent. One can register to:
EventSource::onopen
EventSource::onclosed
EventSource::onmessage

EventTarget::addEventListener

Usually, one would take addEventListener and put in an identifier and a function, but as said before that doesn’t work. In a forum one said that all unknown identifier will be delegated into the onmessage channel.
However, regardless which message identifier I chose, it every time landed in onmessage.

To overcome this I wrapped my data class into another with the fields “Identifier” and “Data”. So, now I can use a switch case and every message gets processed by the correct function.

Would like to know that earlier, it took me 2 days of reading references and for the workaround 5 minutes.

Author
Categories Programming, JavaScript

Posted

For my 3D printer watchdog project, I am using Kotlin with IntelliJ. To avoid the hassle of uploading and remote debugging, I use the Embedded Linux JVM Debugger for Raspberry Pi plugin for IntelliJ, which is very straightforward.

On the other side, I use a Raspberry Pi 1 Model B with DietPi installed. DietPi v9.5.1 (Linux 6.1.21+) comes with Dropbear installed as the default SSH server, but this doesn’t work with the plugin. Running an application with that combination results in an IOException (-1).

The reason for that seems to be the missing SFTP service, which, as far as I know, is not available with Dropbear.

However, switching to OpenSSH with SFTP solved that issue.

Author
Categories 3dPrinter, Intellij

Posted

As I calibrated my printer, I observed a kinda strange issue. While moving my Z axis up and down repeatedly, I measured different lengths. Up and Up gave me exact 10mm. Down and down another 10mm. But sometimes it measured only 9.8mm. So, what was wrong?

After some testing, I figured out that it only happens during a direction change. This means I can lift my Z-axis by 10mm as often as I want, but the next time I lower the Z-axis, it will measure 9.8mm.

For a system with gears, I expected this because gears need to have some space to fit inside one another. Therefore, the space will cause such behavior. But with a direct-driven Z-axis, this was unexpected.

I don’t think that this was because the screw was worn due to the weight of the X-axis, which is hanging on it with some pressure. So, for me, the current drop during direction change could be a reason.

However, the Marlin firmware can handle this if it’s not a mechanical issue. Search for BACKLASH_COMPENSATION to enable it.

Author
Categories 3dPrinter

Posted

This is a wonderful laptop and since it has a lot to give and was laying around I decided to use it as server.

Shutoff display
One problem to solve was that the display stayed on all the time. To solve that, I had to insert the command consoleblank into the GRUB command line:

GRUB_CMDLINE_LINUX="consoleblank=30"
That will switch off the display after 30 seconds. To do that I opened /etc/default/grub with an editor. And inserted “consoleblank=30” into the already existing line:
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="consoleblank=30"
after that call:
update-grub

Disable action on Lid changes
The second thing I wanted to disable was the action for lid changes. Since I don’t want to open or close it all the time, but there may be a time, I have to move it to another location. To disable that action, I opened /etc/systemd/logind.conf with an editor, removed the hashtag on all lines that contain the word HandleLidSwitch, and changed the values to ignore:

#HandleHibernateKeyLongPress=ignore
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
After that, call:
systemctl restart systemd-logind

To test the changes, I rebooted the server.

Backup drives
Since I have a backup drive from a former Proxmox installation, I wanted to add it again. First, I wanted to mount it. To do so, I used fstab and the mount command. But before I could start, I needed the UUID and the folders prepared, so I created a folder in /mnt/:

mkdir -p /mnt/backup
To get the UUID and the file system type, I called lsblk in the console with some self-chosen columns:
lsblk -o name, uuid,type,size,tstype

Then I inserted the data into fstab:

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/backup ext4 defaults 0 0
After that, reload:
systemctl daemon-reload
Let’s test:
mount -a
ls /mnt/backup

It should show the contents of the disk. Then, add it as directory to storage.

Author
Categories Proxmox, Post Installation