Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR code generation #10

Closed
solo2424 opened this issue Jun 25, 2023 · 36 comments
Closed

QR code generation #10

solo2424 opened this issue Jun 25, 2023 · 36 comments
Labels
Feature Request New feature or request

Comments

@solo2424
Copy link

I think a Barcode/QRCode would be very useful.

Being able to easily scan a QR code and be able to have the printer select that spool would be nice. You would need a way to select the printer first, maybe add a qrcode to the printer as well so you could scan that one first, then scan the spool. But a dropdown of printers would be just as easy unless you are running a farm. This may involve more interaction with the printer software then what is possible.

I know this would be a strech and may not be worth the effort, but if you could scan UPC and have it populate all the info it could pull from it, that would be amazing. But I don't know enough on how UPC codes work to even know if that data could be pulled.

@Donkie
Copy link
Owner

Donkie commented Jun 26, 2023

If you want it to also integrate with barcodes on a printer, it sounds like you want to add printers as a concept to Spoolman as well. Currently, Spoolman only cares about filaments and spools, not machines. But it's something I've had in mind.

@solo2424
Copy link
Author

solo2424 commented Jun 26, 2023 via email

@Donkie
Copy link
Owner

Donkie commented Jun 26, 2023

It sounds like that is something that could be entirely done in a frontend like Mainsail, yes.

I believe it's time to take this suggestion to them. They could likely integrate a QR code scanner directly in their frontend, since browsers nowadays support giving direct access to the camera.

@solo2424
Copy link
Author

solo2424 commented Jun 26, 2023 via email

@Donkie
Copy link
Owner

Donkie commented Jun 26, 2023

I think the QR code could be created in many different ways. It doesn't need any complicated setup, could just be a free-text encoding of like "spool:1" where 1 is the spool ID. Then you could generate and print the QR code in any way you like.

The above idea then only works for a setup where you first open mainsail for the printer you want to assign the spool to, and then scan the spool.

If you want a more fancy integration where you can first scan the QR code for a printer, and then the QR code for the spool you want to assign, it will be a bit more messy. Mainsail only operates with a single printer, so it wouldn't know what to do with you scanning a printer QR code inside mainsail. If this variant is desired, it would be something that needs to be more integrated with Spoolman itself.

@solo2424
Copy link
Author

solo2424 commented Jun 26, 2023 via email

@solo2424
Copy link
Author

I was able to get this working using the macros like Arksine explained in his last post on your thread. I have to say I am stoked that this happened so fast. I appreciate your efforts. More donation will be coming down the road. I remember going down this path about 6 months ago and being very frustrated that there were no solutions. I did not want to go back to Octoprint. Someone needed to take this project on, I am glad you decided to. And to get Arksine attention and have him make it work well with moonraker, That is just so awesome! Thanks!

To piggy back on one of the other request, a notification if there isn't enough filament would be nice. And I still would like for a QR code to be automatically created when the spool is created. I am sure I will think of other cool things that could be added in the future. Let's make this the standard for Klipper Spool Management!

@Donkie
Copy link
Owner

Donkie commented Jun 27, 2023

For your full spool management ideas, I think we'd need a more fleshed out investigation on what exact usecases the majority of users want etc. This could be discussed in a new issue. I only have a single printer, with a single extruder, myself, so it's a bit harder for me to understand where the pain points are.

Lot nr is a general term when dealing with manufactured materials. It is generally printed on the spool, could also be called batch nr. When making a big project that would require several spools of the same color, you'd want all spools to have the same lot nr, otherwise they could have variations in color.

Front ends will have to be manually updated in their own rate. I have created a feature request in Mainsail for added support. Not yet notified the Fluidd community though.

Notification if there isn't enough filament is something that would be done in the front ends I believe.

I could add a feature to the built-in client to generate a QR code for a spool. But let's first try to get some basic functionality into the front ends before diving into qr code scanning!

Glad you find my work useful!

@locki-cz
Copy link

Please add some box with spool colour to list to easy find, maybe link to vendor page and other info? :) PA settings?

@Donkie
Copy link
Owner

Donkie commented Jun 27, 2023

@locki-cz please create new issues, one for each feature request

@Donkie Donkie added the Feature Request New feature or request label Jun 27, 2023
@Donkie Donkie changed the title [Feature Request] Barcode/QRCode QR code generation Jun 28, 2023
@NonaSuomy
Copy link

NonaSuomy commented Jul 8, 2023

I did a proof of concept using the chamber camera worked for QR codes just not barcodes.

I tested this with

pi@mainsailos:~ $ wget http://IP/webcam/?action=snapshot -O qrcode.jpg | zbarimg qrcode.jpg
--2023-02-18 07:36:48--  http://IP/webcam/?action=snapshot
Connecting to IP:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [image/jpeg]
Saving to: ‘qrcode.jpg’

qrcode.jpg                        [ <=>                                            ]  28.89K  --.-KB/s    in 0.001s

2023-02-18 07:36:48 (24.7 MB/s) - ‘qrcode.jpg’ saved [29579]

QR-Code:
serial: 007
model: white
material: PLA
vendor: Prusa
density:  1.24
diameter: 1.75
total_weight: 970
spool_weight: 832
cost: 24.99
scanned 1 barcode symbols from 1 images in 0.18 seconds

You could poke Spoolman's code somehow?

image

sudo apt install zbar-tools
cd /home/pi/klipper/klippy/extras/
wget https://raw.githubusercontent.com/th33xitus/kiauh/master/resources/gcode_shell_command.py
[gcode_shell_command qrcode_snapshot]
command: wget http://IP/webcam/?action=snapshot -O /home/pi/printer_data/gcodes/qrcode.jpg
verbose: True
timeout: 2.
[gcode_shell_command qrcode_scanner]
command: zbarimg /home/pi/printer_data/gcodes/qrcode.jpg
verbose: True
timeout: 2.
[gcode_macro QRCode_Scan]
gcode:
    RUN_SHELL_COMMAND CMD=qrcode_snapshot
    RUN_SHELL_COMMAND CMD=qrcode_scanner

I tested regular barcodes on most spools with this code above and enabled all barcodes in the app's arguments but for whatever reason maybe my camera isn’t clear enough for the library. It just says it can’t detect any code. QR codes almost always work no matter the weirdness of what it’s having with what it sees.

To generate QR codes on the printer just use

qrencode -s 6 -l H -o "qrcodespool007.png" "spool:007"

@Donkie
Copy link
Owner

Donkie commented Jul 8, 2023

Integrating it with the existing printer webcam is a brilliant idea! How the frontends decide to scan and register the spool ID from the picture is up to them. But from my end in Spoolman I will still definitely add a way to create QR codes for the spools.

And yes, QR codes have a lot better error correction than regular old barcodes.

@NonaSuomy
Copy link

NonaSuomy commented Jul 9, 2023

I fixed the PoC code above to set the spool_id with curl which works like this now

Install ZBar

mkdir code
cd code
sudo apt install autopoint build-essential libv4l-dev libtool
git clone https://github.com/mchehab/zbar.git
cd zbar
autoreconf -vfi
./configure
sudo make install

Install qrencode
sudo apt install qrencode

Generate a QRCode

qrencode -s 6 -l H -o "qrcodespool1.png" "web+spoolman:s-1"

On your 2D printer, print this on a sticker for your spool.

CLI

cd /home/pi/klipper/klippy/extras/
wget https://raw.githubusercontent.com/th33xitus/kiauh/master/resources/gcode_shell_command.py

Change <PrinterIP> to the IP of your 3D printer below.

mainsail.cfg

[gcode_shell_command qrcode_qrscanner]
command: sh /home/pi/klipper_config/qrcodespoolman.sh
verbose: True
timeout: 2.
[gcode_macro QRCode_Scan]
gcode:
    RUN_SHELL_COMMAND CMD=qrcode_qrscanner

/home/pi/klipper_config/qrcodespoolman.sh

#!/bin/sh
# NonaSuomy PoC scan QRCodes via 3D printer camera
wget http://<PrinterIP>/webcam/?action=snapshot -O /home/pi/printer_data/gcodes/qrcode.jpg
SPOOLID=$(zbarimg -S*.enable /home/pi/printer_data/gcodes/qrcode.png | sed 's/[^0-9]*\([0-9]\+\).*/\1/')
echo $SPOOLID
curl -X POST -H "Content-Type: application/json" -d "{\"spool_id\": \"$SPOOLID\"}" http://<PrinterIP>:7125/server/spoolman/spool_id

Put your spool qrcode upto the chamber camera and hit "QRCode Scan" on the dashboard of MainsailOS.

image

http://<PrinterIP:7125/server/spoolman/spool_id

{"result": {"spool_id": 1}}

Enjoy!

@zellneralex
Copy link

zellneralex commented Jul 9, 2023

Sorry to say but we will never add a macro to the mainsail.cfg that needs a not default Klipper module.

wht you do at your own install is up to you but that method will never be part of the package we deliver with MainsailOS

@NonaSuomy
Copy link

NonaSuomy commented Jul 9, 2023

Hence the PoC! Most people have the CMD module made by Arksine the creator of Moonraker from the kiauh installer. Until that day though people can still have fun with something that works. Anyone besides me (Not a developer) could make a module without the CMD module and have something running just the same. Ideally, this could just as easily be added to the Spoolman docker. It would just have to have a setting to be pointed at the printer's webcam feed, decode, then post to moonrakers spool_id :D

@zellneralex
Copy link

zellneralex commented Jul 9, 2023

In my opinion moonraker would be the best fit for that. Then you could use the remote method to to the same as you do know with your gcode shell command.

moonraker-timelapse is a good example for stuff like that.

@NonaSuomy
Copy link

Not sure how that would work or how moonraker-timelapse is a comparison of how it would work. Maybe you could explain further. The nicest way would be to just toss the spool in the chamber for a second and have a scan button on KlipperScreen so you don't have to touch a computer to load the new spool. However it gets to that point and what works in the background is beyond my ability.

@zellneralex
Copy link

Timelapse use a moonraker module that takes a picture in the background triggered by a Klipper macro.
For your Scanner that stuff could be done the same way but instead of storing the picture you would post process it with your QR scanner. If you get that far we could get that macro in the mainsail.cfg and also in the mainsail integration of Mainsail.
KS as any UI can execute macros. So you could execute in on the macro page.

@zellneralex
Copy link

zellneralex commented Jul 9, 2023

See here that is how we take the picture thru Klipper https://github.com/mainsail-crew/moonraker-timelapse/blob/main/klipper_macro/timelapse.cfg#L297

and that is called in moonraker < https://github.com/mainsail-crew/moonraker-timelapse/blob/main/component/timelapse.py#L378> when the gcode is executed

Best would be to integrate that in the spoolman module that is already part of moonraker. The moonraker DB also contains the webcam setup so that it could use the cam specified in there.

@bazis
Copy link

bazis commented Jul 14, 2023

QR code may contain URL to spool info on spoolman web page ( https://my_domain/spool/show/555 )
That's how it works in the service simplyprint.io

matmen added a commit to matmen/fluidd that referenced this issue Aug 4, 2023
to be reverted when QR scanning is available
ref: Donkie/Spoolman#10

Signed-off-by: Mathis Mensing <[email protected]>
@Donkie
Copy link
Owner

Donkie commented Aug 12, 2023

This is now available in release 0.10.0. Please try it out! If you have any suggestions or find any bugs, please make new issues :)

@Donkie Donkie closed this as completed Aug 12, 2023
@samwiseg0
Copy link

@Donkie I am sure I am missing it somehow but how would you go about generating and printing the QR code from the UI?

@Donkie
Copy link
Owner

Donkie commented Aug 12, 2023

Remember to do Ctrl+F5 after every update.
After that's done, you should see a "Print QR Codes" button on the spools page

@samwiseg0

This comment was marked as off-topic.

@samwiseg0

This comment was marked as off-topic.

@Donkie
Copy link
Owner

Donkie commented Aug 12, 2023

Looks like you don't even have the previous version. How are you updating Spoolman?

@samwiseg0

This comment was marked as off-topic.

@samwiseg0

This comment was marked as off-topic.

@NonaSuomy
Copy link

NonaSuomy commented Aug 12, 2023

Tested and everything worked!

@NonaSuomy
Copy link

Tip if you can't get the cam scanner working because of https.

Make the browser device camera work with non https local sources.

chrome://flags/#unsafely-treat-insecure-origin-as-secure

Enable the Insecure origins treated as secure

Add the address for your Spoolman server IP:Port that you want to ignore the secure origin policy for. Remember to include the port number too.

Ignore the port used in this image I made it for another docker with a similar issue.
image

Save and restart Chrome.

Click enable on camera request when pops up.

@solo2424
Copy link
Author

solo2424 commented Aug 13, 2023 via email

@NonaSuomy
Copy link

What do you want working and how do you want it to work? As mainsail really has no support for this unless you want to use my PoC above. You would have to use fluidd which seems to have knocked it out of the park with support for it with matmen's pr fluidd-core/fluidd#1119

@solo2424
Copy link
Author

solo2424 commented Aug 13, 2023 via email

@samwiseg0

This comment was marked as off-topic.

@NonaSuomy
Copy link

NonaSuomy commented Aug 13, 2023

But I like the idea of being able to use the WebCam to scan the spool and
automatically set it to active.

My PoC above does only this but I haven't tested it yet with the current release of QR codes.

But I would also like the same thing to happen if I use my phones, camera.

This feature request would have enabled that ability #72

Maybe donkie will eventually add a plugin system for stuff they don't directly agree with but makes sense to others.

Ideally, there is nothing stopping you from modifying donkeys spoolman code and adding an action button next to the spools or automatically post via the qr code scanning page as well. Then you can bring that webpage up on your phone then scan and set the spool maybe with a drop-down list of your printers. Basically set the spool id via a similar command to how I did above but use whatever web-related methods to POST -H "Content-Type: application/json" -d "{\"spool_id\": \"$SPOOLID\"}" http://<PrinterIP>:7125/server/spoolman/spool_id etc.

I'm not sure if the phone has the same https limitation but probably does. So this may toss a wrench in the gears.

Looking at your code above, I try to manipulate using my settings as much as possible, but I can’t find a klippy_config folder anywhere. Therefore, I also do not have the qrcodespoolman.sh file.

klippy_config is a standard folder in your home directory when you use the MainsailOS pi image. Maybe yours is called RedRover_config? Maybe search what files are stored in klippy_config and then find that same directory of files on your setup. It can probably be put in any place you want that the printer has access to. Then edit the scripts above to show those location changes you made.

You have to make this file qrcodespoolman.sh and edit it as was said above.

Let me know if you need more information.

@NonaSuomy
Copy link

NonaSuomy commented Aug 13, 2023

Looks like the current QR code shows up like this web+spoolman:s-1
Not sure why it was formed like this but seems the regex above still matches it fine. So the code above "should" just work once you get your directories figured out.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants