This document provides an overview of cloud computing and its relevance to IoT. It discusses various cloud storage models and APIs that enable communication with cloud services. It introduces the WAMP protocol for building publish-subscribe and RPC-based distributed apps for IoT. The document also covers using the Xively cloud platform and Django web framework for developing IoT apps. Key topics include cloud computing concepts, types of cloud services, advantages of cloud, and getting started with Django projects, apps, databases and models.
IoT Physical Devices and End Points.pdfGVNSK Sravya
Basic building blocks of an IoT Device
• Exemplary Device: Raspberry Pi
• Raspberry Pi interfaces
• Programming Raspberry Pi with Python
• Other IoT devices
on successful go through of this complete PPT, the learners can be able to understand the Raspberry PI, Raspberry Pi Interfaces(Serial, SPI,I2C) Programming, Python programming with Raspberry PI with the focus of Interfacing external gadgets
Controlling output Reading input from pins.
The slides defines IoT and show the differnce between M2M and IoT vision. It then describes the different layers that depicts the functional architecture of IoT, standard organizations and bodies and other IoT technology alliances, low power IoT protocols, IoT Platform components, and finally gives a short description to one of IoT low power application protocols (MQTT).
Performance trends and alerts with ThingSpeak IoTAnoush Najarian
We use data analysis and visualization capabilities of ThingSpeak, our favorite Internet of Things platform to capture and analyze performance data, to help with performance monitoring and to generate alerts
IoT Physical Devices and End Points.pdfGVNSK Sravya
Basic building blocks of an IoT Device
• Exemplary Device: Raspberry Pi
• Raspberry Pi interfaces
• Programming Raspberry Pi with Python
• Other IoT devices
on successful go through of this complete PPT, the learners can be able to understand the Raspberry PI, Raspberry Pi Interfaces(Serial, SPI,I2C) Programming, Python programming with Raspberry PI with the focus of Interfacing external gadgets
Controlling output Reading input from pins.
The slides defines IoT and show the differnce between M2M and IoT vision. It then describes the different layers that depicts the functional architecture of IoT, standard organizations and bodies and other IoT technology alliances, low power IoT protocols, IoT Platform components, and finally gives a short description to one of IoT low power application protocols (MQTT).
Performance trends and alerts with ThingSpeak IoTAnoush Najarian
We use data analysis and visualization capabilities of ThingSpeak, our favorite Internet of Things platform to capture and analyze performance data, to help with performance monitoring and to generate alerts
1. Explaining the importance of platform based development
2. Understanding The importance of NodeMCU and demonstrate its interfacing with various devices and sensors.
Real Life Applications of Distributed Systems:
1. Distributed Rendering in Computer Graphics
2. Peer-To-Peer Networks
3. Massively Multiplayer Online Gaming
IOT and its communication models and protocols.pdfMD.ANISUR RAHMAN
A brief visual description of the Internet of Things and how it works. Then, we will learn about the communication models of IoT and how their structure defines them. Then we will go for the IoT protocols and know about different types of protocols. At last, we will see some applications of IoT.
Webinar presented live on April 4, 2017
The Cloud Standards Customer Council has published an API Management reference architecture. APIs allow companies to open up data and services to external third party developers, business partners, and internal departments within the company to create innovative channel applications and new business opportunities. An effective API management platform provides a layer of controlled and secure self-service access to core business assets for reuse.
In this webinar, the authors of the reference architecture will cover the architectural components and capabilities that make up a superior API Management Platform and will also cover important runtime characteristics and deployment considerations.
Read the CSCC's paper here: http://www.cloud-council.org/deliverables/cloud-customer-architecture-for-api-management.htm
1. Explaining the importance of platform based development
2. Understanding The importance of NodeMCU and demonstrate its interfacing with various devices and sensors.
Real Life Applications of Distributed Systems:
1. Distributed Rendering in Computer Graphics
2. Peer-To-Peer Networks
3. Massively Multiplayer Online Gaming
IOT and its communication models and protocols.pdfMD.ANISUR RAHMAN
A brief visual description of the Internet of Things and how it works. Then, we will learn about the communication models of IoT and how their structure defines them. Then we will go for the IoT protocols and know about different types of protocols. At last, we will see some applications of IoT.
Webinar presented live on April 4, 2017
The Cloud Standards Customer Council has published an API Management reference architecture. APIs allow companies to open up data and services to external third party developers, business partners, and internal departments within the company to create innovative channel applications and new business opportunities. An effective API management platform provides a layer of controlled and secure self-service access to core business assets for reuse.
In this webinar, the authors of the reference architecture will cover the architectural components and capabilities that make up a superior API Management Platform and will also cover important runtime characteristics and deployment considerations.
Read the CSCC's paper here: http://www.cloud-council.org/deliverables/cloud-customer-architecture-for-api-management.htm
Cloud Native Patterns with Bluemix Developer ConsoleMatthew Perrins
This presentation talks about Cloud Native Application patterns Mobile, Web, BFF (Backend for Frontend) and Microservices. It will walk through the patterns and show how they can be used to deliver public cloud solutions with IBM Cloud, using Bluemix Developer Console
IBM Hybrid Cloud Integration UCC Talk, 21st November 2018Michael O'Sullivan
A lecture to the students of the University College Cork 3rd year Undergraduate Computer Science class, CS3311 (Middleware) module, and MSc Computer Science class, CS6312 (Mobile Devices and Systems) on IBM Hybrid Cloud. The presentation provides a brief overview of the different technologies that can be used to deploy applications on the IBM Cloud (formerly known as IBM Bluemix) - Cloud Foundry applications and services, Docker containers, and Kubernetes clusters. Following, the presentation focuses in on the Hybrid Cloud model, looking at Hybrid Cloud architectures, integration between on-prem, private, and public cloud services, API Economy, and finally, IBM API Connect as one IBM Hybrid Cloud Solution.
Acknowledgements to my team lead Sanjay Nayak for assisting in preparing some of the content used in this presentation that we have built and delivered together over the last few years, and Christopher Phillips for inspiration on topics to discuss.
Bluemix provides developers with multiple open-source compute options to run their apps, chief among them Cloud Foundry, the world’s leading platform-as-a-service (PaaS) offering. Cloud Foundry enables teams to practice continuous delivery by supporting the full software development lifecycle, from dev to deployment. One of the key advantages of the platform is the ability it gives developers to easily configure and start using a MongoDB datastore for their application. In this lightning talk, Bluemix developer advocate Jake Peyser will go over Cloud Foundry and best practices for data storage when using the platform. He will then take attendees through a live demo where he will show users how to quickly configure a MongoDB instance in Bluemix and connect it to an application.
Edge 2016 Session 1886 Building your own docker container cloud on ibm power...Yong Feng
The material for IBM Edge 2016 session for a client use case of Spectrum Conductor for Containers
https://www-01.ibm.com/events/global/edge/sessions/.
Please refer to http://ibm.biz/ConductorForContainers for more details about Spectrum Conductor for Containers.
Please refer to https://www.youtube.com/watch?v=7YMjP6EypqA and https://www.youtube.com/watch?v=d9oVPU3rwhE for the demo of Spectrum Conductor for Containers.
Openbar 12 - Leuven - From reactive programming to reactive architectureOpenbar
Reactive Programming begint meer en meer door te dringen in de Java wereld. Deze programmeerstijl waarbij message-driven en data-streams centraal staat beloofd een betere schaalbaarheid en weerbaarheid van onze applicaties.
Deze andere manier van programmeren vraagt echter ook een ander soort architectuur onze systemen. We kijken naar hoe je de architectuur van je applicaties in lijn brengt met het gebruik van reactive streams, en welke voordelen dat deze manier van werken kan aanbieden.
Want to integrate MongoDB into your Cloud Foundry App? Learn exactly how to do that with Bluemix Developer Advocate Jake Peyser! Follow him @Jakepeyser.
This slide deck was originally used for a Lightning Talk on integrating MongoDB into a Cloud Foundry application at MongoDB World 2015. It contains an overview of Cloud Foundry, as well as an explanation of where the MongoDB service fits into the technology stack.
A developer can now build out Cloud Native applications using our patterns-first approach. You simply select the type of building block you’d like to create followed by which services you’d like to incorporate into your application (i.e., Cloudant database, WatsonConversation, Push Notifications).
How we got to where we are?
What's Serverless
Serverless Principles
Pros and cons
Serverless architectures
Lambda Anatomy
Demos
AWS SAM
Demo
By : Ahmed Samir
Similar to IoT Physical Servers and Cloud Offerings.pdf (20)
Language features of Python, Data types, Data structures, Control of flow, Functions,
Modules, Packaging,
File handling,
Data/time operations,
Classes,
Exception handling Python packages - JSON, XML, HTTPLib,
URLLib, SMTPLib.
IoT & M2M
Differences and Similarities between M2M and
IoT, SDN and NFV for IoT, Difference between SDN and NFV for IoT,
Basics of IoT System Management with
NETCONF, YANG-NETCONF, YANG and SNMP NETOPEER.
GPS Signal Components, Purpose, Properties and Power level,
Signal Acquisition and Tracking, Navigation Information Extraction, Pseudo Range Estimation, Frequency Estimation, GPS Satellite Position Calculation, Signal Structure, Anti Spoofing (AS), Selective Availability, Difference between GPS and GALILEO Satellite Construction.
Basic concept, System Architecture, GPS and GLONASS Overview, Satellite Navigation, Time and GPS, User Position and Velocity Calculations, GPS Satellite Constellation, Operation Segment, User Receiving Equipment, Space Segment Phased Development, GPS Aided Geo augmented Navigation (GAGAN) Architecture.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
1. Unit - V
IoT Physical Servers &
Cloud Offerings
6/7/2022 1
2. Outline
• Introduction to Cloud Storage models
• Communication APIs
• Webserver-Web server for IoT
• Cloud for IoT
• Python web application framework
• Designing a RESTful web API.
6/7/2022 2
3. Introduction to Cloud Computing
• The Internet of Things (IoT) involves the internet-connected devices which are used
to perform the processes and services that supports way of life.
• Another component set to help IoT succeed is cloud computing, which acts as a sort
of front end.
• Cloud computing is an increasingly popular service that offers several advantages to
IOT, and is based on the concept of allowing users to perform normal computing
tasks using services delivered entirely over the internet.
6/7/2022 3
4. Introduction to Cloud Computing
• In simple words, Cloud Computing means providing computing services over the
internet (called as cloud).
• The computing services include Servers, Software, Storage, Database,
Networking, Analytics, Intelligence etc.,
6/7/2022 4
5. Introduction to Cloud Computing
• A worker may need to finish a major project that must be submitted to a manager,
but perhaps they encounter problems with memory or space constraints on their
computing device.
• Memory and space constraints can be minimized if an application is instead hosted
on the internet.
• The worker can use a cloud computing service to finish their work because the data is
managed remotely by a server.
6/7/2022 5
6. Introduction to Cloud Computing
• Another example- you have a problem with your mobile device and you need to
reformat it or reinstall the operating system.
• You can use Google Photos to upload your photos to internet-based storage.
• After the reformat or reinstall, you can then either move the photos back to you
device or you can view the photos on your device from the internet when you want.
6/7/2022 6
9. Types of Cloud Services
6/7/2022 9
• Infrastructure-as-a-service(IaaS) provides users the ability to provision computing
and storage resources. These resources are provided to the users as a virtual
machine instances and virtual storage.
• Platform-as-a-Service(PaaS) provides users the ability to develop and deploy
application in cloud using the development tools, APIs, software libraries and
services provided by the cloud service provider.
• Software-as-a-Service(SaaS) provides the user a complete software application or
the user interface to the application itself.
12. Cloud Storage API
• A cloud storage API is an application program interface that connects a
locally-based application to a cloud-based storage system, so that a user
can send data to it and access and work with data stored in it.
• To the application, the cloud storage system is just another target device,
like tape or disk-based storage.
• An application program interface (API) is code that allows two software
programs to communicate with each other.
6/7/2022 12
13. Cloud Storage API
• The API defines the correct way for a developer to write a program that
requests services from an operating system (OS) or other application.
• APIs are implemented by function calls composed of verbs and nouns.
• The required syntax is described in the documentation of the application
being called.
6/7/2022 13
14. How APIs Works
• APIs are made up of two related elements.
• The first is a specification that describes how information is exchanged
between programs, done in the form of a request for processing and a
return of the necessary data.
• The second is a software interface written to that specification and
published in some way for use. The software that wants to access the
features and capabilities of the API is said to call it, and the software that
creates the API is said to publish it.
6/7/2022 14
15. Why APIs are important
• The web, software designed exchange information via the internet and
cloud computing have all combined to increase the interest in APIs in
general and services in particular.
• Software that was once custom-developed for a specific purpose is now
often written referencing APIs that provide broadly useful features,
reducing development time and cost and mitigating the risk of errors.
6/7/2022 15
16. Why APIs are important
• APIs have steadily improved software quality over the last decade, and the
growing number of web services exposed through APIs by cloud providers
is also encouraging the creation of cloud-specific applications, internet of
things (IoT) efforts and apps to support mobile devices and users.
6/7/2022 16
17. Basic Types of APIs
• APIs take three basic forms: local, web-like and program-like.
• Local APIs are the original form, from which the name came. They offer
OS or middleware services to application programs. Microsoft's .NET APIs,
the TAPI (Telephony API) for voice applications, and database access
APIs are examples of the local API form.
6/7/2022 17
18. Basic Types of APIs
• Web APIs are designed to represent widely used resources like HTML
pages and are accessed using a simple HTTP protocol. Any web URL
activates a web API.
• Web APIs are often called REST (representational state transfer) or
RESTful because the publisher of REST interfaces doesn't save any data
internally between requests. As such, requests from many users can be
intermingled as they would be on the internet.
6/7/2022 18
19. Basic Types of APIs
• Program APIs are based on remote procedure call (RPC) technology that
makes a remote program component appear to be local to the rest of the
software.
• Service oriented architecture (SOA) APIs, such as Microsoft's WS-series of
APIs, are program APIs.
6/7/2022 19
20. WAMP - Autobahn for IoT
• Web Application Messaging Protocol (WAMP) is a sub-protocol of Websocket
which provides publish-subscribe and remote procedure call (RPC) messaging
patterns.
• WAMP enables distributed application architectures where the application
components are distributed on multiple nodes and communicate with messaging
patterns provided by WAMP.
6/7/2022 20
22. WAMP - Concepts
• Transport: Transport is channel that connects two peers. The default transport
for WAMP is Web socket. WAMP can run over the transports as well which
support message based reliable bi directional communication.
• Session: Session is a conversation between two peers that runs over a
transport.
6/7/2022 22
23. WAMP - Concepts
• Client: Clients are peers that can have one or more roles. In publish-subscribe
model client can have following roles:
–Publisher: Publisher publishes events (including payload) to the topic
maintained by the Broker.
–Subscriber: Subscriber subscribes to the topics and receives the events
including the payload.
6/7/2022 23
24. WAMP - Concepts
• In RPC model client can have following roles:
–Caller: Caller issues calls to the remote procedures along with call arguments.
–Callee: Callee executes the procedures to which the calls are issued by the caller
and returns the results back to the caller.
6/7/2022 24
25. WAMP - Concepts
• Router: Routers are peers that perform generic call and event routing. In publish-
subscribe model Router has the role of a Broker:
–Broker: Broker acts as a router and routes messages published to a topic to all
subscribers subscribed to the topic.
6/7/2022 25
27. WAMP Protocol Interaction between the Peers
• In this protocol, WAMP transport used is Websocket.
• WAMP sessions are established over Websocket transport within the
lifetime of Websocket transport.
6/7/2022 27
29. Publish Subscribe Messaging using WAMP -
Autobahn
• The client in Publisher role runs a WAMP application component that
publishes messages to the router.
• The router in broker role runs on the server and routes the messages to
the subscribers.
• The router decouples the publisher from the subscribers.
• The communication between publisher- broker and broker subscribers
happens over a WAMP websocket session.
6/7/2022 29
32. WAMP - Autobahn
• Create a WAMP Publisher Component.
• The publisher component will publish a message containing the current
time stamp to a topic named ‘test – topic’.
• Create a WAMP Subscriber component.
• The subscriber component that subscribes to the ‘test-topic’
6/7/2022 32
36. Xively Cloud for IoT
• It is a commercial platform as a service (PAAS) that can be used for
creating solutions for IoT.
• With Xively cloud, IoT developers can focus on the front end infrastructure
and devices for IoT(that generate the data), while the backend data
collection infrastructure is managed by Xively.
6/7/2022 36
37. Xively Cloud for IoT
• Xively platform comprises of a message bus for real-time message
management and routing, data services for time series archiving, directory
services that provides a search - able directory of objects and business
services for device provisioning and management.
• Xively provides an extensive support for various languages and platforms
• The Xively libraries leverage standards based API over HTTP, sockets and
MQTT for connecting IoT devices to the Xively Cloud.
6/7/2022 37
38. Xively Cloud for IoT
• To start using Xively python library, first we need to register a developer
account and then create development devices on Xively.
• When a new device is created, Xively automatically creates a Feed ID and
an API key to connect to the device.
• Feed ID is a collection of channels or data streams defined for a device
and associated meta data.
• API keys are used to provide different levels of permissions.
• The default API key has read, update, create and delete permissions.
6/7/2022 38
41. Xively Cloud for IoT
• Xively devices have one or more channels and each channel enables
bidirectional communication between the IoT devices and Xively cloud.
• IoT devices can send data to a channel using the Xively APIs.
• For each channel one or more triggers can be created. A trigger
specification includes a channel to which the trigger corresponds, trigger
condition and an HTTP post URL to which the request is sent when the
trigger fires.
• Trigger are used to provide integration for third party applications.
6/7/2022 41
42. Xively Cloud for IoT
• Let us consider an example of using Xively cloud for an IoT system that
monitors temperature and sends the measurements to a Xively channel.
• Temperature monitoring device can be built by raspberry pi board and a
temperature sensor is connected to the board.
• The raspberry pi runs a controller program that reads the sensor values
every few seconds and sends the measurements to a Xively channel.
• Box 8.4 shows the python program for sending the temperature data to
Xively cloud by using Xively python library.
6/7/2022 42
43. Xively Cloud for IoT
• To keep the program simple and without going in to the details of the
temperature sensor, synthetic data is used (generated randomly in
readTemp Sensor()function).
• A feed object is created by providing the API key and Feed ID. Then a
channel named temperature is created.
• The temperature data is sent to this channel in the runController() function
every 10 seconds.
6/7/2022 43
47. Xively Cloud for IoT
• Figure 8.6 shows the temperature channel in the Xively dashboard. In this
example a single Xively device with one channel is created. Xively can also
have multiple channels and multiple devices.
6/7/2022 47
49. Python Web Application Framework - Django
• Django is an open source web application framework for developing web
applications in Python.
• A "web application framework" in general is a collection of solutions,
packages and best practices that allows development of web
applications and dynamic websites.
• Django is based on the Model-Template-View architecture and provides a
separation of the data model from the business rules and the user
interface.
6/7/2022 49
50. Python Web Application Framework - Django
• Django provides a unified API to a database backend.
• Thus web applications built with Django can work with different databases
without requiring any code changes.
• With this fiexibility in web application design combined with the powerful
capabilities of the Python language and the Python ecosystem, Django is best
suited for cloud applications.
• Django consists of an object-relational mapper, a web templating system and
a regular-expression- based URL dispatcher.
6/7/2022 50
51. Django Architecture
• Django is Model-Template-View (MTV) framework .
Model
• The model acts as a definition of some stored data and handles the
interactions with the database. In a web application, the data can be
stored in a relational database, non-relational database, an XML file,
etc. A Django model is a Python class that outlines the variables and
methods for a particular type of data.
6/7/2022 51
52. Django Architecture
Template
• In a typical Django web application, the template is simply an HTML
page with a few extra placeholders. Django’s template language can
be used to create various forms of text files (XML, email, CSS,
Javascript, CSV, etc.)
6/7/2022 52
53. Django Architecture
View
• The view ties the model to the template. The view is where you write the
code that actually generates the web pages. View determines what
data is to be displayed, retrieves the data from the database and passes
the data to the template.
6/7/2022 53
54. Starting Development with Django
Creating a Django Project and App
• When a new Django project is created, a number of files are created as
described below
6/7/2022 54
55. Starting Development with Django
• A Django can have multiple Apps, where these Apps are used to write the
code that makes website function.
• When a new application is created a new directory for the application is
also created which has a number of files including –
6/7/2022 55
57. Starting Development with Django
• Django comes with a built in, light weight web server that can be used for
development purposes.
• When the Django development server is started the default project can be
viewed at the URL: http://localhost:8000.
6/7/2022 57
59. Starting Development with Django
Configuring a Database
• Developers have a wide choice of databases that can be used for web
applications including both relational and non relational databases.
• Django provides a unified API for database backend thus giving the
freedom to choose the database.
• Django supports various relational database engines including MySQL,
PostgreSQL, Oracle and SQLite3.
6/7/2022 59
60. Starting Development with Django
• Support for non relational data bases such as MongoDB can be added by
installing additional engines (Eg. Django- MongoDB engine for
MkongoDB).
• The first step in setting up a database is to install and configure a
database server.
• After installing the data base, the next step is to specify the database
settings in the setting.py file in the Django project.
6/7/2022 60
65. Defining a Model
• A Model acts as a definition of the data in the database.
• Box 8.10 shows an example of a Django model for TemperatureData
collected by an IoT Device.
• The TemperatureData table in the database is defined as a class in the
Django Model.
• Each class that represents a database table is a subclass of
django.db.models.Model which contains all the functionality that allows
the models to interact with the database.
6/7/2022 65
66. Defining a Model
• The TemperatureData class has fields timestamp, temperature, lat and lon
all of which are CharField.
• To sync the models with the database, run the following command:
• >python manage.py syncdb
• When the syncdb command is run for the fist time, it creates all the tables
defined in the Django model in the configured database.
6/7/2022 66
68. Django Admin Site
• Django provides an administration system that allows to manage the
website without writing the additional code.
• This “admin” system reads the Django model and provides an interface
that can be used to add content to the site.
• The Django admin site is enabled by adding d jango.contrib.admin and d
jango.contrib.admindocs to the INSTALLED_APPS section in the
settings.py file.
6/7/2022 68
69. Django Admin Site
• The admin site also requires URL pattern definitions in the url.py file.
• To define which application models to be editable in the admin interface, a
new file named admin.py is created in the application folder.
•
6/7/2022 69
72. Defining a View
• The view contains the logic that glues the model to the template.
• The view determines the data to be displayed in the template, retrieves
the data from the database and passes it to the template.
• Conversely, the view also extracts the data posted in a form in the
template and inserts it in the database.
• Typically, each page in the website has a separate view, which is
basically a python function in the views.py file.
6/7/2022 72
73. Defining a View
• Views can also perform additional tasks such as authentication, sending
emails, etc.,
• Box 8.12 shows an example of a Django view for the Weather Station
app.
• This view corresponds to the webpage that displays latest entry in the
TemperatureData table.
• In this view the Django’s built in object-relational mapping API is used to
retrieve the data from the TemperatureData Table.
6/7/2022 73
74. Defining a View
• The object- relational mapping API allows the developers to write generic
code for interacting with the database without worrying about the
underlying database engine.
• So the same code for database interactions works with different database
backends.
• A specific python library can be chose to the database backend used (eg.
MySQLdb for MySQL, PyMongo for MongoDB etc.) to write database
backed specific code.
6/7/2022 74
75. Defining a View
• In the view shown in Box 8.12, the
TemperatureData.objects.order_by(‘_id’) query returns the latest entry in
the table.
• To retrieve all entries, can use table.objects.all().
• To retrieve specific entries, use table.objects.filter(**Kwargs) to filter out
queries that match the specified condition.
6/7/2022 75
76. Defining a View
• To render the retrieved entries in the template, the render_to_response
function is used.
• This function renders a given template with a given context dictionary and
returns an HttpResponse object with that rendered text.
• Box 8.13 shows an alternative view that retrieves data from the Xively
cloud.
6/7/2022 76
80. Defining a Template
• A Django Template is typically an HTML file (it can be any sort of text file
such as XML, email, CSS, Java script, CSV etc,).
• Django templates allow separation of the presentation of data from the
actual data by using placeholders and associated logic (Using template
tags).
• A template receives a context from the view and presents the data in
context variables in the placeholders.
6/7/2022 80
81. Defining a Template
• Box 8.14 shows an example of a template for the Weather Station app
and the variables containing the retrieved temperature, latitude and
longitude are passed to the template.
6/7/2022 81
86. Defining the URL Patterns
• URL patterns are a way of mapping the URLs to the views that should
handle the URL requests.
• The URLs requested by the user are matched with the URL patterns and
the view corresponding to the pattern that matches the URL is used to
handle the request.
6/7/2022 86
87. Defining the URL Patterns
• Box 8.15 shows an example of the URL patterns for the Weather Station
Project and the URL patterns are constructed using regular expressions.
• The simplest regular expression (r’ ^ $’) corresponds to the root of the
website or the home page.
6/7/2022 87
89. Defining the URL Patterns
• With the Django models, views, templates and URL patterns defined for
the Django project, the application finally runs with the commands shown
in Box 8.16.
•
6/7/2022 89
90. Designing a RESTful Web API
• Django REST framework can be installed as follows:
6/7/2022 90
91. Designing a RESTful Web API
• After installing the Django REST framework, create a new Django project
named restfulapi, and then start a new app called myapp, as follows:
6/7/2022 91
92. Designing a RESTful Web API
• The REST API allows to create, view, update and delete a collection of
resources where each resource represents a sensor data reading from a
weather monitoring station.
• Box 8.17 shows the Django model for such a station.
• The station model contains four fields – station name, timestamp,
temperature, latitude and longitude
6/7/2022 92
94. Designing a RESTful Web API
• Box 8.18 shows the Django views for the REST API.
• ViewSets are used for the views that allows to combine the logic for a set
of related views in a single class.
•
6/7/2022 94
97. Designing a RESTful Web API
• Box 8.19 shows the serializers for the REST API.
• Serializers allow complex data (such as querysets and model instances)
to be converted to native python datatypes that can be easily rendered
into JSON, XML or other content types.
• Serializers also provide de-serialization, allowing parsed data to be
converted back into complex types, after first validating the incoming
data.
6/7/2022 97
99. Designing a RESTful Web API
• Box 8.20 shows the URL patterns for the REST API.
• Since, ViewSets are used instead of views, it can automatically generate
the URL conf for API, by registering the ViewSets with a router class.
• Routers automatically determining how the URLs for an application
should be mapped to the logic that deals with handling incoming
requests.
6/7/2022 99
101. Designing a RESTful Web API
• Box 8.21 shows the settings for the REST API Django project.
6/7/2022 101
102. Designing a RESTful Web API
• Box 8.21 shows the settings for the REST API Django project.
6/7/2022 102
103. Designing a RESTful Web API
• After creating the station REST API source files, the next step is to setup
the database and then run the Django development web server as
follows:
6/7/2022 103
104. Designing a RESTful Web API
• Box 8.22 shows examples of interacting with the Station REST API using
CURL.
• The HTTP POST method is used to create a new resource, GET method
is used to obtain information about a resource, PUT method is used to
update a resource and DELETE method is used to delete a resource.
6/7/2022 104