Skip to content Skip to sidebar Skip to footer

How to Connect Wifi With Raspberry Pi 3 for Data Uploading

The Raspberry Pi is a little computer that yous tin can become for as low as USD $5 and on which you can run many unlike types of software and build many different projects.

In this commodity, I'm going to guide you through the process of setting it up as a home development server and deploying a total-stack JavaScript application that you tin can admission from outside your network. This is peachy for setting up your own remote digital workspace, or simply to accept control over the hardware you utilize for development.

What Practice You Need for This Raspberry Pi Domicile Server?

While this is now a Raspberry Pi iii tutorial in particular, it should still piece of work with models going back to the beginning generation—if y'all have an older model or a Raspberry Pi Zip, delight let us know your feel in the comments below.

In addition to the Raspberry Pi board itself, you will need:

  • A Micro USB charger
  • An Ethernet cable
  • A microSD card (minimum 8GB, and cards upwardly to 32GB seem to work fine)

These volition as well come up in handy during the initial setup:

  • A USB keyboard
  • An HDMI cable and monitor

The Raspberry Pi OS: Raspbian

Installing an operating system onto a Raspberry Pi is simple. First, using your reckoner, install the boot paradigm onto a microSD card. Then simply insert the card into the Raspberry Pi and boot from there.

Raspbian is a Linux distribution ported from Debian vii.0 (Wheezy), and is the official OS for Raspberry Pi optimized for the device's architecture. While there are other options for running your favorite OS on the Pi, nosotros'll use Raspbian because of its simplicity.

This tutorial has been updated to work with this version (or later) of Raspbian:

          Kernel version : #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) Kernel release : 4.ix.0-viii-amd64                  

To install Raspbian, caput to the official download page and download the zip file with the latest Raspbian version.

Then, insert the microSD carte into your figurer's SD card slot or adapter. Depending on your calculator'southward operating system, follow the instructions provided on Raspberry's website for Linux, Mac Bone, or Windows.

Once the process is finished, eject the SD menu from your computer and insert information technology into the Raspberry Pi. Connect the Raspberry Pi to your router using the Ethernet cable, and plug in the Micro USB charger, which will start the Raspberry Pi booting.

For the initial configuration, at that place are two options:

  • If y'all have a USB keyboard and an HDMI monitor, you can plug them into the Raspberry Pi for the initial setup.
    • Your Pi should recognize these devices as soon every bit they are plugged in.
    • The first time the Pi boots, it will automatically run raspi-config. Afterward the first kicking, you will demand to run sudo raspi-config yourself in society to configure the device.
  • If you don't have them, you can connect to your Raspberry Pi while it is on using SSH:
    • First, you need to find the IP address of your Raspberry Pi in your local network. This tin exist done by connecting to your router'due south admin page, or by using a network tool like nmap.
    • In one case you accept the device's IP accost, connect to it using SSH from your terminal (or through Putty if you're using Windows). The default user is pi, and the default password is raspberry. So, for example, if the IP address is 192.168.1.16, run ssh pi@192.168.1.16 and enter the password when prompted.
    • When you lot are connected, run sudo raspi-config.

raspi-config will walk you through the final setup. You can configure all the options simply the most important are the first two: to expand the filesystem, ensuring that all the SD carte du jour storage is available for the OS, and to alter the password for the default Pi user, so that your server volition be protected from intruders.

Raspi-config

Install a Web Server (Nginx) on Your Raspberry Pi

Next, you'll install the web server. I prefer Nginx because information technology has a small memory footprint, and because information technology plays well with Node.js (which you'll be setting upwards later). Other web servers, such as Apache or lighttpd, would work as well, but we'll use Nginx for this sit-in.

Before you starting time installing anything, you demand to be sure everything is up-to-engagement past running these commands on the Pi:

          sudo apt-get update sudo apt-get upgrade                  

And then y'all can install Nginx using apt-go:

          sudo apt-get install nginx                  

Once installation is completed, start the server past running:

          sudo service nginx start                  

If you lot didn't take to figure out the local IP of your Raspberry Pi in the previous step, it's time to discover out by running ifconfig. The output for your ethernet adaptor will be under eth0, and with its local IP accost labeled inet addr.

One time yous know the IP address, you tin can bespeak your figurer's browser at it, where yous should see the default "Welcome to Nginx" message.

Open to the Web: Port Forwarding

You tin skip this step if you lot are non planning to admission your Raspberry Pi from outside your local network. But for those wanting to access their server from other locations, let's make certain that's possible.

In a typical home network, devices connected to the router are invisible to the outside globe. Just your router tin be reached from outside, using your network's external IP address. Your router is responsible for determining which incoming traffic is allowed into the network, and which device information technology should exist sent to.

When a device on the local network initiates a connection (for case, when y'all open a website on your browser), the router recognizes the incoming response traffic as beingness part of this connection, and allows it through. However, if the router receives incoming traffic that is not part of an open connection (for example, when an outside device attempts to initiate a connectedness with an within device), it will block the incoming traffic from crossing into the network. This is an important security feature to protect the network!

And then how tin can you lot connect to your Pi from exterior? The answer is port forwarding. The router must be configured to permit incoming connections on specific ports to pass through, and be sent to the right device. By the default, the HTTP protocol uses port 80, and SSH uses port 22, so these are the two ports that you need to open on your router in order to admission your spider web application, and permit secure connections for managing your server.

Port forwarding.

The steps to configure your router to open and forward the ports may vary depending on your internet provider and the brand of your router, but in whatever case, you lot should be able to attain information technology through the advanced configuration options of your router's admin page. Simply look for an choice with a name like "Forwarding," "Port Forwarding," or "Network Address Translation."

You lot need to open a port for HTTP connections, and another i for SSH. The basic idea consists of forwarding data addressed to these two external ports to your Raspberry Pi, with web traffic going to port 80 where Nginx is listening, and SSH traffic going to port 22, where the SSH server accepts connections from external computers. Hither's an example of how this might wait in your router's configuration page:

Port forwarding configuration table.

Port forwarding configuration if your Raspberry Pi's internal IP address is 192.168.1.16. All incoming traffic spring for ports lxxx or 22 are forwarded to this internal address.

You can decide your router's external IP accost past only typing "what'due south my ip address" into Google. If you then motion outside your router's network, you lot tin examination that port forwarding is working by opening an SSH connection with ssh pi@{external IP address}. Also, HTTP port forwarding can be tested past entering the external IP address into your browser's accost bar. But keep in heed that port forwarding allows anyone from outside to access the device on these ports if they know your router's external IP.

If you don't have a static IP, and so you tin ready dynamic DNS. Information technology'southward a very simple and easy pace. You tin can fix up dynamic DNS from your router or you can configure your Raspberry Pi for it. I'm not going to cover how to configure DDNS here, but BitPi.co has a good tutorial on the subject if needed.

Install the Framework: Full-stack JavaScript

You tin run most web frameworks on pinnacle of Nginx, simply allow's see how to get full-stack with JavaScript. To do this, you demand to install Node.js and MongoDB.

Nowadays, Node.js is easily installed onto a Raspberry Pi with:

          sudo apt-get install nodejs                  

Once information technology finishes installing, you can check if it'due south working by running node -5.

Now yous can install MongoDB but by typing:

          sudo apt-get install mongodb                  

Just exist aware that if you always need to turn off the Raspberry Pi, you demand to shut down the service first in order to avoid database abuse:

          sudo service mongodb stop                  

Deploy Your App

You tin develop on your local automobile, and then push your changes to a Git repository on BitBucket. Since Raspbian comes with Git pre-installed, you tin can then pull your latest application code onto the device and run it.

Scaffold the Project

Start let'southward fix upwardly some application lawmaking and push information technology to a Git repository. There are many ways of starting an application, but one of my favorites is generator-angular-fullstack, which scaffolds both server and client code.

Install generator-angular-fullstack on your computer:

          npm install -g generator-angular-fullstack                  

Create a new directory for your application:

          mkdir my-app cd my-app                  

And scaffold the application:

          yo athwart-fullstack my-app                  

Create the Repository and Push the Code

Now create a repository in BitBucket, as described hither. So set upward your local directory:

          git init git remote add together origin git@bitbucket.org:USER/REPO.git                  

So you can commit and push the code:

          git add . git commit -m 'Initial commit' git button -u origin principal                  

The generator comes with the grunt-build-command plugin, which allows you to commit the build code to a specific branch in your repository. Just add the configuration for BitBucket to Gruntfile.js in your application's root directory:

          buildcontrol: {    options: {       dir: 'dist',       commit: truthful,       push: truthful,       connectCommits: imitation,       message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'    },    bitbucket: {       options: {          remote: 'git@bitbucket.org:USER/REPO.git',          branch: 'build'       }    } }, // ...                  

At present run:

          grunt build                  

…to create the distribution folder, followed by this:

          grunt buildcontrol:bitbucket                  

…to commit and push the code to the build branch in your repository.

Generate the SSH Key

You now accept your code hosted. Before y'all can deploy it to your Raspberry Pi, y'all need to generate an SSH primal for the Raspberry Pi and add together it to your BitBucket account. Nosotros'll run through this step quickly, merely if y'all accept whatsoever problem, delight follow the BitBucket guide. And then, log back into your Raspberry Pi terminal, and generate the public/private cardinal pair:

          ssh-keygen                  

And so, kickoff the agent:

          ssh-amanuensis /bin/bash                  

And add together the key to the agent:

          ssh-add /home/pi/.ssh/id_rsa                  

Now you just demand to output the content of the public central:

          cat /home/pi/.ssh/id_rsa.pub                  

…and so you tin can copy and paste it into BitBucket.

In BitBucket, click on your profile picture and go to Manage account. Nether SECURITY, observe SSH keys, and click the push button Add key.

Clone the Repository

There isn't a convention for where to place the code of your apps, merely you can create a /var/www directory and put all your projects there.

          cd /var sudo mkdir www                  

To avert the use of sudo when you want to place files in the webroot, you can change the owner to your Pi user, and the group to www-data, which is used past Nginx:

          sudo chown -R pi:www-data world wide web cd www                  

Now, you tin can clone the build branch of your repository and install the dependencies:

          git clone git@bitbucket.org:USER/REPO.git --branch build --single-co-operative cd REPO npm install --production                  

Once information technology's finished, yous can start your app, setting the environment to production:

          export NODE_ENV=production; node server/app.js &                  

Now, point your calculator browser to the device IP address to check if information technology works.

Wish you had a dev server yous could call your ain? Y'all tin, with a #RaspberryPi.

Configure Nginx Contrary Proxy

There is one more than footstep remaining to make your application accessible from the outside. Although Nginx is listening on port 80, where it will receive HTTP requests for your Pi, the Node application itself is listening on a different port (for case, port 8080). Therefore, you need to configure Nginx to act as a reverse proxy, recognizing requests intended for your application, and passing them to Node.

Nginx keeps the configuration file for each application it serves in the sites-bachelor folder:

          cd /etc/nginx/sites-available/                  

Here, you tin copy the default configuration file and edit at your convenience:

          sudo cp default my-app sudo nano my-app                  

The terminal configuration file should wait like this, with Nginx acting equally a proxy to the Node.js server:

          server {    listen 80;    root /var/world wide web/my-app/;                  # identifies the location of the application yous are configuring    server_name my-app.dev;                 # identifies the hostname used by this application's traffic    location / {       proxy_pass http://localhost:8080/;   # configures the back-end destination for this traffic    } }                  

In society to enable this configuration, y'all need to create a symlink in the sites-enabled folder, where Nginx looks for active configurations during runtime:

          sudo ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/my-app                  

And reload the service to activate these changes:

          sudo service nginx reload                  

At this betoken, your application is ready to receive HTTP traffic intended for the my-app.dev domain (thanks to the server_name my-app.dev directive you configured above). The final event yous need to solve is how to brand traffic yous ship from outside match this domain name. Although y'all could buy a domain name and point it to your IP, the hosts file comes to the rescue and makes that unnecessary.

On the workstation from which you will access the site, just add your router's external IP accost, and match information technology with the host name my-app.dev. Whatsoever HTTP traffic you generate for my-app.dev volition and so be sent straight to your router, with the correct host name in the Host HTTP header.

On Windows, with administrator privileges, you tin can edit the file located in c:\windows\system32\drivers\etc\hosts with the notepad. On Linux and Mac you can use the terminal with sudo nano /etc/hosts and sudo nano /private/etc/hosts respectively.

          ## # Host Database # # localhost is used to configure the loopback interface # when the arrangement is booting. Practice not change this entry. ## 127.0.0.1       localhost 255.255.255.255 broadcasthost ::ane             localhost  212.124.126.242 my-app.dev    # add your host name to the list                  

What's Adjacent?

Now that everything is fix up, yous can deploy as many applications every bit yous want to your Raspberry Pi, and install forever or pm2 to go along your Node.js servers alive.

And just remember that if something goes incorrect, you tin can only wipe the SD bill of fare and starting time again from scratch!

Raspberry Pi development server in action.

murphycoped1954.blogspot.com

Source: https://www.toptal.com/raspberry-pi/how-to-turn-your-raspberry-pi-into-a-development-server

إرسال تعليق for "How to Connect Wifi With Raspberry Pi 3 for Data Uploading"