IoT System Development with Raspberry Pi and Django

Slides:



Advertisements
Similar presentations
POE-Client Overview The POE-CLIENT product is a Zero client powered by power over Ethernet. Unlike other zero clients this board directly drives all internal.
Advertisements

TECH SKILLS COMPUTER BASICS
HARDWARE Rashedul Hasan..
Digital Skills Academy. What is a Computer Super Calculator Digital Skills Academy.
Computer Basics I Course Outline 1: What is a computer? 2: What is an operating system? Using a Desktop Computer 3: What are the basic parts of a desktop.
Design & Developed by: EATL
Components of a Personal Computer (PC) Adapted from Region IV TIFF Training.
Introduction to the Raspberry Pi ® Saman Amighi 10/2013 ® Raspberry Pi Foundation.
Building an APRS Weather Station for Under $300 APRS Wx station presentation by Chris, W8CWG, Mound Amateur Radio Association 3 Dec 2014.
Computer Architecture Ports.  There are lots of external devices that you can connect to your computer. All external devices connect to the computer’s.
Embedded Programming and Robotics Lesson 12 Introducing the Raspberry Pi Intro to Raspberry Pi1.
COMPUTER SYSTEM.
RaspberryPi Ira Goldstein Siena College. What is a Raspberry Pi? University of Cambridge’s Computer Laboratory – Decline in skill level – Designed for.
SINGLE BOARD COMPUTERS -KEVIN JOSE. WHY DO WE USE THEM? Good performance at low price GPIO capability to interact with the outside world Small form factor,
Submitted by Ravi Prakash PGT(Computer Sc.) KV39 GTC Varanasi
A mother board is the main circuit board for the computer system (hence the name mother board ) The mother board holds all of the other components of a.
By Naveed Ahmad! How to setup a. First of all, what are the parts of a Raspberry Pi? Source:
Nama: Chuli jimmi Manurung
Computer Parts By: Kayla Alvarez Period: A2. A modem is an electronic device that makes the transmission of data to or from a computer via telephone or.
Managing Devices Lesson 5. Objectives Objective Domain Matrix Technology SkillObjective Domain DescriptionObjective Domain Number Connecting Plug-and-Play.
Computer Hardware – System Unit
Introduction :  In the beginning, the calculator is the basic idea of computers out, then that arrived at the large computers.  in1980 or late seventies.
THE PARTS OF A COMPUTER WHAT ARE THE PARTS OF A COMPUTER THAT MAKE A COMPUTER A COMPUTER?
Digital Literacy: Computer Basics
Raspberry Pi Project Control Your Home Lights with a Raspberry Pi.
Introducing the Raspberry Pi Nauru ICT Department April 2016.
PCs ENVIRONMENT and PERIPHERALS Lecture 4. An expansion cards: - An expansion card (expansion board) is an electronic circuit board that adds more functionality.
Raspberry PI 2 Installation & Demo App By Wayne Keadle.
An introduction to the Raspberry Pi. What is a Raspberry Pi?  University of Cambridge’s Computer Laboratory  Decline in skill level  Designed for education.
RaspberryPi.
Python with Raspberry PI Kit
Introduction to Computers Mrs. Gambucci
Introduction to Raspberry Pi & Kano
Workshop on Raspberry Pi 3
Computer System Laboratory
Chapter 1: Introduction to the Personal Computer
Mandava Institute of Engineering and Technology
Ira Goldstein Siena College
Power Supply.
Computer Information Systems
IoT 101 with Raspberry Pi and Azure
EMBEDDED SYSTEMS.
Buttons, Sockets and Slots of a Desktop Computer
Prepared by: Raghad J Foqha Supervisor: Dr. Saed Tarapiah
Chapter A - The Raspberry Pi Computer
Computer Hardware – System Unit
Cloud Architecture Internet of Everything Meetup
Components of Computer
A microcontroller Raspberry Pi 2 Model B V1.1 RPi
Types of Computers & Computer Hardware
WORKSHOP LED CONTROL.
RASPBERRY PI WORKSHOP.
Presentation created by Jared D.
Programming with Arduinos and Rapsberry Pi
Session 3 DIY Moderate Project
Drill Translate the following message:
Lighting LEDs with a RASPBERRY PI
Instructor Materials Chapter 1: Introduction to the Personal Computer
Raspberry Pi Pi 2 Model B.
An introduction to the Raspberry Pi
Internet-of-Things (IoT)
Introduction to EV3Dev: Setup with Python
Internet-of-Things (IoT)
Keyboarding Class LHMS Ms. Key © Mr. Thrasher
Embedded Software Development with Python and the Raspberry Pi
Building an Internet of Things Device
Tareq Khan, Ph.D. Assistant Professor,
Python with Raspberry PI Kit
Chapter 7 IoT Physical Devices and Endpoints
Robot and Crickit HAT © Copyright 2019 by Dr. Elizabeth I. Horvath and Dr. Eva A. Horvath 1.
Presentation transcript:

IoT System Development with Raspberry Pi and Django 此页可以删除

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi 2 Raspberry Pi connects sensors 3 The Web Application

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi (1) Models (2) Parts (3) Electronic Components 3 (4) Operating system (5) Start Up

Raspberry Pi Raspberry Pi: a tiny computer  integrated on a single circuit board with linux-based operating system. Size: like a credit card. Function: all the basic functions of a PC.

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi (1) Models (2) Parts (3) Electronic Components 3 (4) Operating system (5) Start Up

Cheaper, Lower CPU and memory, Fewer ports and accessories Models There are many different models of Raspberry Pi: Model A, A+, B, B+, 2B, 3B, 3B+....... At present, the latest models have two: Raspberry Pi 3B Raspberry Pi zero (including zero w) Cheaper, Lower CPU and memory, Fewer ports and accessories

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi (1) Models (2) Parts (3) Electronic Components 3 (4) Operating system (5) Start Up

Parts Power supply Micro SD card Displayer Keyboard and mouse

Power Supply To connect to a power socket, all Raspberry Pi models have a USB port (the same found on many mobile phones):

Micro SD Card Raspberry Pi doesn’t have a hard drive. A Micro SD card is used to store all its files.

Displayer A TV or computer screen You need a screen, and a cable to link the screen and the Pi. There is a HDMI port on Raspberry Pi.

Keyboard and Mouse Raspberry PI built-in bluetooth, both USB or bluetooth wireless keyboard and mouse can be used

Other optional extras Adapter A case Headphones or speakers Many computer monitors may also have DVI or VGA ports. A case This is not essential, but you can put your Raspberry Pi in a case to protect it. Headphones or speakers The large Raspberry Pi models (but not Pi Zero/Zero W) have a standard audio port like the one on your smart phone or MP3 players. An Ethernet cable The large Raspberry Pi models (but not Pi Zero/Zero W) have a standard Ethernet port to connect them to the Internet. Raspberry Pi 4, 3, and Pi Zero W can also be wirelessly connected to the Internet.

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi (1) Models (2) Parts (3) Electronic Components 3 (4) Operating system (5) Start Up

Bread Plate By inserting the components into the hole, the circuit and components can be tested without welding or manual wiring

Connection Male and female connection

LED Diode and Resistor

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi (1) Models (2) Parts (3) Electronic Components 3 (4) Operating system (5) Start Up

Operating System The official operating system is Raspbian, a customized version of Debian. There is an official installer, NOOBS, that allows you to install Raspbian in a relatively simple way.

Introduction To Raspberry Pi 目录 Contents 1  Introduction To Raspberry Pi (1) Models (2) Parts (3) Electronic Components 3 (4) Operating system (5) Start Up

Connection It’s important to do this in the right order, so that all your components are safe.

Right Order Insert the SD card with Raspbian. Connect the mouse to a USB port on Raspberry Pi. Connect the keyboard in the same way. Plug the screen into a wall socket and switched on. Connect the screen to Raspberry Pi’s HDMI port.

Start Up Raspberry Pi doesn’t have a power switch: as soon as you connect it to a power outlet, it will turn on. As it starts up (booting), a raspberry will appear in the top left- hand corner of the screen.

Start up After a few seconds the Raspbian Desktop will appear.

Raspbian Desktop

Raspberry Pi connects sensors 目录 Contents 2  Raspberry Pi connects sensors (1) Sensors (2) GPIO & Pins (3) Temperature and Humidity Sensor 3 (4) Smoke Sensor

Raspberry Pi connects sensors 目录 Contents 2  Raspberry Pi connects sensors (1) Sensors (2) GPIO & Pins (3) Temperature and Humidity Sensor 3 (4) Smoke Sensor

Sensors Definition: A device that senses specified measurements and converts them into usable signals according to certain rules (mathematical function rules.) Constitute: A sensor usually consists of a sensitive element and a conversion element. Characteristic: Miniaturization, digitalization, intelligentization, multi-function, systematization and networking

Different Sensors

Different Sensors Temperature and humidity sensor Photosensitive resistance sensor Acceleration sensor Flame sensor Tilt sensor Hall sensor Sound sensor Smoke sensor

Raspberry Pi connects sensors 目录 Contents 2  Raspberry Pi connects sensors (1) Sensors (2) GPIO & Pins (3) Temperature and Humidity Sensor 3 (4) Smoke Sensor

Raspberry Pi Pin Chart

Raspberry Pi Pin Chart There are three different names for the pin number of raspberry pi: wiringPi, BCM GPIO and HEADER GPIO.setmode(GPIO.BCM)

BCM

Raspberry Pi connects sensors 目录 Contents 2  Raspberry Pi connects sensors (1) Sensors (2) GPIO & Pins (3) Temperature and Humidity Sensor 3 (4) Smoke Sensor

DHT11 Application field: DHT11 is a compound temperature and humidity sensor with calibrated digital signal output. Application field: Air conditioning testing and testing equipment Dehumidifier Automobile data recorder Automatic control of consumer goods Medical humidity regulator

DHT11

Connect to the Pi

A library that encapsulates related functions Get the digital values Step 1 Update package sudo apt-get update sudo apt-get install build-essential python-dev Step 2 Get Adafruit from GitHub sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git cd Adafruit_Python_DHT A library that encapsulates related functions

Represent the DHT11 and data pin, respectively. Get the digital values Step 3 Install this library to both python2 and python3 sudo python setup.py install sudo python3 setup.py install Step 4 Run the sample program cd examples python AdafruitDHT.py 11 17 Represent the DHT11 and data pin, respectively.

AdafruitDHT.py import sys import Adafruit_DHT sensor_args = { '11': Adafruit_DHT.DHT11,'22': Adafruit_DHT.DHT22, '2302': Adafruit_DHT.AM2302 } if len(sys.argv) == 3 and sys.argv[1] in sensor_args: sensor = sensor_args[sys.argv[1]] pin = sys.argv[2] else: print('Usage: sudo ./Adafruit_DHT.py [11|22|2302] <GPIO pin number>') print('Example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO pin #4') sys.exit(1)

AdafruitDHT.py results humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) if humidity is not None and temperature is not None print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity)) else: print('Failed to get reading. Try again!') sys.exit(1) results

Use it in other programs Import Adafruit_DHT sensor = Adafruit_DHT.DHT11 gpio = 17 humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)

Raspberry Pi connects sensors 目录 Contents 2  Raspberry Pi connects sensors (1) Sensors (2) GPIO & Pins (3) Temperature and Humidity Sensor 3 (4) Smoke Sensor

Smoke Sensor

Smoke Sensor Import RPi.GPIO as GPID Import time CHANNEL = 7 #the data out is connected to pin 7 GPIO.setmode(GPIO.BOARD) # set pin numbering mode GPIO.setup (CHANNEL, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # The initial level of the input port is set to low def action(pin): print’Sensor detected action!’

Smoke Sensor GPIO.add_event_detect(CHANNEL, GPIO.RISING) # monitor the change of input port GPIO.add_event_callback(CHANNEL, action) #if change, execute action function try: while True: print’alive’ time.sleep(0.5) except KeyboardInterrupt: GPIO.cleanup()

The Web Application Web Architecture Web Communication 目录 Contents 3  The Web Application (1) Web Architecture (2) Web Communication (3) Environment Setup & Configuration 3 (4) Demo

The Web Application Web Architecture Web Communication 目录 Contents 3  The Web Application (1) Web Architecture (2) Web Communication (3) Environment Setup & Configuration 3 (4) Demo

Web Architecture Django V.S. Java Frameworks: Spring Framework, Servlet, JSP…… Here some comparison of Python/Django stack over Java/Spring stack: Python/Django feels quicker and lighter than Java/Spring stack which result in productivity boost. Django admin is great! Java technologies servlet, beans, XML configurations etc have more mental overhead which I do not like。 Easier !

Django A view of Django MTV framework

The Web Application Web Architecture Web Communication 目录 Contents 3  The Web Application (1) Web Architecture (2) Web Communication (3) Environment Setup & Configuration 3 (4) Demo

Web Communication HTTP Connection HTTP connection is a protocol that runs on a socket. HTTP connection is a higher-level abstraction of a network connection. Socket Connection With Socket connection you need to take care of all the lower-level details of a TCP/IP connection.

GET vs. POST The following table compares the two HTTP methods: GET and POST.

The Web Application Web Architecture Web Communication 目录 Contents 3  The Web Application (1) Web Architecture (2) Web Communication (3) Environment Setup & Configuration 3 (4) Demo

Install the configuration According to prepare.docx. We use Django+uwsgi+nginx as our framework. Main Thought: Client 1 request return Connect Client 2 Sensor Host Client 3

The Web Application Web Architecture Web Communication 目录 Contents 3  The Web Application (1) Web Architecture (2) Web Communication (3) Environment Setup & Configuration 3 (4) Demo

Create Django project 1. create Django project called helloworld: django-admin.py startproject helloworld 2.create application called raspberrypistate: cd /helloworld python manage.py startapp raspberrypistate Edit settings.py & urls.py

Create Django project Edit raspberrypistate’s urls.py cd ../raspberrypistate Edit raspberrypistate’s views.py

Create Django project Structure helloworld raspberrypistate settings.py urls.py views.py Django Project Project main settings Application By url, you can call related function realized in vews,py Write your functions here templates Html files

Create Django project cd /home/pi/helloworld python manage.py migrate python manage.py makemigrations raspberrypistate sudo systemctl restart emperor.uwsgi.service Type the url on Raspberry Pi--http://127.0.0.1/raspberrypistate In this way, a Django project is created.

First target—Read Pi’s temperature of CPU The way to get the temperature: Then your can write this on views.py:

Read Pi’s temperature of CPU sudo systemctl restart emperor.uwsgi.service Type the url on Raspberry Pi--http://127.0.0.1/raspberrypistate You only need edit views.py. CPU: 55.3℃

Second target—Read DHT11’s value DHT11 -- Humidity & Temperature Sensor

Read DHT11’s value View the pin diagram gpio readall

Read DHT11’s temperature The way to get DHT11’s value Then your can write this on views.py:

Read DHT11’s temperature sudo systemctl restart emperor.uwsgi.service Type the url on Raspberry Pi--http://127.0.0.1/raspberrypistate You only need edit views.py. Temperature:29℃ humidity: 69%

The way to provide service The host needs to provide service. Clients in Local Area Network need get responses from the host. That is easy— You only need to edit settings.py: Use ifconfig –a find your Raspberry Pi’s IP address Then edit settings.py In this way, clients 192.168.2.121/raspberrypistate

Different Types of Echarts

Echarts

Reference https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up https://projects.raspberrypi.org/en/projects/raspberry-pi-using