Giter Site home page Giter Site logo

koodi101-template's Introduction

Koodi101 Project Template

Frontend & Backend

How to run backend and frontend using docker-compose?

docker-compose build
docker-compose up

Hit Ctrl+C to stop the process

What if I want to run the project in the background?

docker-compose build
docker-compose up -d

DO NOTE: when you run the project with docker-compose on your own server, you need to do the following

export ENDPOINT='http://195.201.28.137:9000'
docker-compose build
docker-compose up -d

Replace 195.201.28.137 with the ip address of your team's server.

Nice, how can I now see if the project is already running?

docker-compose ps

Cool, how can I stop the project from running and start from scratch

docker-compose down --rmi all --remove-orphans

This also deletes the built docker images, if you do not want this, you can also just run

docker-compose down

How to run the backend and frontend without Docker?

Prerequisites

Backend

    cd backend
    npm install
    npm run dev

Frontend

    cd frontend
    npm install
    npm start

Internet of Things (IoT)

Raspberry pi – first time setup

  1. Login with pi:raspberry
  2. Type sudo raspi-config
  3. Change the password for pi user to something else
  4. Under network options, configure the wifi
  5. Under localization options, configure keyboard layout
  6. Under interfacing options, enable SPI and I2C
  7. Exit the raspi-config

RPI should now connect to wifi. You can check the ip address by typing ip addr

It should produce output like

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:f9:6a:c2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::799c:261a:a62:b56a/64 scope link 
       valid_lft forever preferred_lft forever

In this example, the ip address would be 192.168.1.101

If you want to use ssh to connect to your RPI, you can do it by writing

sudo systemctl enable ssh
sudo systemctl start ssh

Now you can connect from your own machine with ssh pi@<ip> if you are in the same network.

Setting up the sensor

To read data from the DHT11 humidity sensor with Raspberry Pi, it needs to be connected to the device. The sensor has three pins which need to be connected to corresponding IO-pins in Raspberry: VCC (power), ground and data. Each pin is labeled in the sensor. Corresponding pins in the IOT-device can be seen from Raspberry Pi's website, or with the pinout command on Raspberry's command line.

The default data pin is set to GPIO4. This can be changed by setting the desired pin to the GPIO environment variable e.g. when running the scipt with the command (more examples about running the script below):

GPIO=14 python3 rpi.py

Run the project

Let's update our system and install some needed libraries.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip git
sudo pip3 install requests Adafruit_DHT

To test if our application works, you can create a "request bin" for testing purposes in requestbin. You will get a bucket with url similiar to https://requestb.in/v6lrggv6

First clone your forked version of this repository to the Rasperry pi and go to the iot folder

git clone <url>

You can now try our app by starting it with

ENDPOINT=https://requestb.in/v6lrggv6 python3 rpi.py

Your requests should appear into your browser after you refresh it.

Starting the app automatically

One way to keep raspberry sending information without manual work, is to use cron to run our script every minute.

That can be achieved by opening crontab editor by typing crontab -e

Window will open and you can append the following line at end of the file, of course replacing the endpoint with a correct one.

* * * * * ENDPOINT=https://requestb.in/1ljyjs61 python3 /home/pi/koodi101-template/iot/rpi.py >> /home/pi/rpi.log 2>&1

So what does this mean?

  • * * * * * ENDPOINT=https://requestb.in/1ljyjs61 python3 /home/pi/koodi101-template/iot/rpi.py >> /home/pi/rpi.log 2>&1
    • When to run the script, see below
  • * * * * * ENDPOINT=https://requestb.in/1ljyjs61 python3 /home/pi/koodi101-template/iot/rpi.py >> /home/pi/rpi.log 2>&1
    • Pass environmental variable for script to be executed
  • * * * * * ENDPOINT=https://requestb.in/1ljyjs61 python3 /home/pi/koodi101-template/iot/rpi.py >> /home/pi/rpi.log 2>&1
    • Normal command to run a script with python
  • * * * * * ENDPOINT=https://requestb.in/1ljyjs61 python3 /home/pi/koodi101-template/iot/rpi.py >> /home/pi/rpi.log 2>&1
    • Append output to a file
  • * * * * * ENDPOINT=https://requestb.in/1ljyjs61 python3 /home/pi/koodi101-template/iot/rpi.py >> /home/pi/rpi.log 2>&1
    • By default, error messages wouldn't be logged into the file. With this definition, we redirect the to standard output and therefore into the same file.

Cron works by comparing current time to parameters at the beginning of every line. If it matches, it will run the script.

Our example is run every minute, although it should match at anytime, why is it so? Well, cron runs only every minute, so that is why this will work and that is why we can't schedule it to run more often.

There exist cool tool to "translate" cron time entries into human readable form: https://crontab.guru

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.