CoSQM - a color hack to the SQM-LE for Light At Night Sensing
Software package
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
Introduction
The aim of this project is to develop a system capable of remotely controlling a light pollution monitoring system consisting in a 5 slot filters wheel in order to add multispectral detection capabilities to the Sky Quality Meter (SQM-LE). Four of the slots are filled with color filers (Red, Green, Blue, Yellow). The SQM is connected to a raspberry pi 3b (RPI) and a step motor filter wheel.
The linux distribution used for this system is raspbian Jessie.
We chose 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 RPI connected to the system act as a server. Also to promote the implementation of measuring network, the data acquired by the CoSQM is stored on a web server installed on the RPI.
From internet:
or
inside a private network
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 subsystems
Basic system installations and dependancies
If necessary, refer to this guide for the setting up of your Raspberry Pi.
- Install raspbian Stretch image on the microSD card link. We sugggest to use the NOOBS based installation.
- Put the microSD card on the RPI and power it on.
- Set time, time zone and date
- time zone have to be GMT
- Select None of the above
- Select GMT
- Set time and date
span class="st0">'2017-02-03 01:35:55'- Adapt the date and time to your situation.
- Create the sand account
- Edit /etc/passwd
sudo vim /etc/passwd
- Enter the input mode by typing < i > and add the following text at the end of the last line (N.B. < i > is the keyboard key i)
- Use the raspberry configuration tool to desactivate the Auto login
- Select 3 Boot Options Configure options for start-up
- Select B1 Desktop / CLI Choose whether to boot into a des
- Select B3 Desktop Desktop GUI, requiring user to lo
- Select Finish
- Accept to reboot the raspberry
- Login as sand
- Install the following packages
SSH
SSH 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.
- We must first be sure that the SSH server start automatically when you start the computer.
- Select 5 Interfacing Options
- SSH
- Yes (to enable ssh)
- SSH
- ok
- Finish
- Set up your personal firewall to allow the SSH and http connections to pass through the firewall.
Activating the pi camera module
- Use the raspberry configuration tool to activate the raspberry pi camera
- Select 5 Interfacing Options Configure connections to peripher
- P1 Camera Enable/Disable connection to the
- Yes (to enable camera interface)
- ok
- finish
- reboot
Setting pi password
Disabling the camera front LED
To forbid the LED light reflected by the window to interfere with the sky image, it is useful to shutdown the camera LED. Symply enter the following commands in the command line prompt.
Installing CoSQM applications
Latest available package release on bitbucket mercurial repository
- To download CoSQM apps:
- Copy apps to system directory:
- Copy local configuration file
Automatic startup of observe-sqm-stepper.bash code
Edit /etc/rc.local
Enter the input mode by typing < i > and add the following line before the exit 0 (N.B. < i > is the keyboard key i)
Then save the file by typing: <escape> :wq (N.B. <escape> is the keyboard key esc)
Apache server
We are using the Apache2 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:
- activate userdir module
sudo service apache2 restart
- Create the data directory and modify the permissions by doing:
- Edit the apache2 configuration file
Then type < i > to enter insert mode and add the following lines to the file
<Directory /var/www/html/data>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
Then exit and save by typing: <escape> :wq
- Restart the webserver
crontab
The 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.
Add program Camera.bash to the root crond schedule
Edit crontab
chose editor 3. /usr/bin/vim.basic
type < i > and add the following content:
00 12 * * * /sbin/shutdown -r now
Save and quit by typing: <escape> :wq
N.B. the time for daily shutdown above was set to noon (00 12). Please adapt to you time zone so that it will be executed around noon local time.
Then logout from the root
USB GPS Stratux Vk-162 Remote Mount USB GPS (U-blox)
The GPS code in no more compatible with the new version of gpsd. So that we recommend not to use the GPS module until that bug will be corrected. The latitude/longitude of your site can simply be written ii the /home/sand/localconfig file
The 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-sqm-stepper.bash is able to extract latitude and longitude from the GPS. To be sure that the gpsd server will work properly, do the following steps.
Edit the gpsd configuration
type < i > and set the following parameters
# Start the gpsd daemon automatically at boot time
START_DAEMON="true"
# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="true"
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group
dialout.
DEVICES="/dev/ttyACM0"
# Other options you want to pass to gpsd
GPSD_OPTIONS="-F /var/run/gpsd.sock -b -n"
Save and quit by typing: <escape> :wq
Shutdown button
Enter the following commands in the terminal
Real time clock
We are using the DS3231 RTC module to keep the date and time after powering off the system.
Update the RPI
sudo apt-get upgrade
Configure the I2C interface
This command will bring up the configuration tool; this tool is an easy way to make a variety of changes to your Raspberry Pi’s configuration. Today, however, we will only by exploring how to enable the I2C interface.
Use the arrow keys to go down and select “5 Interfacing Options“. Once this option has been selected, you can press Enter.
- On the next screen, you will want to use the arrow keys to select “P5 I2C“, press Enter once highlighted to choose this option.
- You will now be asked if you want to enable the “ARM I2C Interface“, select Yes with your arrow keys and press Enter to proceed.
- Once the raspi-config tool makes the needed changes, the following text should appear on the screen: “The ARM I2C interface is enabled“.
We must restart the Raspberry Pi. To do this first get back to the terminal by pressing Enter and then ESC.
Type the following command into the terminal on your Raspberry Pi to restart it.
Run the following command on your Raspberry Pi to install python-smbus and i2c-tools:
With those tools now installed run the following command on your Raspberry Pi to detect that you have correctly wired up your RTC device.
If you have successfully wired up your RTC circuit, you should see the ID #68 appear. This id is the address of the DS3231 RTC Chips.
Once we have the Kernel driver up and running the tool will start to display UU instead, this is an indication that it is working as intended.
Setting up the Raspberry Pi RTC Time
With I2C successfully setup and verified that we could see our RTC circuit then we can begin the process of configuring the Raspberry Pi to use our RTC Chip for its time.
- To do this, we will first have to modify the Raspberry Pi’s boot configuration file so that the correct Kernel driver for our RTC circuit will be successfully loaded in.
Run the following command on your Raspberry PI to begin editing the /boot/config.txt file.
Within this file, you will want to add the following line to the bottom of the file. DS1307
Once you have added the correct line for your device to the bottom of the file you can save and quit out of it by pressing Esc, then :wq and then Enter.
With that change made we need to restart the Raspberry Pi, so it loads in the latest configuration changes.
Run the following command on your Raspberry Pi to restart it.
Once your Raspberry Pi has finished restarting we can now run the following command, this is so we can make sure that the kernel drivers for the RTC Chip are loaded in.
You should see a wall of text appear, if UU appears instead of 68 then we have successfully loaded in the Kernel driver for our RTC circuit.
Now that we have successfully got the kernel driver activated for the RTC Chip and we know it’s communicating with the Raspberry Pi, we need to remove the fake hwclock package. This package acts as a placeholder for the real hardware clock when you don’t have one.
Type the following two commands into the terminal on your Raspberry Pi to remove the fake-hwclock package. We also remove hwclock from any startup scripts as we will no longer need this.
sudo update-rc.d -f fake-hwclock remove
Now that we have disabled the fake-hwclock package we can proceed with getting the original hardware clock script that is included in Raspbian up and running again by commenting out a section of code.
Run the following command to begin editing the original RTC script.
If you upgrade the operating system, you may need to redo the following step.
Find and comment out the following three lines by placing # in front of it as we have done below.
Find
exit 0
fi
Replace With
# exit 0
#fi
Once you have made the change, save the file by pressing Esc then :wq then Enter.
Syncing time from the Pi to the RTC module
Now that we have our RTC module all hooked up and Raspbian and the Raspberry Pi configured correctly we need to synchronize the time with our RTC Module. The reason for this is that the time provided by a new RTC module will be incorrect.
- You can read the time directly from the RTC module by running the following command if you try it now you will notice it is currently way off our current real-time.
- Now before we go ahead and sync the correct time from our Raspberry Pi to our RTC module, we need to run the following command to make sure the time on the Raspberry Pi is in fact correct. If the time is not right, make sure that you are connected to a Wi-Fi or Ethernet connection.
- If the time displayed by the date command is correct, we can go ahead and run the following command on your Raspberry Pi. This command will write the time from the Raspberry Pi to the RTC Module.
4. Now if you read the time directly from the RTC module again, you will notice that it has been changed to the same time as what your Raspberry Pi was set at. You should never have to rerun the previous command if you keep a battery in your RTC module.
You should hopefully now have a fully operational RTC module that is actively keeping your Raspberry Pi’s time correct even when it loses power or loses an internet connection.
Configuring the IP address of the SQM
The SQM-LE does not come shipped with a fixed IP address, so it may be necessary to fix that address before installing the unit into such a direct connection system without DHCP server software running.
- Install the unit into a DHCP system where the IP addresses are assigned to connected devices.
- Determine the SQM-LE IP address by querying the router or using the “Lantronix Device Installer” in Windows. In Linux, you may also use “nmap” to discover connected device IP addresses.
- Use a browser to go to the SQM-LE IP address as in the following example: http://192.168.1.nnn
- There is no default username and password, just press OK.
- The built in Lantronix XPort Device Server Configuration Manager will appear.
- Select NETWORK from the left side.
- Select the radiobutton associated with “Use the following IP configuration:”, and enter the IP address that you would like the unit to occupy in your direct connection system. This IP Address should match the one indicated in the /home/sand/localconfig file. It should actually be 192.168.0.101.
- IP Address: 192.168.0.101
- Subnet Mask: 255.255.255.0
- Default Gateway: field may be left blank.
- Press “OK” at the bottom then “Apply Settings” on the menu of the left side of the page and the unit will applythe settings and reboot in about 15 seconds. Since you may have changed the IP address, the web browser will notrespond unless you browse to the new address.
- The unit is now ready for connection into a non-DHCP system or a direct connection system with a crossover cable
Configure the network parameters of the raspberry pi
Edit the file /etc/dhcpcd.conf
Uncomment the section related to the static ip configurations but set ip address to 192.168.0.100
i.e.
interface eth0
static ip_address=192.168.0.100/24
static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
System reboot
Now all the relevant software are installed, in order to activate all newly added functionalities, restart the computer.
Optional stuff
D-LINK router configuration
The router is useful when CoSQM 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.
- Router local IP: 192.168.0.1
- Disable DHCP server and attribute Fixed IP as follow:
- 192.168.0.100 = raspberry pi
- 192.168.0.101 = SQM
- 192.168.0.other = any other computer connected temporarily or permanently to the router
- Create a virtual server to redirect port 2022 of the router toward SSH port 22 of 192.168.0.100
- Do the same for port 2080 to allow web access redirection (port 80)
- Create virtual server from port 2180 toward 192.168.0.101 port 80 (webcam server). This redirection will allow a user to see the webcam image from the web even if the computer is off.
UPS control
The 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.
- Use an APC UPS
- Do:
- In drakconf->system->services and deamons et enable the apcupsd deamon on startup. Then startup the deamon.
- Be sure that everything is working properly by doing: