In determining a method to create a distributed sensor network I decided to test the idea of taking some old hardware to use it as a remote server to communicate with Arduinos. The basic idea is to have a server that communicates with the Arduinos and sends the data to a central monitoring process over the network. As long as you have a network connection to the server, you can add as many Arduinos as the server can handle to monitor or control whatever it is you are trying to accomplish.The motivation for this investigation revolved around Energy Management, therefore, I may have some references that apply to that subject to use as examples.
This article is not meant to be a step by step procedure, simply because there are many variables in each of our situations. Mainly this is a guide to how to accomplish the task with a conceptual basis that will lead you to discover some solutions that are needed for your application. It is more of a framework with some details and references.
The Arduino Server will be focused on Linux. I guess it is possible to consider windows, but I have not been able to find the same capabilities easily and I am not sure it is even worth investigating, given the ease and flexibility of linux in this application. The central monitoring computers can be any OS that is capable of communicating to network TCP ports or file transfer, which is pretty much anything.
If you do not fully understand these topics below, this article will still be helpful for learning the capabilities of computers. Finding out computing techniques is half the battle to finding solutions. You can always learn the skills later and things will eventually fall in place.
- You are familiar with the Linux command line
- You understand basic text file configuration methods
- You are familiar with serial communications in Linux
- You are able to manipulate computer BIOS settings
- You understand how to configure booting from HD,USB,CD,PXE
- You understand sudo, su, chroot commands
The idea is that you are able to find any old server that you may have laying around and put it to use and save money or buy one cheap just to help you learn as a low cost education. The hardware requirements are very little, you should be fine as long as you have about 256k in memory. It may be possible to have less, but that is where I decided to draw the line. The processor is mostly irrelevant, because just about any processor you have laying around will most likely be able to manage the light load we are creating. I will not be testing it, but it may be possible to go as far back as a 386. The hardware configuration that I am using is a 1.2MHz pentium with 256k in memory, which actually works very well even in full GUI mode. You should also be able to find this type of computer laying around in many junk piles at a computer swap.
After a significant search and years of playing around with small linux distributions, I have fallen on upon Tiny Core Linux. It is amazing. With this distribution you can breath life into old computers you thought were long useless. It has a full GUI and is quite capable of many tasks. With a quick download you can be up and running in no time. What really sealed the deal for me was the fact that I could change all the characteristics of this OS with ease and quickly. After fiddling around with many other linux distros for hours or even days, I was making progress with Tiny Core literally in minutes. I'm completely sold on this idea and while many have created small distributions, this concept is masterful in my eyes and far better than any other that I have tried.
With Tiny Core you have these boot options: HD,CD,USB,PXE. I am focusing on PXE (Network Booting), because to me this is the best way to manage old computers that tend to die. I can pretty much find any old computer with net boot capability and just plug it in and off we go with very little work. The CD and USB are similar in this capability, but not nearly as fast on booting up. The HD being the least flexible of all options, but may not be too bad if you use an IDE or SATA to SD converter, which I have not tried yet, but they look interesting.
- download TinyCore-current.iso
- mount TinyCore-current.iso and copy entire contents of the iso to a tftboot directory
sudo mkdir /mnt/tmp sudo mount TinyCore-current.iso /mnt/tmp -o loop,ro sudo cp -r /mnt/tmp/* /tftpboot/tinycore/ sudo umount /mnt/tmp
- copy core.gz to a development dir
sudo cp /tftpboot/tinycore/boot/core.gz /tftpboot/tinycore_dev/
- extract core.gz
mkdir /tftpboot/tinycore_dev/core_root cd /tftpboot/tinycore_dev/core_root zcat ../core.gz | sudo cpio -i -H newc -d
- modify/add files/dirs in the development dir (use chroot commands for setting passwords and other system level settings)
- Add these directories
mkdir /tftpboot/tinycore_dev/core_root/home/scada mkdir /tftpboot/tinycore_dev/core_root/home/scada/scripts mkdir /tftpboot/tinycore_dev/core_root/home/scada/data
- create this file
- Add these lines:
#!/bin/bash # arduino_init - initialization tasks for scada ### Main script starts here ### # Store file name of arduino FILE="/dev/arduino_1" # Arduino Communications # set serial commuication for arduino stty -F $FILE cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts # make sure file (serial device) exist and is readable if ! pidof socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1; then echo "$FILE is not logging" if [ ! -c $FILE ]; then echo "$FILE : does not exists" exit 1 elif [ ! -r $FILE ]; then echo "$FILE: can not read" exit 2 else socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1 echo "start process - socat TCP-LISTEN:2111,fork OPEN:$FILE" fi fi exit 0
- Edit this file:
- Add these lines
/etc/init.d/dropbear start sh /home/scada/scripts/arduino_init &
- pack up the new core and move it to the PXE boot dir (show script for doing this)
cd /tftpboot/tinycore_dev/core_root sudo find | sudo cpio -o -H newc | gzip -2 > ../ard-core.gz cd .. cp ard-core.gz /tftpboot/tinycore/boot/
- modify PXE boot settings to boot with your new root image.
- example of default boot properties and file
- example of how to set up the .lst files to load expansion modules
wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/dropbear.tcz wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/dropbear.tcz.md5.txt
- introduce the TinyCore boot codes and provide your example
- log into the booted computer and test/verify the configuration and update image and reboot if needed
- Create scripts to transfer Arduino to interface with TCP port using nc command
- Create scripts to connect to the port on the Arduino Server and collect data
- socat example of TCP to serial port - you have to set the serial port with stty - This resets the program in Arduino after a reconnect to port.
socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1
- Connect to TCP from another computer
rm -f /home/scada/data/arduino_1_in mkfifo /home/scada/data/arduino_1_in tail -f /home/scada/data/arduino_1_in | nc 192.168.1.147 2111 > /home/scada/data/arduino_1 &
- Send a command to the pipe into the nc command
echo S > /home/scada/data/arduino_1_in
- Discuss security and ssh
- Discuss file transfer methods
- Discuss cron jobs and set up
- This section will end up being a wide scope with many ideas presented and possibly referenced