0

I'm trying to develop small app detecting when/which phone was connected / disconnected to rpi and than base on that take some actions it should work with both android and apple phones

I know how to detect if something was connected to USB but I don't know how / if its possible to detect exact phone (unique Id - eg imei or serial)

High level functionality I'm thinking of - phone registration (store unique number in local db) - phone connected to usb : * check if it is "known" phone, then do something * if unknown do Notting

Can somebody please advise if this is possible / where to start?

** EDIT ** This will be just USB cable connection Rpi-Phone. Only to 'authorize' user that way (and keep Phone charging). I do not need send anything / exchange data etc.

Ideally this should work without need phone unlocking

5
  • 2
    How are you planning to connect the phone to the Raspberry?
    – Dougie
    Commented Nov 24, 2019 at 14:16
  • 2
    You could parse the output of lsusb to get, eg., the manufacturer and model USB ids. You can also get that and other info from udev (probably including the mei, which I believe is used to create individual device paths in /sys). A udev hook could also be used to log the information (much of which is logged by the kernel and/or udev already).
    – goldilocks
    Commented Nov 24, 2019 at 16:11
  • 1
    Thanks will check this. I can get vendor id, but Im looking to get something which is unique for device so I can recognize 'registered' phone even if same model will be connected
    – Maciej
    Commented Nov 24, 2019 at 20:40
  • 1
    How are you planning to connect the phone to the Raspberry? USB or BT or WiFi tethering?
    – Dougie
    Commented Nov 25, 2019 at 10:09
  • 1
    Just USB cable connecition. Only to 'authorize' user that way. I do not need send anything / exchange data etc. Ideally this should work without need phone unlocking
    – Maciej
    Commented Nov 25, 2019 at 11:08

1 Answer 1

2

For Android phones, you can install adb on your RPi and run

adb shell dumpsys iphonesubinfo

This will return a data block containing the IMEI (international mobile equipment identity) number of your device. This is guaranteed to be unique for legitimately produced phones.

There are scripts you can use to extract the IMEI value from the Android info block.

3
  • 1
    Thanks Dmitry. Will this work also if Android phone is not in debug mode / unlocked ?
    – Maciej
    Commented Nov 25, 2019 at 11:08
  • 1
    @Maciej You have to enable USB debug mode to use adb, otherwise how would you know your phone charger isn't spying on you? If by "unlocked" you mean unlocked bootloader, then no, this is not required. Commented Nov 25, 2019 at 11:46
  • No other option than that? It would be hard to convince users to enable debugging just for this purpose.
    – Maciej
    Commented Nov 25, 2019 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.