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