Arduino Server

From Combustory
(Difference between revisions)
Jump to: navigation, search
(Operation)
 
(7 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
<anyweb>http://combustory.com/wiki/ads/ad_rtc.html</anyweb>
 +
 +
{{default}}
 +
 +
<anyweb>http://combustory.com/wiki/ads/ad_rtc_1.html</anyweb>
 +
 
=Summary=
 
=Summary=
 
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.
 
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.
Line 28: Line 34:
 
==Configuration==
 
==Configuration==
 
===PXE Setup===
 
===PXE Setup===
The PXE boot process is
+
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]]
====Development Environment====
+
====Operation====
* download TinyCore-current.iso
+
At this stage you should have the server working and we will test it and connect to the arduino from a client.
* mount TinyCore-current.iso and copy entire contents of the iso to a tftboot directory
+
<pre>
+
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
+
</pre>
+
* copy core.gz to a development dir
+
<pre>
+
sudo cp /tftpboot/tinycore/boot/core.gz /tftpboot/tinycore_dev/
+
</pre>
+
* 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
+
nano /tftpboot/tinycore_dev/core_root/home/scada/scripts/arduino_init
+
** Add these lines:
+
<pre>
+
#!/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
+
</pre>
+
** Make arduino_init executable
+
chmod 755 /tftpboot/tinycore_dev/core_root/home/scada/scripts/arduino_init
+
** Edit this file:
+
nano /tftpboot/tinycore_dev/core_root/opt/bootlocal.sh
+
** Add these lines
+
/etc/init.d/dropbear start
+
sh /home/scada/scripts/arduino_init &
+
** create this file:
+
touch /tftpboot/tinycore_dev/core_root/etc/udev/rules.d/98-arduino.rules
+
** We need to put the rules of our Arduinos in this file and this is a subject on it's own. Refer to this [http://combustory.com/wiki/index.php/Arduino_Communications_Device_Naming_with_udev udev naming] page
+
** Here is an example of what I used
+
SUBSYSTEMS=="usb", ATTRS{serial}=="A700618T", ATTRS{product}=="FT232R USB UART", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", NAME="arduino_1"
+
* 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/
+
====Booting Process====
+
* modify PXE boot settings to boot with your new root image
+
** Create the following directory and file
+
mkdir /tftpboot/tinycore/pxelinlux.cfg
+
touch /tftpboot/tinycore/pxelinlux.cfg/default
+
** Put this text in the default file
+
default boot/vmlinuz
+
append initrd=boot/ard-core.gz tftplist=172.1.1.150:/tinycore/cde/onboot_x.lst xvesa=800x600x32
+
** Copy PXE boot file
+
cp /usr/share/syslinux/pxelinux.0 /tftpboot/tinycore/
+
** If you cannot find pxelinux.0 file on your system then download syslinux from here:
+
<nowiki> http://www.kernel.org/pub/linux/utils/boot/syslinux/4.xx/syslinux-4.06.tar.gz</nowiki>
+
** you will find pxelinux.0 file in /syslinux-4.06/core/ directory of the archive
+
** example of how to set up the .lst files to load expansion modules
+
** Download the following files:
+
<pre>
+
cd /tftpboot/tinycore/cde/optional
+
wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/dropbear.tcz
+
wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/socat.tcz
+
wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/usb-serial-3.0.21-tinycore.tcz
+
</pre>
+
** introduce the TinyCore [http://distro.ibiblio.org/tinycorelinux/faq.html#bootcodes boot codes] and provide your example
+
* log into the booted computer and test/verify the configuration and update image and reboot if needed
+
  
====Operation====
+
Test Server:
* Create scripts to transfer Arduino to interface with TCP port using nc command
+
* Log into the server from the console or ssh
* Create scripts to connect to the port on the Arduino Server and collect data
+
* Verify that the /home/scada/scripts/arduino_init script worked with this command
* 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.
+
netstat -tl
 +
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
 
  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
 
  socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1
* Connect to TCP from another computer
+
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
 
   rm -f /home/scada/data/arduino_1_in
 
   mkfifo /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 &
+
   tail -f /home/scada/data/arduino_1_in | nc 172.1.1.147 2111 > /home/scada/data/arduino_1 &
 
* Send a command to the pipe into the nc command
 
* Send a command to the pipe into the nc command
 
  echo S > /home/scada/data/arduino_1_in
 
  echo S > /home/scada/data/arduino_1_in
 +
=More Investigation=
 +
* Create scripts to connect to the port on the Arduino Server and collect data
 
* Discuss security and ssh  
 
* Discuss security and ssh  
 
* Discuss file transfer methods
 
* Discuss file transfer methods
 
* Discuss cron jobs and set up
 
* Discuss cron jobs and set up
 
* This section will end up being a wide scope with many ideas presented and possibly referenced
 
* This section will end up being a wide scope with many ideas presented and possibly referenced

Latest revision as of 15:35, 8 November 2012

Welcome to Combustory


Any questions or comments:

  • Send them to - combustor@combustory.com

Contents

Summary

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.

Software

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.

Assumptions

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

Server

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.

Operating System

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.

Boot Methods

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.

Configuration

PXE Setup

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

Operation

At this stage you should have the server working and we will test it and connect to the arduino from a client.

Test Server:

  • Log into the server from the console or ssh
  • Verify that the /home/scada/scripts/arduino_init script worked with this command
netstat -tl

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 172.1.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

More Investigation

  • 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
Personal tools
Sponsers
Your Ad Here
Your Ad Here