Raspberry Pi Config

The Beta 01 ships with a Raspberry Pi configured to run serial-port-json-server for use with chilipeppr.com. Basically, this allows you to put the Beta 01 on your home network using an Ethernet cable, and then connect to it with Chilipeppr from any computer at home.

The Raspberry Pi boots from an SD card. Unfortunately it seems that the SD card can occasionally become corrupt, especially if the Raspberry Pi is switched off without doing a graceful shutdown. This has happened to me once so far.

Finding the IP address of the Pi

The Raspberry Pi will request an IP address from your network. You will need to know this IP for use in Chilipeppr and also to connect to the Pi to do any other configuration or to shut it down gracefully.

You can scan for the IP using a network scanning app such as LanScan for the Mac. Chilipeppr also has a scanning feature under the Serial Port section, although it only scans for the default port number (8989), not the one Printrbot configured (8000).

I found it convenient to configure my router to always give the Pi the same IP address.

Doing a graceful shutdown

So, how do you shut down the Raspberry Pi with the least chance of causing problems with the SD card? Unless you configure an alternate way to do it, you need to:

  1. SSH into the Pi from a computer on your network. You have to know the IP address of your Pi for this. For example, on a Mac, open "Terminal" and type (substitute your Pi's IP for the "10.0.123.30"):
  2. ssh pi@10.0.123.30
  3. (the default password is "raspberry")
  4. Type the shutdown command:
  5. sudo shutdown -h now
    1. This should disconnect you from the SSH connection.
  6. After waiting for the shutdown to complete (maybe 30 seconds or so?), you can now turn off the power to the Pi.

Rebuilding the SD card if things go bad

Here are the steps I used to get my Pi going again after the SD card got corrupted. You need a computer with an SD card reader for this to work:

  1. On your computer, download the operating system image for the Raspbian OS from http://www.raspberrypi.org/downloads/
  2. Pull the SD card from the Pi, put it in your computer's reader, and follow the instructions to write the image to it at: http://www.raspberrypi.org/documentation/installation/installing-images/README.md
  3. As of Nov. 2016, SSH is disabled by default. To re-enable it without having to connect a monitor and keyboard, just add a file called "ssh" to the root level of the SD card's boot partition. On Mac, like this:
    1. touch /Volumes/boot/ssh
  4. Put the SD card back in the Pi, and power it up.
  5. SSH to the Pi with user "pi" and password "raspberry" (use your Pi's IP rather than the "10.0.123.30"):
  6. ssh pi@10.0.123.30
  7. Optional: use raspi-config to expand to use the entire SD card, and set so no UI loads on boot:
  8. sudo raspi-config
  9. Get the current binary of serial-port-json-server by doing the following on the pi's command line:
  10. curl -O http://chilipeppr.com/downloads/v1.86/serial-port-json-server-1.86_linux_arm.tar.gz
  11. gunzip serial-port-json-server-1.86_linux_arm.tar.gz
  12. tar -xvf serial-port-json-server-1.86_linux_arm.tar
  13. You can now run the binary directly (manually) by typing:
  14. cd serial-port-json-server
  15. ./serial-port-json-server &
  16. (it will use the default communication port of 8989)

This works, but you would need to do step 4 and 6 every time you power on the Pi. To get it to start automatically, do the following:

Setting serial-port-json-server to start at power up

First, create a file at /etc/init.d/cnc by typing:

sudo pico /etc/init.d/cnc

which will bring up an editor. Copy and paste the following and save the file (Control-o, then Control-x):

#! /bin/sh
# /etc/init.d/cnc
### BEGIN INIT INFO
# Provides:          cnc
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start cnc server
# Description:       A simple script to start the chilipeppr json server.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting cnc"
    # run application you want to start

/home/pi/serial-port-json-server_linux_arm/serial-port-json-server -regex=ttyUSB* &

    ;;
  stop)
    echo "Stopping cnc"
    # kill application you want to stop
    killall serial-port-json-server
    ;;
  *)
    echo "Usage: /etc/init.d/cnc {start|stop}"
    exit 1
    ;;
esac
exit 0

Now make the script executable:

sudo chmod +x /etc/init.d/cnc

And finally, to set it to run at startup, type:

sudo update-rc.d cnc defaults

You could reboot now to see if it works by typing:

sudo shutdown -r now

Or, you can run it directly from the command line with:

sudo /etc/init.d/cnc start

If for some reason in the future you don't want it to start at boot, you can remove it with:

sudo update-rc.d -f cnc remove