Skip to content

Raspberry Pi 3 IoT Demo using Docker & Python 2.7 to query a temp sensor (DHT11/DHT22) using a RESTful API

License

Notifications You must be signed in to change notification settings

allthingsclowd/docker_rpi3_python_iot_api_dht_11_22

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi 3 IoT Demo using Docker & Python 2.7 to read a DHT11 or DHT22 Temperature and Humidity Sensor using a RESTful API

The Dockerfile in this repo can be used to build an IoT demo container that runs a Python 2.7 application that will work with the GPIO pins configured to match the following setup : rpi3-dht11-dht22_bb rpi3-dht11-dht22_schem

The docker image can be found here: https://hub.docker.com/r/allthingscloud/rpi3-python-iot-api-dht/

To build the dockerfile on a raspberry pi 3 after cloning this repository:

docker image build --tag allthingscloud/rpi3-python-iot-api-dht -f Dockerfile . 

Launch as follows:

docker container run -d -p 4321:8989 --name my-python-iot-demo --device /dev/gpiomem allthingscloud/rpi3-python-iot-api-dht

Verification

Using curl

curl http://raspberry-pi-ip-address:4321/   <-- Returns both the temperature and the humidity readings in JSON format
						  
curl http://raspberry-pi-ip-address:4321/temperature   <-- Returns a JSON temperature response
						       
curl http://raspberry-pi-ip-address:4321/humidity   <-- Returns a JSON humidity response

Using a browser

Navigate to :

http://raspberry-pi-ip-address:4321/   <-- Returns both the temperature and the humidity readings in JSON format
					     
http://raspberry-pi-ip-address:4321/17/on   <-- Returns a JSON temperature response
						  
http://raspberry-pi-ip-address:4321/17/off   <-- Returns a JSON humidity response

Raspberry Pi 3 - Docker Installation

Please check the official documentation at https://docs.docker.com

I used the following steps :

sudo apt-get update

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
	
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88

echo "deb [arch=armhf] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
     $(lsb_release -cs) stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list   
   
sudo apt-get update

sudo apt-get install docker-ce

About

Raspberry Pi 3 IoT Demo using Docker & Python 2.7 to query a temp sensor (DHT11/DHT22) using a RESTful API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages