Configuring C.H.I.P. to go Mobile!
I recently received my $9 NTC CHIPs and decided a cool use of the tiny server would be to mate it up with the Adafruit FONA 3G Cellular Breakout and Adafruit FONA 2G Cellular and GPS Breakout to test using both GPS and GSM GPRS via ppp on the CHIP.
Turns out you can’t use the ppp out of the box on the CHIP as it’s not part of the kernel. Depending on which flash you use, you might not even have USB-Serial support (via PL2303 or FTDI USB-to-Serial cables).
So, roll up your sleeves and let’s build us a new kernel! At first blush, this sounds far more daunting than it should. Having been a Unix kernel hacker for far too many years than I’d care to admit, today’s modern kernel build environment takes a lot of the sting out of configuring and building your custom kernel.
Kernel hacking
We need to start by setting up an environment and pulling a code base to allow us to configure and build our kernel
- Build environment:
The build environment will consist of setting up a vagrant environment for the CHIP-SDK. There are great directions for doing so on the CHIP Documentation site. Take a look at these instructions on setting up the CHIP-SDK vagrant vm.
Before you grab the source, you might need a few tools to make your vm ready to rock and roll. Specifically, add the following with your favorate package manager:
1 2 3 |
|
and
1 2 |
|
Once the vagrant machine is setup, clone the CHIP-linux source onto the machine into a working directory, say CHIP-linux
1 2 |
|
Next, check out the debian NTC release…
1 2 |
|
Now you have the source, and the tools, and are ready to roll. But before you start the build process, we might want to start with our baseline config from our existing CHIP. This isn’t a requirement, but it will allow you to either add to or subtract from a known kernel configuration.
To grab your config file, simply:
1
|
|
You might run into problem or two here depending on your CHIP Linux configuration. One, you may not have a root password! You might need to set that. Secondly, you might not have configured sshd to allow root login. Be sure you’ve remedied both of these issues as we’ll use root login throughout the kernel build process.
- Configuring the kernel
To configure our kernel, we simply invoke the makefile with the following:
1
|
|
This will bring up an easy to use menu-driven application that allows you to select or delete items that you wish to have in your kernel.
Remember that config file that we copied over from the CHIP? Let’s load that as our starting point.
Now make the modifications that you wish to your kernel. In this kernel, I want to add ppp support as well as ppp async-serial support. I select both of those, and then save my configuration file as .config
.
Before we actually save the configuration, it’s a good idea to mark your Kernel so you can easily verify you’re running the kernel that you built. To do that we add a Local Version
marking to the kernel release. Under the following Menu item:
- General setup
- ( ) Local version - append to kernel release
Add a tag that marks your kernel. I use rb-2016-08-01.0
for example.
Now I’m ready to actually compile the kernel that represents the configuration that I just selected. To do so, simply run make
as follows:
1
|
|
where n
is the number of cores that you have on your box.
Once the compilation successfully completes, you’ll next need to install the modules into a directory that we’ll use later to place them onto the CHIP.
1 2 |
|
Add the RTL8723BS
: This is not part of the CHIP-linux source tree.
1 2 |
|
And build it…
1 2 3 4 5 6 7 8 9 10 11 |
|
Now that everything is compiled and built, you’re ready to copy it to your CHIP!
1 2 3 4 5 6 7 |
|
Now to boot your new kernel, there are two choices.
The Easy Choice:
Simply copy the existing kernel so you have a backup
1 2 |
|
Should something go wrong with the new kernel and you can’t boot, you’re hosed. There’s another way.
The Complicated, But More Better for Ya Choice:
The more complicated, but far more flexible approach is to add a serial USB-to-Serial connector to the chip. You can use a PL2303 and connect it as follows:
1 2 3 |
|
And on your computer use screen
to access the serial port:
1
|
|
Keep in mind that the actual device name may change depending on what OS you are using. I use the linux device name. Also, pay attention to the digit at the end, it might be some number other than zero.
Before you connect the serial port, be sure to first copy the orgiginal kernel so you have a backup. And then shut down the CHIP before you connect the serial cable.
Once all connected (both litreally with the USB connector as well as the screen command), type a key to stop the U-Boot booting process and fall into a u-boot shell.
Now you can change the bootcmd
and boot the kernel that you copied to the CHIP in the previous section. In this case, if there is a problem booting your new kernel, you can easily boot the backup kernel instead.
Wah Lah! You have successfully booted your new kernel!
If everything went as expected, you should be able to now connect your FONA 2g or 3g Cellular GSM breakout to a PL2303 and connect it to your CHIP. Be sure to use a lipo battery as well as a USB power source for your FONA. Turn it on, and verify that you can access the device.
Here again, I use screen /dev/ttyUSB0
to access the FONA. Verify that the PL2303 is accessable to the CHIP via lsusb
and you should see the PL2303 signature. If you don’t see it, you likely didn’t configure your kernel properly to include the USB device.
But if you did read the directions carefully, and have the device, and are able to screen
to it, you should be able to communicate with the FONA by sending it AT
commands, and receive back from the FONA a response, like OK
.
Make sure you’ve added the ppp
package.
1 2 |
|
If all’s connected, and you’ve successfully added the ppp
package, you can now configure the ppp setup.
1 2 3 |
|
Now edit the file and change the MUST CHANGE
items. There are essentialy two of them
The first one is the APN. In my case I am using Ting Wireless. The APN is
wholesale
The second item to change is the serial device. Make sure the device name that is connected to the FONA is specified in the file. For example,
/dev/ttyUSB0
.
Save the file, and give it a go! To turn on and off ppp, use pon`` and
poff“` respectivly.
1
|
|
You can verify that it worked by looking for the interface. A successful ppp session will result in a device shown when you run ifconfig
. If you run into problems, take a look at the log files for details on what went wrong. Common problems include forgetting to turn on the FONA device!
take a look at the ppp chat script in the syslog file:
1
|
|
If you successfully create your ppp connection and have verified it via ifconfig
, try it out! simply ping a website of your choice.
1
|
|
To get a feel for the speed of the connection, grab some data too:
1
|
|
Once you’re done with your ppp connection, simply turn it off:
1
|
|
GPS
Now that you have your FONA and your kernel in order, you can get the GPS setup. Start off by adding the following packages:
1
|
|
To start the GPS software, first stop the systemd gps services.
1 2 |
|
And now start the gpsd daemon
1
|
|
Use the cgps
command to run the GPS data viewer. Or for a more detailed data view, run gpsmon