Here's a quick hack for debugging Internet of Things projects
Let's say you built a nice, Internet-connected Arduino project with a fancy Web interface served by, e.g. the Ethernet shield. After one or two days it somehow stops working and you don't have a clue what happened.
The Arduino provides serial output over USB, but keeping your development machine attached for days is often not very practical. Or worse: you already deployed the embedded system and it only fails in a certain network at your customer's. You could attach an SD card to the Arduino, but this changes the code and the library uses additional memory.
On the other hand, Linux computers like the BeagleBone are cheap enough to throw one at every problem you have to solve. So why not use it as a long term debugging help?
- Your existing Arduino (or other embedded device) project
- USB cable, A-B, e.g. https://www.adafruit.com/products/62
- Ethernet cable, e.g. http://www.adafruit.com/products/730
- BeagleBone Black, e.g. https://www.adafruit.com/products/1876
- 5V, 2A power adapter, e.g. https://www.adafruit.com/products/276
- A desktop or laptop computer connected to the local network
Step 1: Connect the Arduino to the BeagleBone
Set up the Arduino
- Set up the Arduino project as intended
- Plug the Arduino USB cable into the BeagleBone
(If you prefer to use the GPIOs, check this great Instructable)
Set up the BeagleBone
- Install Ubuntu on the BeagleBone (or any Linux)
- Connect the BeagleBone to your local network (Ethernet, WiFi, ...)
- Plug in the external power supply to power up the BeagleBone and wait a bit
Other embedded devices
- The same setup works for every device providing serial output over USB
- E.g. the custom ARM Cortex-M4 / .NET Micro Framework device I work with
Step 2: Set Up the Screen Command on the BeagleBone
Install the screen command
- Open a terminal on your computer and ssh into the BeagleBone (default password: temppwd), e.g.
$ ssh email@example.com
- To install the screen command line tool, type
$ sudo apt-get update $ sudo apt-get install screen
Run screen to see and log the Arduino output
The screen command allows you to see the Arduino serial debug output
- Make sure the baud rate matches your Arduino's Serial.begin(...) value
- To run screen with logging enabled, add the -L command line argument, e.g.
$ screen -L /dev/ttyACM0 115200
- If /dev/ttyACM0 is not available, try /dev/ttyUSB0 instead (depends on device)
- To change the logging directory, use the keyboard shortcut CTRL-a-: inside screen, then type
: chdir /home/ubuntu/
- Press RETURN to save the log directory
Leave them alone
- Detach from screen with CTRL-a-d
- To terminate the ssh session, type
Done. The BeagleBone now logs the Arduino's output into a file.
Step 3: Check the Log File (remotely) on the BeagleBone
Re-attach to screen
- Open a terminal on your computer and log back into the BeagleBone, e.g.
$ ssh firstname.lastname@example.org
- Optional: to re-attach to the running screen command, type
$ screen -r
Display the log file(s)
- To see the log file name, type
$ ls /home/ubuntu
- To display the log file type, e.g.
$ cat /home/ubuntu/screenlog.0
Cleanup once you're done
- To stop all running screen commands, type
$ pkill -9 screen $ screen -wipe
Enable remote access
You can also set up port forwarding, or use a relay service like https://yaler.net/ to remotely access the BeagleBone with SSH. This allows you to conveniently check logs, right from your kitchen table. (Disclosure: I'm a founder of Yaler.)
That's all. Thanks for reading. Use the comments for questions or suggestions.