Presentation is loading. Please wait.

Presentation is loading. Please wait.

IoT System Development with Raspberry Pi and Django

Similar presentations


Presentation on theme: "IoT System Development with Raspberry Pi and Django"— Presentation transcript:

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

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

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

4 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.

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

6 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

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

8 Parts Power supply Micro SD card Displayer Keyboard and mouse

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

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

11 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.

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

13 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.

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

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

16 Connection Male and female connection

17 LED Diode and Resistor

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

19 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.

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

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

22 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.

23 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.

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

25 Raspbian Desktop

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

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

28 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

29 Different Sensors

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

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

32 Raspberry Pi Pin Chart

33 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)

34 BCM

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

36 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

37 DHT11

38 Connect to the Pi

39 A library that encapsulates related functions
Get the digital values Step Update package sudo apt-get update sudo apt-get install build-essential python-dev Step 2 Get Adafruit from GitHub sudo git clone cd Adafruit_Python_DHT A library that encapsulates related functions

40 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.

41 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 Read from an AM2302 connected to GPIO pin #4') sys.exit(1)

42 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

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

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

45 Smoke Sensor

46 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!’

47 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()

48 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

49 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

50 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 !

51 Django A view of Django MTV framework

52 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

53 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.

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

55 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

56 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

57 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

58 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

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

60 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

61 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-- In this way, a Django project is created.

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

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

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

65 Read DHT11’s value View the pin diagram gpio readall

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

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

68 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 /raspberrypistate

69 Different Types of Echarts

70 Echarts

71 Reference


Download ppt "IoT System Development with Raspberry Pi and Django"

Similar presentations


Ads by Google