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.
The PXE boot process requires a tftp server. If you decide to use this process then you will need to install that software first. I originally had some long instructions, but I decided to create a script, which is still long, so I moved it to this page: Arduino Sever PXE Script
At this stage you should have the server working and we will test it and connect to the arduino from a client.
- Log into the server from the console or ssh
- Verify that the /home/scada/scripts/arduino_init script worked with this command
Expected command ouput:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:2111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN netstat: /proc/net/tcp6: No such file or directory
This shows the port 2111 we are looking for to show that the arduino_init script worked. If you do not see that line, then it did not work.
- Try to manually run socat command: (Note:This resets the program in Arduino after a reconnect to port)
stty -F /dev/arduino_1 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1
If this fails, then check that /dev/arduino_1 exists, it may be a udev naming issue. See this article for assitance with udev: Arduino Communications Device Naming with udev
- Connect to TCP port 2111 from another computer (If you have trouble try this as root)
rm -f /home/scada/data/arduino_1_in mkfifo /home/scada/data/arduino_1_in tail -f /home/scada/data/arduino_1_in | nc 220.127.116.11 2111 > /home/scada/data/arduino_1 &
- Send a command to the pipe into the nc command
echo S > /home/scada/data/arduino_1_in
- Create scripts to connect to the port on the Arduino Server and collect data
- 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