Skip to content

A tutorial for create IoT enabled Raspberry Pi's

Notifications You must be signed in to change notification settings

xbnrxout/IoT-XR-Proj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

IoT-XR-Proj

This project will be a comprehensive tutorial as I learn about
Arduino, Raspbery Pi4, and Wifi-Chips.

This README will be constantly updated as I progress and learn

Current Devices

Required Tools

Project 1

Create node server with endpoints for requests from devices

Step 1 - Get Raspian Image


Download Raspian Buster Lite


Step 2 (optional) Unzip image


Unzip the image


Step 3 - Create Raspbian Bootable


The simplest method I found, that had the same desired
outcome as manual tools was balenaEtcher

Simply navigate to the .zip or the .img Raspbian file and
select the MicroSD you wish to create as a bootable


Step 4 - Create SSH file


Navigate into the /boot directory on the MicroSD
and create a ssh file


Step 5 - Test your setup


  • Connect the Power to your Pi
  • Connect the LAN cable from your Pi to your home router
    • This should be the same router your PC is connected to

Your Pi green LED should blink for at least 5 second

Do not worry if you green LED stops blinking!

As long as your red LED is solid after this, it mean we are good to go


Step 6 - Connecting to your Pi via SSH


This is operating system specific

Windows


TODO: I will fill this section in once I have proved a reliable solution


Linux | Mac


We need to now find the IP address of the Pi in our network
First lets query our network for devices

Install nmap

Linux

sudo apt install nmap

Mac

brew install nmap

Now we need to determine our IP, but more importantly our subnet mask

In terminal type the command

ifconfig

You should get a similar output:

My CIDR is /24 based on my Subnet mask of 255.255.255.0

This shows that my ip range is 192.168.0.0 --> 192.168.0.255

Our Pi must have an IP in that range

Now we need to scan our network to find devices

In terminal type in

sudo nmap -sn 192.168.0.0/24

This will not work without a CIDR value added in

The command does not tell you what is happening
So if you press the up arrow key it will show you the scanning progress as shown below

We should get a table of ARP requests with a device with hostname
of Unknown or RaspberryPi with an IP associated.

We can now go ahead and SSH into our Pi

The default username is

pi

with a default password of

'raspberry'

In terminal type

ssh pi@IP_ADDRESS

On my PC I type in

ssh [email protected]

A prompt will display and simply type in the default password

You might be prompted to change your password. Do so now

You have now successfully logged into your pi!


Step 7 - Install Nodejs and NPM


I like to install the LTS(Long Term Support) version as they are less prone to bugs and latest release

On the pi type in

sudo apt-get install curl

then

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

Change the setup_12.x to the desired version you required

e.g. setup_13.x for version 13
or setup_14.x for version 14

then sudo apt-get install nodejs

This will install the PPA desired version of Nodejs

check the node version

node -v
v12.13.1

check the npm version

npm -v
6.12.1


Step 8 - Create Directory for project


Still in the SSH connection
type the command

mkdir node-app

This creates and empty directory for your node app


Step 9 - Create an SSH remote session in VSCode


type

exit

to stop and logout of the Pi

Open VSCode and press

F1

to open the Command Palette.
Search for and Select

'Remote-SSH: Connect to Host...'

Enter your ssh connection string

pi@_IP_ADDRESS_

You will be prompted for a password, so the password you have set on the pi
is what you enter here


Windows


TODO: I will fill this section in once I have proved a reliable solution


Linux/Mac


You can now edit and configure your server from here.

Select terminal from the top menu and then select New Terminal

Open File Explorer from the side menu

Select Open Folder and select from the dropdown menu that pops up our
node-app directory and press OK

Re-enter your password

We can now manage our node-app from here without having to using Vi/Vim
and this gives us a familiar interface to create and edit our app


Step 10 - Add Git and SSH key for Github/Gitlab/Bitbucket


Within the terminal on VSCode let's install git
type in

sudo apt install git

We should now create an ssh key for secure connection to github
(Also so we dont have to enter a username and password everytime)

type in

ssh-keygen -t rsa -b 4096 -C YOUR_EMAIL_ADDRESS_ON_GITHUB"

Press enter unless you wish to change the directory the files are generated in

You can default on the next few options by pressing enter

Once you have generated your key. Log in to your Github/Gitlab/Bitbucket account, navigate to the add ssh-key section.

To see your ssh-key, go back to the pi terminal on VSCode and type

vim ~/.ssh/id_rsa.pub

This will show you your public key

Ensure you select the .pub file, as you do not want to expose your private key

Your ssh-key is now presented.

Using your mouse, select everything in the file

Be careful, and make sure you select everything

Right-click and copy.

Now paste this key into your SSH-Key on Github/Gitlab/Bitbucket

Enter the desired name. I like to use the Name of the PC + Name of the OS

XavierDesktopUbuntu1804

You have now a secure connection between your Pi and Github/Gitlab/Bitbucket


About

A tutorial for create IoT enabled Raspberry Pi's

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages