Home > front end >  How Call a Python Websocket from a NFC Scanned on the phone(straight from the phone like with a URL)
How Call a Python Websocket from a NFC Scanned on the phone(straight from the phone like with a URL)

Time:11-02

Ok, no code here, more trying to get some directions. I'm working on my home automation using tuya objects. Till now I was able to create a websocket (using python websockets and asyncio) that gets a message and turn on my devices. I created a flask website to configure passwords, keys etc. Now what I'm trying to achieve is using a NFC tag(scanned by my phone) call the websocket sending a message. I bought some NFC tags, got a an android app called NFC Tools to record data into the NFC tag.

Problem is NFC tools doesnt give me too many options I can add text, and URLs but I dont know how to call my websocket from there. Can I call it using its URL like ws://something.go? Can I make the phone not open a browser when I scam the tag? Should I create a page on flask for that and put the page address?

Anyway, I'm kind of lost. Can you guys point me in the right direction?

CodePudding user response:

The right direction is to write your own NFC app for your phone.

In OS has a basic limited (fallback) idea of how to process the different type of Ndef record types, but it mostly relies on App's registering that they are capable for processing a certain record type.

So the OS can process various URL formats and open a web browser BUT ws: is not a standard URI as defined by the Ndef specs.

Thus the OS has nothing to processes it with.

To solve this you would best to make up your own mimeType string and create an App that registers that it can process this mimeType (Android docs on this, iOS has something similar). Then when you scan your custom Tag and the OS know what App can process this Tag, you app then reads the data and processes it accordingly and open the websocket request itself.

CodePudding user response:

End up creating a get route on flask and using NFC Tools Pro with http get to access it. The route just send a message to my websocket and turn on or off my devices. Thx Andrew for the tip I will have that in mind if this goes anywhere far from a personal project.

  • Related