Detect USB network not connected

Discussion in 'UDOO NEO' started by Maurice, Dec 14, 2016.

  1. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    I'm trying to start my program when I'm not connected to my PC, so my program automatically starts when I run the Neo connected to a USB battery pack, but not when to my development PC. I thought that I could do that by checking if the 7.2 address is configured.

    I have added to /var/rc.local the following code:
    Code:
    usb_inet=$(ifconfig | grep -c 192.168.7.2)
    if [ $usb_inet -eq 0];
    then
     ...
    fi
    
    Unfortunately it seems that when connected to a battery pack the USB network looks like it is up to, the grep still returns 1.

    So if it is not the 7.2 ip address, what else could be checked to see how the board was booted.
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Perhaps ping your development PC from the Neo, but that will only work if you are not connected to wifi or Ethernet to your network.
     
  3. Gorgo

    Gorgo UDOOer

    Joined:
    Nov 9, 2016
    Messages:
    159
    Likes Received:
    17
    Note that usb0 is always up due to settings in /etc/network/interfaces.
    The line
    Code:
    inet addr:192.168.7.2  Bcast:192.168.7.255  Mask:255.255.255.0
    is always in ifconfig.
     
  4. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    @Gorgo, thanks. I assumed something like this, or at least, I thought that as long as power was detected on the USB port the interface would be up. And as I'm using a powerbank that would be the case in my project.

    I now use a semi-automatic solution: I check if a certain file exists, and if it does I autostart my program.
     
  5. Gorgo

    Gorgo UDOOer

    Joined:
    Nov 9, 2016
    Messages:
    159
    Likes Received:
    17
    Check this: if you plug your battery, is usb0 running or not?
    If not, you can use
    Code:
    ifconfig usb0| grep -c RUNNING
     
  6. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    If the Neo is powered from the barrel jack USB0 is not running, if it powered from the battery it is :(. Thanks for the suggestion.
     

Share This Page