📜 ⬆️ ⬇️

The monitoring system in the car for him on the Raspberry Pi. Part 1

Introduction


Good day.
Once I purchased Raspberry Pi without any kind of purpose - as soon as the mention of it started in Habré. I started aimlessly launching a ftp server, trying Node.js and other small server business until I purchased a new car. Of course, I didn’t do anything that could be found on the Internet like a remote garage opening - due to the normal lack of knowledge of the Linux system and server programming languages. The car became dear to me and an idea arose - to put the raspberry in a car with USB devices screwed to it: GPS, Web-camera, 3G-modem - for which the 2nd Raspberry was purchased.
In this article I will describe the preparation: installing Node.JS, setting up OpenVPN and 3G.

Plans

It is necessary that Malina was installed in the car with GPS and a webcam connected to it and that at any moment I could even watch from my mobile phone what was happening with my car.

So let's get started


Installing Node.JS

Install Node.JS from the site, as version 0.6.18 is in the repository.
sudo mkdir /opt/node wget nodejs.org/dist/latest/node-v0.10.20-linux-arm-pi.tar.gz tar xvzf node-v0.10.20-linux-arm-pi.tar.gz sudo cp -r node-v0.10.20-linux-arm-pi/* /opt/node 

Now we add the path to Node.JS to the environment variables so that we do not have to prescribe a long path. To do this, edit the file:
 sudo nano/etc/profile  : NODE_JS_HOME="/opt/node" PATH="$PATH:$NODE_JS_HOME/bin" 

As a result, the head of this file will look like this:
 # /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). if [ "`id -u`" -eq 0 ]; then PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" else PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games" fi NODE_JS_HOME="/opt/node" PATH="$PATH:$NODE_JS_HOME/bin" export PATH 

We will need to install some modules globally (eg npm install -g express), so we will make our user the node directory:
 sudo chown -R pi /opt/node 

Checking:


To write the code in the future, create a folder:


According to the rules for finding modules, we will make a symlink of the global directory of modules in the home directory, more information about this can be found here: nodejs.ru/doc/v0.4.x/modules.html#_u0417_u0430_u0433_u0440_u0443_u0437_u043A_u0430_ukh147
 ln -s /opt/node/lib/node_modules ~/node_modules 


')
OpenVPN setup

Since there is no possibility to connect via SSH or somehow get in touch with Malinka via OpCoS except for paying for external IP services, let's configure OpenVPN.

Training


  • there is a router with a static external IP address
  • one Malinka is connected to the router via Ethernet
  • There are 2 Raspberries, which will be far away and only available via 3G


To do this, we will issue a physical IP address for Raspberry connected to the router:


Forward OpenVPN requests to the router from the outside to our "home" Malin, and for one SSH and HTTP:
We will install Node.JS on home Raspberry just as it was done before.

Installation

 sudo apt-get install openvpn -y 

About the generation and configuration has been written a lot both in Habré, and beyond. I used the following articles: habrahabr.ru/post/188474 , adw0rd.com/2013/01/10/openvpn/#.UmTuCBCpFZQ , www.volmed.org.ru/wiki/index.php/%D0%9D%D0% B0% D1% 81% D1% 82% D1% 80% D0% BE% D0% B9% D0% BA% D0% B0_OpenVPN_% D1% 81% D0% B5% D1% 80% D0% B2% D0% B5% D1% 80% D0% B0 .

I will give katy their settings.


For the client, in the remote field is my external static address on the router.

3G setup

Training

To access 3G, I bought a Huawei E1550 3G modem from Megafon, with its SIM card.

When connecting a modem is defined as a disk, it is necessary to switch it to modem mode.


To switch to modem mode, you must install the program and reboot.
 sudo apt-get update && sudo apt-get install usb-modeswitch -y sudo reboot 


Let's see our devices:


Actually setting up the connection

Create a directory:
 $ mkdir ~/3g && cd ~/3g 

Download the 3G connection setup program:
 wget http://sourceforge.net/projects/vim-n4n0/files/sakis3g.tar.gz/download tar -xzvf sakis3g.tar.gz 

Download the add-in program on UMTSKeeper (this is an add-on over sakis3g and it was written by the same author =))
UMTSKeeper should be in the same directory as sakis3G
 $ wget http://zool33.uni-graz.at/petz/umtskeeper/src/umtskeeper.tar.gz $ tar -xzvf umtskeeper.tar.gz 

Install PPP support
 sudo apt-get install ppp -y 

Now we will try to establish a 3G connection:
 sudo /.sakis3g --interactive 

In the first option, select
Connect with 3G
, and in the second 11th day -
Custom APN
.
For megaphone settings are as follows:
  • APN: internet
  • APN_USER: megafon
  • APN_PASS: megafon

If everything is correct, the program will display a message about successful connection.

In order for the connection to be restored when the connection is broken, we already have the UMTSKeeper.
 sudo /home/pi/3g/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1001' APN='CUSTOM_APN' CUSTOM_APN='internet' APN_USER='megafon' APN_PASS='megafon'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --nat 'no' & 

Instead of the value 12d1: 1001 ', you must specify your device number from lsusb .

Now let's see the magazine:


Everything works perfectly!
Now let's write this command to autoload:
 crontab -e 



Conclusion


As a result, we have this situation:
There is a router with an external static IP address, to which the “home” Raspberry Pi is connected and acting as the OpenVPN server (and http in the future) and the “car” Raspberry Pi, which is connected to the “home” OpenVPN using a 3G modem.

Some pictures for a change:




PS

I spend most of my time on the front-end, so the server part might not be perfect somewhere.
With positive feedback, in the next article I’ll write about connecting and setting up a GPS receiver and a webcam via a USB hub.

Source: https://habr.com/ru/post/202012/


All Articles