So, I decided the best way to interface the pi was to use the tried and tested ssh command. After adding the wireless network to the configurations via the command line. I wanted to do it without installing nmap on every machine. This is how it was done.
On the pi:
Things you will need:
- MAC address of your pi
- Enable the SSH server using raspi-config or some other method
You also need to edit a file and add to the end of it if you are using wifi. A possible command is:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
then add
network={
ssid="<name of your network>"
psk="<network password>"
}
After that, if it doesn't connect right away, simply reboot.
On the *nix machine you are connecting from:
I am using a linux machine so rather than having to type in the IP every time I want to connect, and rather than setting up a static IP I chose to write a small script.
Put the following in a text file on the machine you are connecting from, you can name the file whatever you want. I named it robot.sh since it is the brain of my robot :) Be sure to change <username> and <mac address of your pi> to the proper values.
ssh <username>@`for ((i=1; i<=29; i++));do arp -a 192.168.1.$i; done | grep <mac address of your pi> | awk '{print $2}' | sed -e 's/(//' -e 's/)//'`
to make the script executable you can:
sudo chmod +x <filename>
Now, whenever I invoke the robot script, it looks for the pi by mac address, then connects to it via ssh. You still need to enter a password if your pi is properly secured.
Other info:
The pi is running the latest, as of this writing, version of Raspian lite. I did not want to clutter up space with unnecessary software and just install the required development tools.
on a side note, htop is also a useful program to install for monitoring running software on the pi.
Another useful script for monitoring the temperature of the pi is:
#!/bin/bash
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 % $cpuTemp1))
echo CPU temp"="$cpuTemp1"."$cpuTempM"'C"
echo GPU $(/opt/vc/bin/vcgencmd measure_temp)
Save it to a text file on the pi and make it executable like before using the chmod command. I had to run the temperature script with sudo to get it to report the GPU temp properly.
These are some of the things I found useful when prepping the pi for use in my robot. Hope others find it useful too!
Cheers!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
I'll have to try this as an alternative to static IP addresses.
Are you sure? yes | no