pushkarkadam / iot_building

IoT project that collects the data from LoRa sensors using The Things Network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IoT building

A python project to extract the data from the things network.

This project is a work in progress. There is only one file named subscribe.py that connects to the MQTT broker on TTN.

The credentials are not available in the code. Set up the local environment with your own TTN and MongoDB credentials.

Installation

Clone this repo from github

Download dependencies

  1. Install virtualenv:

    $ pip3 install virtualenv
    
  2. Go to the root of the project and create a virtual environment.

  3. For Mac/Linux:

    $ virtualenv venv
    
    # Activate venv
    $ source venv/bin/activate
    
  4. For Windows:

    $ python3 -m venv venv
    
    # Activate venv
    $ venv\Scripts\activate
    
  5. For Raspberry Pi::

    $ Python3 -m virtualenv venv

  1. Install dependencies in the virtual environment:

    $ pip3 install -r requirements.txt
    

TTN credentials

This repository does not contain any username or API keys.

The username and API key is contained within the .env file.

Alternatively, use the following code:

$ export API_KEY=YOUR_API_KEY

This will create environment variables only for that session.

Installing MongoDB

Follow the instructions from MongoDB for your OS.

Setting up MongoDB locally

The following instructions are for Ubuntu/Linux.

  • Start MongoDB by the following command:

    $ sudo systemctl start mongod
    
  • Check database connection status:

    $ sudo systemctl status mongod
    
  • Stop database connection:

    $ sudo systemctl stop mongod
    

Setting up MongoDB on Atlas

  • Create an account on MongoDB Atlas.
  • Ask for username and password to read/write the database.
  • Checkout the MongoDB documentation to access the DB with python.
  • Checkout the Pymongo documentation to use MongoDB with python.

Note to contributors

  • This project follows git flow approach for development.
  • DO NOT start developing on master branch.
  • Read more about Git Flow.

Running the Scripts

Make sure that the you have connected the MongoDB by following the instructions in setting_mongod.

In the terminal, run the following:

$ python3 subscribe.py

This script will populate the database. To quit the program type CTRL+C in the terminal.

Raspberry Pi installation instructions

You may want to start the Raspberry Pi on console with auto-login.

  1. Downlad virtual environment:

    pip3 install virtualenv
    
  2. Clone the repository in the Documents folder on the RPi:

    cd Documents
    git clone https://github.com/pushkarkadam/iot_building.git
    
  3. Install the virtual inside the code directory's root environment:

    cd iot_building
    Python3 -m virtualenv venv
    
  4. Running the code in the start up

    Type to following to edit .bashrc file after opening nano text editor:

    sudo nano /home/pi/.bashrc
    

    Add the following lines:

    xhost +
    echo Running at boot
    sleep 1m
    git -C /home/pi/Documents/iot_building pull
    source /home/pi/Documents/iot_building/venv/bin/activate
    pip3 install -r '/home/pi/Documents/iot_building/requirements.txt'
    python3 /home/pi/Documents/iot_building/subscribe.py
    

    Exit Nano editor by pressing CTRL+X.

  5. Reboot Raspberry Pi:

    sudo reboot
    

About

IoT project that collects the data from LoRa sensors using The Things Network


Languages

Language:Python 100.0%