Example
- RPi board should have wifi function. Check your RPi board model using command:
cat /proc/cpuinfo
- Verify the system clock synchronization. System clock needs to be synchronized:
timedatectl
- Check the python version. Requires python 3.7 version or above. Please note the double dash:
python --version
- Install or update setup tools for python:
sudo pip3 install --upgrade setuptools
- 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
- Install BME280 library using command:
sudo pip install adafruit-circuitpython-bme280
- 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
- Check if Flask is installed:
pip show flask
- If not, please install flask before continue:
sudo apt install python3-flask
- 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
- 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
. - Obtain the IP address of the host using
ifconfig
orhostname -I
, this IP address is the IP address of the Flask web server. - Check if the example code program works:
python IIoT_wk5/bme280_example.py
- Open another ssh terminal, run the following command and verify if it works:
python IIoT_wk5/LocalSite/localsite.py
- 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
- 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 orhttp://<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.
- Connect to Raspberry Pi via ssh. Install the Initial State library using:
pip install ISStreamer
- 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
- 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.
- 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. - run the program:
python initState_bme280.py
. (If the file is under IIoT_wk5 directory, use:python IIoT_wk5/initState_bme280.py