graphefruit / Beanconqueror

An open source project for coffee enthusiasts.
https://beanconqueror.com/
GNU General Public License v3.0
451 stars 64 forks source link

NFC support #504

Open LagaV opened 1 year ago

LagaV commented 1 year ago

Just had a similar thought as in here: https://github.com/graphefruit/Beanconqueror/issues/67.

Having an NFC tag on each container being scanned with the mobile phone would launch Beanconqueror and start a „repeat“ for the last brew of this roast.

Are there any updates to the NFC framework support, as this was the reason to shelf the original request?

graphefruit commented 1 year ago

The latest release of the plugin was 2020 - so a "bit" outdated. I'd need to test it, and I'd need NFC-Tags at home myself for writing, which I don't have actually.

LagaV commented 1 year ago

I’m using 50ct tags (via eBay bought 10 as a set) to initiate homeautomation tasks (home assistant).

Not sure if you would need to have an embedded NFC capability within the app. For iOS I leverage the Shortcuts automation functionality. This requires (published ?) URL handler capability for the intended app. So Beanconquerer would need a URL handler to start a new brew for a bean sort.

Advantage (within iOS) is, that the app not necessarily needs to be active if the tag is scanned.

graphefruit commented 1 year ago

The issues with this kind of solution is, you'd also need to know how to write an NFC Tag, and without any guidelines it will be a tricky topic. Also you'd need to get the Bean-ID out of beanconqueror, so there need to be atleast one new option to show and copy maybe this kind of information, and generate an URL for tagging.

Yes you're right, there would be some ways of workaround, but wouldn't it be great to just "..." the beans -> Write NFC Tag? Would be much more handy.

reox commented 1 year ago

This would be a great feature!

Basically, what you would have to do is: 1) Have dialog to initialize NFC Tags. In this dialog, a NDEF Message is written onto the tag, containing some random ID. The App keeps track of the IDs it has written 2) Link a tag to a bag. Here, one could also setup the brew type (espresso, filter etc) or defaults that should be used for this bean (specific grinder, water, ...) 2a) the tag is reused, while the bag is still in use. Maybe ask the user if the bag shall be archived or simply linked to the new bag. 3) Now the app knows which NDEF message is connected to which bag. Scanning the tag opens the app and starts the brew 4) When the bag is empty, the tag is removed from the bag and can be used for the next bag

btw, you do not need actual NFC Tags to test most of the functionality, QR codes containing the same URI as the NDEF message work as well ;)

@graphefruit I have a bag full of 15693 Icode Tags (coin shaped w/o glue). If you like I send you a few for free. I bought them years ago when I did a project with NFC and have not used them since them, except one tag for Home assistant (which works great, btw)

for a university project, we used an URL handler with a custom scheme. For example you could use brew://coffeebag/<random_ID> in the NDEF message and simply register for the brew:// scheme. However, this has the drawback/advantage (you can see it both ways actually!) that a phone without beanconqueror installed cannot handle these tags. If you use something like https://beanconqueror.com/tag/<random_ID>, a user that does not have the app, or has it improperly configured, will be send to the webbrowser instead. Homeassiant has it configured that way and sends you here: https://www.home-assistant.io/tag/randomid

and for the fun: Working prototype of the Coffee-nfc-taggifier-9001: image

😁

reox commented 1 year ago

As a workaround, if writing NFC Tags is too much effort, you can simply enable the URL handler. without resorting to NFC Reading/Writing. At least on Android, the NFC Reading is done by the OS and only the URL is forwarded to the App. You could then do the following. If an URL is presented ...

You could basically setup everything except reading/writing of tags. Tags can easily be written manually with another app.

graphefruit commented 1 year ago

@reox I'm not deep inside NFC Tags, but would it be possible to go like: beanconqueror://NFC?beanId=1827318273461827365&brewId=81726364718? Therefore I could just pass the internal UUID's, instead of referencing to a new ID which would need to be saved.

LagaV commented 1 year ago

On iOS I was able to write the sample tag to an NFC tag with „NF21 Tools“. When reading the text it launches Beanconquerer. So seems operable. This approach might also work with QR codes as launcher.

graphefruit commented 1 year ago

On iOS I was able to write the sample tag to an NFC tag with „NF21 Tools“. When reading the text it launches Beanconquerer. So seems operable. This approach might also work with QR codes as launcher.

Yes beanconqueror:// is the internal address, wich is already connected for bean-qr scans from roasteries. If the text is the same it doesn't matter if qr-code or nfc-tag, but NFC-Tags need a plugin to read NFC and a device which has NFC, qr-codes has already a build in scanner in BQ, or you can use normally the camera or plugins, so theres quite a "bit" of a difference.

LagaV commented 1 year ago

Generally to me the (NFC) URL approach seems a very good option, as this also launches the Beanconquerer app in one „swipe“. Having QR codes as a parallel option also makes sense. I would put NFC tags on dedicated bean containers and QR tags on in-use bean bags.

reox commented 1 year ago

@reox I'm not deep inside NFC Tags, but would it be possible to go like: beanconqueror://NFC?beanId=1827318273461827365&brewId=81726364718? Therefore I could just pass the internal UUID's, instead of referencing to a new ID which would need to be saved.

My last experience with NFC on Android was in ... uhhhmmm ... 2013 I guess 😆 So maybe things have changed... But I guess the answer to your question is yes and no.

You can use the beanconqueror:// scheme without any problems. The only downside is, as explained, if someone scans the tag without having the app installed OR having the app misconfiguration (i think you can remove scheme associations manually), then nothing will happen. If you use http(s):// scheme instead, a browser will be opened and you could redirect to a help page.

For the parameters, I guess the approach you have in mind would link always one tag with one bag - right? That would however mean that you need to store the bag ID on the tag, every time you create a new bag.

What you would have to do is to simply give each tag a random ID, i.e., the NDEF Message would link to beanconqueror://NFC?tagId=9cc0bebf-b108-436e-a224-7ea4f9f1861e. Inside the app you then have to make the connection which tag is currently attached to which bag, as described above.

This approach requires you to write the tag once and IMHO you can then rely on the reading capabilities of the OS to send you the data into the app. I.e., no need for NFC reading capabilities in the App itself. And you can do the same with QR Codes - for example, print out some QR codes and laminate them to re-use.