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.
Clone this repo from github
Install virtualenv:
$ pip3 install virtualenv
Go to the root of the project and create a virtual environment.
For Mac/Linux:
$ virtualenv venv # Activate venv $ source venv/bin/activate
For Windows:
$ python3 -m venv venv # Activate venv $ venv\Scripts\activate
- For Raspberry Pi::
$ Python3 -m virtualenv venv
Install dependencies in the virtual environment:
$ pip3 install -r requirements.txt
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.
Follow the instructions from MongoDB for your OS.
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
- 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.
- This project follows
git flow
approach for development. - DO NOT start developing on
master
branch. - Read more about Git Flow.
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.
You may want to start the Raspberry Pi on console with auto-login.
Downlad virtual environment:
pip3 install virtualenv
Clone the repository in the Documents folder on the RPi:
cd Documents git clone https://github.com/pushkarkadam/iot_building.git
Install the virtual inside the code directory's root environment:
cd iot_building Python3 -m virtualenv venv
- 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
.
Reboot Raspberry Pi:
sudo reboot