Excecute code when plugging into USB port

Posted on
  • Hi all,
    Been playing with my new pico and was wondering how I would go about executing code on my windows machine when the pico is plugged into the USB port.

    The e.on("init"... event is fine for executing code on the Pico on startup, but I then want to execute code on the windows machine when the device is plugged in.

    Thoughts?

  • Interesting... Nobody has asked that before!

    I guess the best way might be to make a program on the PC that kept trying to connect to the COM port... When it succeeded it could run some other code.

    The only other option is to do something on the Pico - make it a USB HID keyboard that can enter the key combinations needed to run a command. Problem is that right now that works on Mac and Linux, but not Windows due to some driver issues :(

  • Could be useful for various things but the one I was thinking was for a basic hardware Id authentication token.
    Plug it in and it unlocks and logs you in.

    I was hoping for something similar to how when you plug in a usb drive it can launch an app/explorer etc.

    The polling mechanism would work, but is not ideal. It think event based in some sort of way would be best.

    Thanks for quick response though. And great project by they way... :)

    Cheers,
    Mark

  • @Gordon's 2nd approach is how to go about: I do not know in very detail how USB device type, id and relationship with driver goes. I just experience it when connecting what ever device, any (modern) operating system knows to pull a driver and install it and take it from there. Since a piece of software has to be installed on your host (being, for example the windows machine), security is a challenge when wanting Espruino to execute something. Kind of a pairing up as one has to do with Bluetooth has to happen - just a bit more secure.

    Since Espruino can act as a USB HID keyboard, you could try to become active and do something that almost all systems can do: start the desktop menu (shift/ctrl/...(?) F10(?) or a like in Windows - if not disabled or re-mapped - and go for execution a command.

    You can also high-jack the IDE, modify it, and use its abiity to communicate both ways. You still would have to launch the browser with the plug-in installed and execute a host initiated connect. It could be a starting point - and an easy one: the IDE is written in Javascript... ;-) To communicate, you still need some polling on the host side, but it could be against a file, because the IDE platform has ways to write Javascript controlled to files (see recording in testing feature). Pull down the plug-in, unpack it, and install it from local, and there you go.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Excecute code when plugging into USB port

Posted by Avatar for FrereMark @FrereMark

Actions