GithubHelp home page GithubHelp logo

jz2211 / iiot_wk5 Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 2.23 MB

IIoT Workshop -wk5: Implementation of a Flask Web Server for a simple IoT Application

License: MIT License

Python 91.40% HTML 8.60%
bme280 flask raspberry-pi web data-init iiot

iiot_wk5's Introduction

IIoT Workshop - Week 5

Project: Implementation of a Flask Web Server for a simple IoT Application

Example

Steps in a short list:

  1. RPi board should have wifi function. Check your RPi board model using command: cat /proc/cpuinfo
  2. Verify the system clock synchronization. System clock needs to be synchronized: timedatectl
  3. Check the python version. Requires python 3.7 version or above. Please note the double dash: python --version
  4. Install or update setup tools for python: sudo pip3 install --upgrade setuptools
  5. In order to use CircuitPython, we need to install a library called adafruit_blinka. Please see https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi for details. We can complete it by running the following script. It may take a while to complete the installation. Please be patient. Choose Y to Reboot Now after the installation:
    sudo pip3 install --upgrade adafruit-python-shell
    wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
    sudo python3 raspi-blinka.py
  1. Install BME280 library using command: sudo pip install adafruit-circuitpython-bme280
  2. Download the example code, connect BME280 to the RPi, and check if it works (Week 4 contents):
   wget https://raw.githubusercontent.com/JZ2211/IIoT_wk4/main/demo_bme280.py
   wget https://raw.githubusercontent.com/JZ2211/IIoT_wk4/main/savedata_locally.py
   python demo_bme280.py
  1. Check if Flask is installed: pip show flask
  2. If not, please install flask before continue: sudo apt install python3-flask
  3. Download/Clone the project from github in the Raspberry Pi (assume to the home directory /home/pi/):
   git clone https://github.com/JZ2211/IIoT_wk5.git
  1. Please make sure IIoT_wk5 and sub-directories LocalSite and templates has the write permission for the user owner. If not, change the permission using chmod u+w directory_or_filename.
  2. Obtain the IP address of the host using ifconfig or hostname -I, this IP address is the IP address of the Flask web server.
  3. Check if the example code program works: python IIoT_wk5/bme280_example.py
  4. Open another ssh terminal, run the following command and verify if it works: python IIoT_wk5/LocalSite/localsite.py
  5. If it works, setup crontab to run in the background. Run: crontab -e Add the following lines to the crontab file:
  @reboot sleep 20 && python /home/pi/IIoT_wk5/bme280_example.py
  @reboot sleep 20 && python /home/pi/IIoT_wk5/LocalSite/localsite.py
  0 0 * * 0 sudo reboot
  1. Reboot the RPi and now you can access the site use the url: http://<ip-address>:5000/ for the most recent data in plain text display or http://<ip-address>:5000/yyyy-mm-dd for data on the date. For example, if the Raspberry Pi IP address is 192.168.1.2, then URL should be 192.168.1.2:5000 or 192.168.1.2:5000/2023-07-28.

Additional: Initial State Example Steps:

  1. Connect to Raspberry Pi via ssh. Install the Initial State library using: pip install ISStreamer
  2. The example code initState_bme280.py should have been downloaded when you clone the project. If not yet, download the example code:
wget https://raw.githubusercontent.com/JZ2211/IIoT_wk5/main/initState_bme280.py
  1. Create an account at https://www.initialstate.com/. After you login, click on App Launch and create a stream Bucket. Note the Bucket Key and Access Key for later use.
  2. Modify the Bucket Key and Access Key at the top of the example code using the keys obtain in last step: nano initState_bme280.py Ctrl-X to exit and save the file.
  3. run the program: python initState_bme280.py. (If the file is under IIoT_wk5 directory, use: python IIoT_wk5/initState_bme280.py

iiot_wk5's People

Contributors

jz2211 avatar

Stargazers

 avatar

Watchers

 avatar

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.