Menu |
Prof /
SandcontrolRaspbian(:translatelink style=horizontal :) PLANS - Photometer for Light At Night SensingSoftware package IntroductionThe aim of this project is to develop a system capable of remotely controlling a light pollution monitoring system consisting in a 13 filter slots. Twelve of the slots are filled with narrow-bands filers. The photometer is connected to a raspberry pi 3b and a servo motor filter wheel. Instead of starting from scratch, we decided to take advantage of the SAND spectrometer software package by adding a new instrument to its palette. Some element of the SAND platform are useless for the PLANS photometer project and then we decided to remove the corresponding sections in the procedure below in order to get it much easy to follow. The linux distribution used for this system is raspbian Jessie. We choosed a development philosophy based on a complete control from the Linux command line. The system can be controlled simply with a low speed remote connection provided by a SSH client installed on the user workstation. The raspberry-pi (RPI) connected to the system act as a server. From internet: ssh -p 2022 sand@router_public_ip or inside a private network ssh sand@servers_local_ip From the internet, port 2022 is used instead of standard port 22 to reduce risk of attacks by hackers. A password and user name is required. The standard username is sand. The system administrator should be able to provide you the password for sand. Installing and configuring subsystemsHardware profileThe system consists of the following items, but it would certainly be adapted to a different list of items with minor corrections.
Basic system installations and dependancies
sudo apt-get update && sudo apt-get upgrade sudo apt-get install gfortran sudo ln -s `which gfortran` /usr/local/bin/g77 sudo apt-get install gcc sudo apt-get install cpp sudo apt-get install g++ sudo apt-get install make sudo apt-get install vim sudo apt-get install vim-common sudo apt-get install bc sudo apt-get install mplayer sudo apt-get install apache2 sudo apt-get install gpsd sudo apt-get install gpsd-clients sudo apt-get install lm-sensors sudo apt-get install openssh-client sudo apt-get install openssh-server sudo apt-get install gnuplot sudo apt-get install gnuplot-x11 sudo apt-get install gphoto2 sudo apt-get install apcupsd sudo apt-get install fityk sudo apt-get install imagemagick sudo apt-get install netpbm sudo apt-get install mercurial sudo apt-get install python-serial sudo add-apt-repository ppa:jon-severinsson/ffmpeg && sudo apt-get update -qq sudo apt-get install ffmpeg SSHSSH server allows any remote SSH client to connect to the server to remotely control system programs from the command line or to download (upstream / downstream) data.
sudo raspi-config
sudo iptables -I INPUT 1 -p tcp --dport 2022 -j ACCEPT sudo iptables -I INPUT 1 -p tcp --dport 2080 -j ACCEPT sudo iptables-save Installing SAND applicationsLatest available package release on bitbucket mercurial repository
cd mkdir hg cd hg hg clone https://aubema@bitbucket.org/aubema/sand cd sand bash makeSAND
sudo cp -f /home/sand/hg/sand/* /usr/local/bin/ sudo chmod a+x /usr/local/bin/*
cp -f /home/sand/hg/sand/localconfig /home/sand Servo city PT785-S Pan / Tilt mount and filter wheel servo motorWe are using the Pololu Micro Maestro 6-Channel USB Servo Controller to command up to 3 servo motors involved in the system. The motor channels have to be defined in the localconfig file (elev_channel, azim_channel, filter_channel). Prior to be able to use the Pololu Maestro with the RPI we need to be sure that the maestro is configured in the correct mode. So then you first need a windows computer to do it. Install the maestro software on that computer. You can download it from this page https://www.pololu.com/docs/0J40/3.a After successful installation, connect the usb cable of the Maestro to the windows computer and then start the Maestro Control Center. Get sure that the Maestro communicate with the computer (look to the Connected to section. Then you can try to move the motor from the Status tab. If you are able to move the motor then go to the Serial setting tab and select USB Dual Port and click on Apply Settings button in the lower right corner. Then you can quit the software and plug the Maestro usb cable to one RPI usb port.
cd Downloads wget https://raw.githubusercontent.com/FRC4564/Maestro/master/maestro.py
cd /home/sand/Downloads sudo cp maestro.py /usr/local/bin echo "PYTHONPATH=$PYTHONPATH:/usr/local/bin" >> /home/sand/.bashrc source /home/sand/.bashrc Access to serial/USB ports in order to control mount and to ports video0 or video1 for the mount webcam (if applicable)It seems that the serial ports are not available by default to a given user in the terminal and the remote web control can not access it. A patch to remedy to this is to put add the sand user to the dialout group. sudo usermod -a -G dialout sand An external USB webcam will be available on the USB device /dev/video1 instead of /dev/video0 that is allocated to the RPI camera. SkycalcSkycalc allows ephemeris calculations that provide, among other time of the astronomical twilight ans sunset. These data will be used to manage the launch of observation requests. However a number of additional information will also be archived in the execution log file as the percentage of the lunar disk illuminated.
cd /home/sand/Downloads gzip -d skycalc.c.gz cc skycalc.c -o skycalc -lm sudo cp skycalc /usr/local/bin/ Learn moreD-LINK router configurationThe router is useful when SAND is connected to the Internet and that the appropriate ports are open to take control of the instrument remotely. If the system is not connected to the internet, a simple network switch or hub is sufficient.
Apache serverWe are using the Apache web server. This server allow the remote control from a web interface. It allow also browsing the database. To activate the web server, we must:
sudo a2enmod userdir sudo service apache2 restart
sudo mkdir /var/www/html/data sudo chmod a+rx /var/www/html/data
# added for cosqm <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted </Directory>
sudo a2enmod userdir sudo service apache2 restart Webcam server LINKSYS WVC54GC ou D-LINK DCS-920 et webcam logitech quickcam notebookWe are using a webcam server to track cloudiness and transparency of the window during day time. The webcam server is also usefull to measure the ambiant luminosity. This is obtained by taking the mean grey level of the image. If the mean grey level is higher that a given treshold (typically 10 or 20) then the observe script will pause for 15 min before make another verification of the mean grey level. Observe can also decide to begin observation if the ambiant luminosity is under the threshold when the starting observation time is more than 12 hours later.
crontabThe crond daemon is scheduling repetitive task on lilux system. Users who have the right to use crond can schedule their own tasks to crond. We are using crond to schedule a webcam acquisition every 15 min and to create an animated gif with the last 6 hours images. Allow sand user to use crondAllow sand to use cron by doing: sudo echo sand >>/etc/cron.allow Add program webcamimg to the crond scheduleEdit crontab cd crontab -e Add the following content: */15 * * * * /usr/local/bin/webcamimg Add sand user to the video group sudo usermod -a -G video sand USB GPS BU-353 from GlobalSatThe GPS is controlled by the gpsd server. The GPS startup may easily take 45 seconds (time to connect to available satellites). Sometime, the GPS do not succeed to connect to satellites. Most of the time this occur when satellites are masked by obstacles like mountains or buildings. The observe script is able to extract latitude and longitude from the GPS and use them for ephemeris calculations. To be sure that the gpsd server will startup with the system do the following steps. Create the script gpsstart into /etc/init.d . sudo echo "#!/bin/bash" > /etc/init.d/gpsstart sudo echo "### BEGIN INIT INFO" >> /etc/init.d/gpsstart sudo echo "# Provides: gpsstart" >> /etc/init.d/gpsstart sudo echo "# Required-Start: $remote_fs $syslog" >> /etc/init.d/gpsstart sudo echo "# Required-Stop: $remote_fs $syslog" >> /etc/init.d/gpsstart sudo echo "# Default-Start: 2 3 4 5" >> /etc/init.d/gpsstart sudo echo "# Default-Stop: 0 1 6" >> /etc/init.d/gpsstart sudo echo "# Short-Description: Start daemon at boot time" >> /etc/init.d/gpsstart sudo echo "# Description: Enable service provided by daemon." >> /etc/init.d/gpsstart sudo echo "### END INIT INFO" >> /etc/init.d/gpsstart sudo echo "/usr/sbin/gpsd /dev/ttyUSB0" >> /etc/init.d/gpsstart cd /etc/init.d sudo chmod a+x gpsstart cd /etc/rc5.d sudo ln -s ../init.d/gpsstart S94gpsstart UPS controlThe UPS is a power battery backup. It will protect the system against power fluctuations and will allow the system to continue its ongoing tasks during short power failure.
sudo service apcupsd start
apcaccess System rebootNow all the relevant software are installed, in order to activate all newly added functionalities, restart the computer. Development documentationUser's guide |