Peter1999 profile picture Peter1999 a year ago 2
Blog

RC Viper ACR - Viper 1.0 part 2

RC Viper ACR - Viper 1.0 part 2 - Blog

Second part of Viper 1.0 RC Viper ACR Technologies & Systems shows final RPI setups, connection setups and cross-browsing.

Live Cross-browsing

If we connect a more devices at once, we always want to have actual datas on all of them. That’s why we’ve created a part of the code which sends the latest data when the page is loaded in browser. In addition, we needed to create a code which would send the received data from server as broadcast to all connected devices that process it, except the device from which the data came to server.

We’ll show it again on control of the lights. In addition to led.py, we still send the message to start.py through channel14. We will create a variable sender and set it to “i_send_it”. After receiving the message, start.py will send a message with the same content via the “datachanged” channel.

We subscribed this channel in the app. When we recieve a message, we check the variable sender to see if we’ve sent the message with change or not. If so, we only change the value of the sender variable to reset it for further use. If not, we will change the value of the sender variable and we will use the received data, in this case to check the checkbox light and display the corresponding layer of images in the rotatable 3D model.

RC Viper ACR - Viper 1.0 part 2 - Blog

This way we have created the data forwarding for all components of the page, from the start button to aerodynamic control. Each device receives data from datachanged channels, checks the sender, and makes changes, so we always have current model data on all connected devices.

Copy programs to RPI

When we have the programs finished, we need to get them into the model. We did not use unnecessary file transfers over the internet, we’d rather copy them to a USB key. We connected the USB Hub to the RPI and plugged into it the wifi module and USB with the program. Then we connected powerbank to RPI to turn it on.

We used SSH to communicate with RPI, so we needed to find out its IP address. We can find this address in the router, to which we connected to RPI during the initial installation and setting of RPI in the home network section. We connected to the same router on our computer, entered the default gateway into our browser and logged into the router. Here we found the RPI IP address. When we found the address, we started the PuTTy. In the Host name column, we entered the RPI address, selected the SSH option and clicked Open.

RC Viper ACR - Viper 1.0 part 2 - Blog

After that, the RPI requested the login information, first the name of user, then the password, after which we entered the RPI command line. We have execute the mount command, which showed us connected media devices, we searched for our USB, in this case its name was 12AB-33A3.

RC Viper ACR - Viper 1.0 part 2 - Blog

By cd /media/pi/12AB-33A3/Viper_1.0 command we moved to a folder with our programs. Using the sudo cp index.html /var/www/html command, we copied the files from this folder to the Apache2 Web server location, folders we copied using the sudo cp -r python /var/www/html command.

Then we have allowed the use of copied files. We used chown www-data:www-data -R /var/www/html and sudo chmod 755 -R /var/www/html commands. After entering these commands, we could see our app, when we entered the RPI IP address into the browser.

RC Viper ACR - Viper 1.0 part 2 - Blog

The last thing was to set up start.py to start when RPI is turning on. By sudo crontab -e command we got into a file that runs our script in the background when RPI is turned on. We scroll to the bottom of the program and added the line @reboot sudo python /var/www/html/python/start.py &. By pressing crtl + x, we saved the changes and press enter to confirm. Using the sudo shutdown command, RPI was shut down, then we disconnected the USB Hub, and connected the wifi module back. At this time, it was possible to connect to the model and control it on a local network inside the router area on which we set it, when RPI is turned on.

RC Viper ACR - Viper 1.0 part 2 - Blog

Connect the RPI to the smartphone access point

To keep the model out of router area and still retain PubNub functionality, we used instead of it a smartphone as an access point with enabled mobile internet.

When we had an enabled smartphone running as an access point with SSID and password set up, we connected RPI to this wifi like we did it during first programs installation. In the smartphone network settings, we can see the RPI address on which our app is located. The smartphone in the access point mode instead of the router allows us to manage the network or connected devices more easily, as well as suposed us the mobility required for this project.

Remote network access via Weaved

At this point, it was possible to connect to the model only in the local network via a specific IP address. However, we wanted to take advantage of all available control options, so we’ve set remote access to applications. This makes it possible to control the model from any device connected to the Internet from any place on the world.

We’ve used the Weaved for remote access. First, we created a user profile at https://www.remot3.it/web/remot3-it-is-the-new-weaved.html. The next step was to install the Weaved on RPI by instruction at https://www.weaved.com/installing-weaved-raspberry-pi-raspbian-os/, so we turned on RPI and connected to it through PuTTy via SSH.

The command to install the program is sudo apt-get install weavedconnectd. After installation, we started the program with the sudo weavedinstaller command. The program asks for the login details of the account we created. Then we came into a menu where we chose option 2 for http server and press enter. The program then asked if we want to install the service on the assigned port 80, we entered yes and confirm it by pressing enter. Another thing we’ve entered is the name of the service under which we’ll see our app on the Weaved site. We confirmed the name and the program returned to the main menu where we chose the exit, then we shutdown RPI with the sudo shutdown command.

RC Viper ACR - Viper 1.0 part 2 - Blog

By creating an HTTP server in Weaved, we have made model control available from any device connected to the Internet. Now we just need open the https://developer.weaved.com/portal/login.php page in our browser, log in, and click on the service we created under the name Viper-App under My Services. After clicking, we will see our model control page. LAN connectivity is still available via a specific IP address, so when we are in area of an access point, we do not have to waste the mobile data unnecessarily.

Testing of functionality

The last step was to test the functionality. First, we’ve turned on the smartphone’s data and access point. After checking RPI and other electronics, we connected RPI to the powerbank, we also switched on the transmitter and the ESC in the model. We connected with the computer to an access point and tested the model features in the LAN. Then we connected via Weaved and tested the functionality of all parts of the model. All of the systems were functional, so we completed the Viper 1.0 version and accomplished the goals of this project.

So now Viper 1.0 was finished, that means only one thing – next time Viper 2.0! But I need to mention one thing – to this point was every piece of code, every piece of project created on netbook Acer Aspire one. With this I want to say that you do not need the best hardware to work, you need only idea, desire to work and strong will. Stay tuned and have a nice day!