1. Got a question or need help troubleshooting? Post to the troubleshooting forum or Search the forums!

Detect Wire vs. Wireless, change your hostname, and add a Static IP

Discussion in 'Software' started by JohnShuba, Mar 26, 2017.

  1. JohnShuba

    JohnShuba New Member

    Joined:
    Mar 4, 2017
    Messages:
    24
    Likes Received:
    17
    I recently needed to change to a static IP address to install a camera on the Robo C2. I am new to the Raspberry OS so I am posting this to help any newbies out there. Im dating myself by saying this but In the past I have used VMS and many different UNIX OS systems and the UNIX commands are all basically the same as in the Raspberry OS and it did give me a little head start.

    Prerequisites before proceeding:
    1. The Robo C2 needs to be add to your network.
    2. The ability to reserve a network address on your router. “This will be used for the Robo C2 once you give it a static IP address”
    3. The current network address of the Robo C2: “You need this to SSH into your Pi OS”
    4. Username and Password of your Pi OS: Out of the box it is username: pi and password: raspberry
    5. Download a SSH tool. “See comment below”
    6. You should always backup your Pi OS before any major configuration changes. I use a tool called Win32 Disk Imager to do this, look it up on internet there is a lot of instructions out there on how to use the tool to backup and retore a Pi image.

    For all the commands below you need a SSH command terminal logged into your C2 Raspberry Pi OS. I use a tool called Putty to SSH into the OS. You also need to know how to use the nano text editor, search the internet to learn how to run the editor if you never have before. The editor is easy to use with some simple instructions.

    Changing your Robo C2 hostname

    You need to edit the hostname and change the “original-hostname” to your desired “new-hostname” use the following command.

    sudo nano /etc/hostname

    Next you need to edit the host file and change the line “27.0.1.1 original-hostname” to your new hostname “27.0.1.1 new-hostname” Use the following command.


    sudo nano /etc/hosts

    Now reboot your Robo C2. Use the following command.

    sudo reboot

    Add Static IP address

    You need to gather some information first. The network address listed below are examples; your network addresses will differ. Use the following command.

    ifconfig

    Record the lines in the following display. The eth0 listing below is for cable LAN connection.


    eth0 Link encap:Ethernet HWaddr b8:27:eb:b3:fc:2c
    inet addr:192.168.1.81 Bcast:192.168.1.255 Mask:255.255.255.0


    if you are running a wireless connection than record the settings after the wlan0 listing. Record the following information.

    inet addr – 192.168.1.81
    Bcast – 192.168.1.255
    Mask – 255.255.255.0

    You still need some more information, Use following command.

    netstat –nr

    Record the following information.

    Gateway – 192.168.1.254
    Destination – 192.168.1.0

    Now you need toedit and add this information to your Pi's network configuration file. Run the following command.


    sudo nano /etc/network/interfaces


    Change the top entry’s to be like this, enter the information you gathered from above.

    auto lo
    iface lo inet loopback

    allow-hotplug eth0
    iface eth0 inet static
    address 192.168.1.81
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.254

    auto wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp
    iface “your new-hostname” inet static
    address 192.168.1.81
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.254

    Adding the daemon to detect Wire vs. Wireless connection

    I noticed after setting up my Robo C2 on my home network I saw both a wire LAN connection and my Wireless connection on the router. I personally want a LAN connection for greater speeds. I found a plugin that will detect if you are using a LAN vs. Wireless network. Now on my network I only see my LAN connection. If I unplugged the LAN cable then it will use my wireless connection. It takes a reboot of the Robo C2 and about a minute or so but you will see the connection in your router will refresh and update.

    To start you need to add the ifplugd daemon. Run the following command.

    sudo apt-get install ifplugd

    Once installed you need to edit the ifupdown script. Run the following command.

    sudo nano /etc/ifplugd/action.d/ifupdown

    Edit the script to look like this.

    #!/bin/sh
    set -e

    case "$2" in
    up)
    /sbin/ifup $1
    if [ "$1" == eth0 ]; then /sbin/ifdown wlan0 ; fi # new addition
    ;;
    down)
    /sbin/ifdown $1
    if [ "$1" == eth0 ]; then /sbin/ifup wlan0 ; fi # new addition
    ;;
    esac


    The run the following command and you are all done.

    sudo shutdown -r now

    Once you are power back up your printer will have a new hostname, Static IP address, and only one network connection running.
     
    mark tomlinson likes this.
  2. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,912
    Likes Received:
    7,338
    Only thing I will toss out there is that there is (yet) an issue with the LCD and how the C2 deals with network addresses.
    My printers are all on a 10.x subnet and the LCDs show crazy, carzy IP addresses when you do network status. :)

    They work fine, but report stupid addresses. Just an FYI.

    (when I had them on the 192.x subnet they were OK. )
     
    JohnShuba likes this.
  3. JohnShuba

    JohnShuba New Member

    Joined:
    Mar 4, 2017
    Messages:
    24
    Likes Received:
    17
    Thanks for the information that is good not know, I guess I will stay away from 10.x subnet. I just checked my network status on the C2 after your post and it looks ok. My subnet is 134.x and it listed ok. in the network status listing.
     
  4. WheresWaldo

    WheresWaldo Volunteer ( ͠° ͟ʖ ͡°)
    Staff Member

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    I use my router to give out static leases based on MAC addresses. It eliminates all the editing on the rPi. You could do the same after setting up WiFi, although since WiFi is not the default setting you will need to ssh into the rPi to set that up. Then you only have one place to set up all your networking stuff, your router.

    rationale: all my 'servers' use static IPs as well as the game consoles and it is a heck of a lot easier to sit at one browser and configure them all in the router firmware rather than wandering around my home reconfiguring all the devices that I want to use static IPs on. Especially since nearly every network capable consumer device you can buy comes preconfigured for dynamic IP addressing.
     
  5. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,912
    Likes Received:
    7,338
    Mine are configured to hook to the router on 10.0.0.1 and they are connected there:

    10.0.0.45 -- RoboC2

    Yet if you look at the LCD network status you see something like this:
    198.105.244.130

    :)
     
  6. JohnShuba

    JohnShuba New Member

    Joined:
    Mar 4, 2017
    Messages:
    24
    Likes Received:
    17
    One thing that is important to mention is that when connecting the Robo C2 Printer to Cura 2.3.1 on windows it has difficulties detecting the printer on initial setup. What I found works is while your in Cura and have the printer detection window open reboot your Robo C2 and once it reboots Cura finds your printer right aways. You can then add your API key and connect, I had this problem before I change my network setting and still did after the changes I listed above in this post.

    The good new is that once the printer is detected in Cura it finds it very time your start Cura and finds it very fast, even faster now with the network changes I did and the static IP. It also helps to add the printer to your host file on windows. You would think after all these years windows would have improved their networking, not so much ;)
     

Share This Page