Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
45 views32 pages

Iot 7sem I. T Unit 5

Uploaded by

kothareethika12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
45 views32 pages

Iot 7sem I. T Unit 5

Uploaded by

kothareethika12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
UNIT V IoT Platforms Design Methodology: Introduction, IoT Platform Design Methodology, IoT Physical Devices & Endpoints, Raspberry Pi interfaces, Programming Raspberry Pi with Python, Other loT Devices.IoT Physical Servers & Cloud Offerings: Introduction to Cloud Storage Models & Communication APIs, WAMP - AutoBahn for IoT, Xively Cloud for IoT, Python Web Application Framework-Django, Amazon Web Services for oT. COMPILED BY:MD VAZAHAT ALI (NSAKCET) a er Pat 151, troduction lat cm em flit penn an ine Cpe we ‘eta ye ves He er ee cnet ‘Sete Smet oe Den iT semen eso od ‘Sigs it thew yer ne mses beet ngs ha ‘stencil aut aan st ce a ompmet a d ‘Stance Due surge oer ora ooo cope tsp Sengner myth anne ltr here oT pm SAS ees apa cee pment a ‘Ter. hteSnem mew ete pnt ema T ah prod ances venir ais ch wae i © Smet ea Cie cemes Fr ch nt pag een eg ao ‘Somer one pra unr dae ¢ ogee omy ‘Sige ln mary er eure een ae Ths Cges vps ent ge mde fo ym dns ih snes pe re pera gag om ep toe pend tog ne eu Sigg mer ee ‘Rteprtny sof ced oop Wih he popes meg pm (Gone capen ion anaes roe Mt quency Te meng ‘Sera Capers ey tn on WA te me a ‘Sigh cmes on nay fas ll Lat aps cb ‘Semcon apc oar se nb eed sab 52 loT Design Methodology Pipe 51 show epee a he fT sytem design mato. ah em ‘em capland no ctu at ello. Tegan hw ep nee Sg ‘en ttbeed howe woman em 1521, Step 1: Purpose & Requirements Speciation “he ey nT sy eign metho dia te pup nd genet ‘te yc nth p.m prone bar and eames (ah at ‘Sica reqtenens cee ents sen magnet eee cy sn ny regan eae ements») a ORE “Artin eamp os sma hore sms ym te papa ad item re spun ay be hte low ator a 52 T Dein Metoooay - * Security Requirement : The system should have basic user authentication capability. 5.2.2 Step 2: Process Specitication ‘The second step in the oT design methodology is to define the process specification. In this step, the use cases of the IoT system are formally described based on and derived from the Purpose and requirement specifications, Figure 5.2 shows the process diagram for the home automation system. The process diagram shows the two modes of the system - auto and manual. In a process diagram, the circle denotes the start of a process, diamond denotes a decision box and rectangle denotes a state or attribute. When the auto mode is chosen, the system monitors the light level. If the light level is low, the system changes the state of the ight to “on”. Whereas, if the light level is high, the system changes the state of the light to the light state set by the user is “on”, the system changes the state of light to “on”. Whereas, if the light state set by the user is “off”, the system changes the state of light o “off”. awe tw ow >. tee oh d eee Figure 5.2: Process specification for home automation IoT system Bahga & Madisett, © 2015 “off”. When the manual mode is chosen, the system checks the light state set by the user. If ee 5.2.3. Step 3: Domain Model Specification ‘The third step in the IoT design methodology is to define the Domain Model. The domain trndel describes the main concepts, entities and objects in the domain of ToT system to be designed. Domain model defines the attributes of the objects and relationships between ” Domain model provides an abstract representation of the concepts, objects and otites in the ToT domain, independent of any specific technology or platform. With the domain model, the ToT system designers can get an understanding of the ToT domain for Which the system is to be designed. Figure 5.3 shows the domain model for the home ‘aiomation system example, The entities, objects and concepts defined in the domain model include: ‘* Physical Entity : Physical Entity isa discrete and identifiable entity inthe physical environment (e.g. 00m, alight, an appliance, a car etc.). The IoT system provides information about the Physical Entity (using sensors) or performs actuation upon the Physical Entity (e.g. switching on light). In the home automation example, there are ‘wo Physical Entities involved - one is the room in the home (of which the lighting conditions are to be monitored) and the other isthe light appliance to be controled. ‘© Virtual Entity : Viral Entity is a representation of the Physical Entity in the digital world. For each Physical Entity, there is a Virtual Entity in the domain model. In the hhome automation example, there is one Virtual Entity for the room to be monitored, another for the appliance to be controlled. '* Device : Device provides a medium for interactions between Physical Entities and Virtual Entities. Devices are either attached to Physical Entities or placed near Physical Eniities. Devices are used to gather information about Physical Entities (e.g. from sensors), perform actuation upon Physical Entities (e.g. using actuators) or used to identify Physical Entities (e.g.. using tags). In the home automation example, the device is a single-board mini computer which has light sensor and actuator (relay switeh) attached to it, + Resource : Resources are software components which can be either "on-device” ‘ “network-resources". On-device resources are hosted on the device and include software components that either provide information on or enable actuation upon the Physical Entity to which the device is attached. Network resources include the software components that are available in network (such as a database). Inthe home automation example, the on-device resource is the operating system that runs on the single-board mini computer. * Service : Services provide an interface for interacting with the Physical Entity. Services access the resources hosted on the device or the network resources to obtain information about the Physical Entity or perform actuation upon the Physical Entity. Internet of Things - AHands-On Approach 5.2.4 Step 4: Information Model Specification ‘The fourth step in the IoT design methodology is to define the Information Model. Information Model defines the structure of all the information in the loT system, for example, attributes ‘of Virtual Entities, relations, tc, Information model does not describe the specifics of how the information is represented or stored. To define the information model, we firs list the ‘Virtual Entities defined in the Domain Model. Information model adds more details to the ‘Virtual Entities by defining thei atributes and relations. In the home automation example, there are two Virtual Entities - a Virtual Entity for the light appliance (with attribute - light state) and a Virtual Entity for the room (with attribute - light level). Figure 5.4 shows the Information Model for the home automation system example, Figure 54: Information model of the home automation 1oT system 5.2.8 Step 5: Service Specifications ‘The fifth step in the IoT design methodology is to define the service specifications. Service specifications define the services in the [oT system, service types, service inputoutpat, service endpoints, service schedules, service preconditions and service effects. ‘You leamed about the Process Specification and Information Model in the previous sections. Figure 5.5 shows an example of deriving the services from the process specification and information model for the home automation IoT system, From the process specification and information mode!, we identify the states and attributes, For each state and attribute wwe define a service. These services either change the state or attribute values or retrieve the ‘current values. For example, the Mode service sets mode to auto or manual or retrieves the current mode. The State service sets the light appliance state to on/off or retrieves the current light state. The Controller service monitors the light level in auto mode and switches the 5.2.6 Step 6: loT Level Specification The sixth step in the IoT design methodology is to define the IoT level for the system. In Chapter-1, we defined five IoT deployment levels. Figure 5.9 shows the deployment level of the home automation IoT system, which is level-1. 5.2.7 Step 7: Functional View Specification ‘The seventh step in the oT design methodology is to define the Functional View. The Functional View (FV) defines the functions of the IoT systems grouped into various Functional Groups (FGs). Each Functional Group either provides functionalities for interacting with instances of concepts defined in the Domain Model or provides information related to these concepts. ‘The Functional Groups (FG) included in a Functional View include: * Device : The device FG contains devices for monitoring and control. In the home ‘automation example, the device FG includes a single board mini-computer, a light Internet of Things - A Hands-On Approach 5.2.8 Step 8: Operational View Specification ‘The eighth step in the IoT design methodology is to define the Operational View Specifications. In this step, various options pertaining to the IoT system deployment and operation are defined, such as, service hosting options, storage options, device options, application hosting options, etc. Figure 5.11 shows an example of mapping functional groups to operational view specifications for home automation IoT system. Operational View specifications for the home automation example are as follows: # Devices: Computing device (Raspberry Pi), light dependent resistor (sensor), relay switch (actuator). © Communication APIs: REST APIs © Communication Protocols: Link Layer - 802.11, Network Layer - IPv4/IPv6, Transport - TCP, Application - HTTP. © Services: 1. Controller Service - Hosted on device, implemented in Python and run as a native service. 2. Mode service - REST-ful web service, hosted on device, implemented with Internet of Things - A Hands-On Approach 5.2.9 Step 9: Device & Component Integration The ninth step in the 1oT design methodology is the integration of the devices and components, Figure 5.12 shows a schematic diagram of the home automation JoT system. The devices and components used in this example are Raspberry Pi mini computer, LDR sensor and relay switch actuator. A detailed description of Raspberry Pi board and how to interface sensors and actuators with the board is provided in later chapters. 5.2.10 Step 10: Application Development The final step in the 1oT design methodology is to develop the loT application. Figure 5.13 shows a screenshot of the home automation web application. The application has controls for the mode (auto on or auto off) and the light (on ot off). In the auto mode, the {oT system controls the light appliance automatically based on the lighting conditions in the room. When auto mode is enabled the light control in the application is disabled and it reflects the current state of the light, ‘When the auto mode is disabled, the light control is enabled and it is used for manually controlling the light. ASL lean ai Sold teas 7-loT Physical Devices & Endpoints f | This Chapter covers ¢ Basic building blocks of an IoT Device ¢ Exemplary Device: Raspberry Pi * Raspberry Pi interfaces ¢ Programming Raspberry Pi with Python ¢ Other IoT devices 7.1 What is an loT Device ‘As described cartier, a"Thing” in Internet of Things (IoT) can be any object that has @ unique identifier and which can send/receive data (including user data) over a network (e.g, smart phone, smart TV, computer, refrigerator, car et, ), IoT devices are connected tothe Internet ‘and send information about themselves or about their surroundings (c.g. information sensed by the connected sensors) over a network (to other devices or servers/storage) or allow ‘actuation upon the physical entitieseavironment around them remotely. Some examples of IoT devices are listed below: ‘* A.home automation device that allows remotely monitoring the status of appliances and controlling the appliances. ‘¢ An industrial machine which sends information about ‘monitoring data toa server. ‘A car which sends information about its location to a cloud-based service. «© A wireless-enabled wearable device that measures data about a person such as the number of steps walked and sends the data to a cloud-based service. operation and health 7.1.4 Basic building blocks of an loT Device ‘An loT device can consist of a number of modules based on functional attributes, such as: ‘¢ Sensing: Sensors can be either on-board the 1oT device or attached tothe device. JoT device can collect various types of information from the on-board of atached sensors such as temperature, humidity, light intensity, etc. The sensed information can be communicated either to other devices or cloud-based servers/storage. ‘© Actuation: IoT devices can have various types of actuators attached that allow taking actions upon the physical entities inthe vicinity of the device. For example, a relay switch connected to an loT device can tum an appliance on/off based on the commands sent tothe device. ‘+ Communication: Communication modules are responsible for sending collected data to other devices or cloud-based servers/storage and receiving data from other devices, and commands from remote applications. ‘© Analysis & Processing: Analysis and processing modules are responsible for making sense of the collected data. ‘The representative IoT device used for the examples in this book is the widely used single-board mini computer called Raspberry Pi (explained in later sections), The use of Raspberry Pi is intentional since these devices are widely accessible, inexpensive, and available from multiple vendors. Furthermore, extensive information is available on their ‘programming and use both on the Intemet and in other textbooks. The principles we teach in ‘ahaa & Macisot © 2015 7.2 Exemplary Device: Raspberry Pi 179 this book are just as applicable to other (including proprietary) 1oT endpoints, in addition to Raspberry Pi. Before we look at the specifics of Raspberry Pi, let us first look at the building blocks of a generic single-board computer (SBC) based IoT device. Figure 7.1 shows a generic block diagram of a single-board computer (SBC) based oT device that includes CPU, GPU, RAM, storage and various types of interfaces and peripherals. Figure 7.1; Block diagram of an JoT Device 7.3 About the Board Figure 7.2 shows the Raspberry Pi board with the various components/petipherals labeled. * Processor & RAM : Raspberry Pi is based on an ARM processor. The latest version of Raspberry Pi (Model B, Revision 2) comes with 700 MHz Low Power ARM1176IZ.F Processor and 512 MB SDRAM. * USB Ports: Raspberry Pi comes with two USB 2.0 ports. The USB ports on Raspberry Pi can provide a current upto 100mA. For connecting devices that draw current more than LO0mA, an external USB powered hub is required. © Ethernet Ports : Raspberry Pi comes with a standard RJ45 Ethemet port. You can ‘connect an Ethernet cable or a USB Wifi adapter to provide Intemet connectivity. * HDMI Output : The HDMI port on Raspberry Pi provides both video and audio ‘output, You can connect the Raspberry Pi to a monitor using an HDMI cable. For ‘monitors that have a DVI port but no HDMI port, you can use an HDMI to DVI adapter/cable. ‘* Composite Video Output : Raspberry Pi comes with a composite video output with an RCA jack that supports both PAL and NTSC video output. The RCA jack can be used to connect old televisions that have an RCA input only. + Audio Output : Raspberry Pj has a 3.5mm audio output jack. This audio jack is used for providing audio output to old televisions along with the RCA jack for video. The audio quality from this jack is inferior to the HDMI output. ‘¢ GPIO Pins : Raspberry Pi comes with a number of general purpose inpuvoupat pins. Figure 7.3 shows the Raspberry Pi GPIO headers. There are four types of pins on Raspberry Pi - true GPIO pins, 12C interface pins, SPI interface pins and serial Rx and ‘Tx pins. ‘+ Display Serial Interface (DSI) : The DSI interface can be used to connect an LCD panel to Raspberry Pi ‘* Camera Serial Interface (CSI): The CSI interface can be used to connect a camera module to Raspberry Pi. ‘© Status LEDs : Raspberry Pi has five status LEDs. Table 7.1 lists Raspberry Pi status LEDs and their functions. ‘* SD Card Slot : Raspberry Pi does not have a built in operating system and storage. ‘You can plug-in an SD card loaded with a Linux image to the SD card slot. Appendix-A provides instructions on setting up New Out-of-the-Box Software (NOOBS) on Raspberry Pi. You will requite atleast an 8GB SD card for seting up NOOBS. ‘¢ Power Input : Raspberry Pi has a micro-USB connector for power input. 7.4 Linux on Raspberry Pi 181 PaaioumonRespienyhiss oe 3.39 Power is present Figure 7.2: Raspberry Pi board 7.4 Linux on Raspberry Pi Raspberry Pi supports various flavors of Linux including: Raspbian Raspbian Linux is a Debian Wheezy port optimized for Raspberry Pi. This is the recommended Linux for Raspberry Pi. Appendix-1 provides instructions on setting up Raspbian on Raspberry Pi. Arch : Arch is an Arch Linux port for AMD devices, ‘¢ Pidora : Pidora Linux is a Fedora Linux optimized for Raspberry Pi. * RaspBMC ; RaspBMC is an XBMC media-center distribution for Raspberry Pi. # OpenELEC : OpenELBC is a fast and user-friendly XBMC media-center distribution. * RISC OS : RISC OS is a very fast and compact operating system. 7.6 Programming Raspberry Pi with Python nist you wl a Row stared with developing yon proce aptry PF Repory Preis ad vppers Pion ora een Ther, ‘Soin any Prins ppm tras on aoa compe owes ie per ferent cpt poised GPA po asp Pa aks (et ee rin Tg os an ert we vai ef ences ‘Tan any Pony PIO pl snd he SPL BC ul wl ies pt ee ‘Spurs comes faery Msn prec avais arto cn Be ae (SE Soding stare ening el ggg ly ch “781 Contring LED with Reapbery PL Lexus iba example of centling a LED on Rage Pie 79 shows (chem dng comeing st LED to Repent Box sows how Retain os 7 1 ropaningRaspberyP wih bon = 0 ‘te LED ew rm oman ine, hs xp LED coed 0 GPO pi ‘Yosonconotte LED sy er OPIO pawl ‘bx 72 shoe» Pym pgm king LED come Raper Psy cont The pga er Nc RP OPD mee ctl th GMO oo Raper Fe ‘Sspogam wesc con ot and en we TrePule evel sere ‘el fee sco [2 ER rs 2 re ‘pee 1 Contoing LED wi Rape 7.6.2 Interfacing an LED and Switch with Raspberry Pi Now let us look at a more detailed example involving an LED and a switch that is used to 2ontrol the LED. Figure 7.10 shows the schematic diagram of connecting an LED and switch to Raspberry Pi. Box 7.3 shows a Python program for controlling an LED with a switch, In this example the LED is connected to GPIO pin 18 and switch is connected to pin 25, In the infinite while oop the value of pin 25 is checked and the state of LED is toggled if the switch is pressed. This example shows how to get input from GPIO pins and process the input and take some ction. The action in this example is toggling the state of an LED. Let us look at another -xample, in which the action is an email alert. Box 7.4 shows a Python program for sending in email on switch press. Note that the structure of this program is similar to the program in 30x 7.3. This program uses the Python SMTP library for sending an email when the switch onnected to Raspberry Pi is pressed. 7.7 Other loT Devices Letus look at single-board mini-computers which are alternatives to Raspberry Pi. Table 73 provides a comparison of some single-board mini-computers that can be used for IoT: Figure 7.12: pcDuino Figure 7.13: Beaglebone Black 7.7.4 peDuino peDuino [105] is an Arduino-pin compatible single board mini-computer that comes with 1 GHz. ARM Cortex-A8 processor. pcDuino is a high performance and cost effective devic 7.7.2 BeagleBone Black ‘BeagleBone Black{ 106) i similar to Raspberry Pi, but a more powerful device. It comes with a | GHz ARM Cortex-A8 processor and supports both Linux and Android operating systems. Like Raspberry Pi, it has HDMI video/audio interface, USB and Ethernet por, 7.7.3 Cubleboard Cubieboard [107] is powered by a dual core ARM Cortex A7 processor and has a range ‘of inpuvoutput interfaces including USB, HDMI, IR, serial, Ethemet, SATA, and 96 pin ‘extended interface. Cubieboard also provides SATA support. The board can run both Linux and Android operating systems. ‘Banga & Macieeti, © 2015, 7.7 Other loT Devices ‘Summary {Inthis chapter you learned about Raspberry Pi which is a low-cost mini-computer. Raspberry i supports various flavors of Linux operating system. The official recommended operating system is Raspbian Linux. Raspberry Pi has an ARM processor, $12MB RAM, two USB ‘ports, HDMI, RCA and audio outputs, Ethernet port, SD card slot and DSI and CS interfaces. ‘Raspberry Pi has serial, SPI and I2C interfaces for data transfer. Raspberry Pi supports ‘Python. You learned how to develop Python programs that run on Raspberry Pi. You learned ‘how to interface LED, switch and LDR with Raspberry Pi. Review Questions 1. How is Raspberry Pi different from a desktop computer? 2. What isthe use of GPIO pins? 3. What isthe use of SPI and I2C interfaces on Raspberry Pi? 8.1. Introduction to Cloud Storage Models & Communication APIs Cloud computing is a transformative computing paradigm that involves delivering applications and services over the Internet. NIST defines cloud computing as (77) - Cloud computing is ‘4 model for enabling ubiquitous, convenient, on-demand network access to a shared pool of configurable computing resources (e.g., networks, servers, storage, applications, and services) that can be rapidly provisioned and released with minimal management effort or service provider interaction, The interested reader may want to refer to the companion book ‘on Cloud Computing by your authors. In this chapter you will learn how to use cloud computing for Intemet of Things (loT), You will learn about the Web Application Messaging Protocol (WAMP), Xively's Platform-as-a-Service (PaaS) which provides tools and services for developing IoT solutions, ‘You will also lear about the Amazon Web Services (AWS) and their applications for oT. 8.2 WAMP - AutoBahn for loT ‘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. Let us look at the key concepts of WAMP: # Transport: Transport is channel that connects two peers. The default transport for WAMP is WebSocket. WAMP can run over other transports as well which support rmessage-based reliable bi-directional communication. ‘* Session: Session is a conversation between two peers that runs over a transport. ‘© 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 tothe topics and receives the events including the payload. 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. ‘© 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. In RPC model Router has the role of a Broker: ~~ Dealer: Dealer acts a router and routes RPC calls from the Caller tothe Callee and routes results from Callee to Caller. + Application Code: Application code runs on the Clients (Publisher, Subscriber, Callee of Caller). Figure 8.1 shows a WAMP Session between Client and Router, established over a Transport. Figure 8.2 shows the WAMP protocol interactions between peers. In this figure the WAMP transport used is WebSocket. Recall the WebSocket protocol diagram explained in Chapter-1. WAMP sessions are established over WebSocket transport within the lifetime of WebSocket transport, [ieee nla ee art ee meee ipa deg Figure 8.1: WAMP Session between Client and Router For the examples in this hands-on book we use the AutoBahn framework which provides ‘open-source implementations of the WebSocket and WAMP protocols [100]. Figure 8.3 shows the communication between various components of a typical WAMP-AutoBahn deployment. The Client (in Publisher role) runs a WAMP. ‘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 (in Broker role) decouples the Publisher from the Subscribers. The communication between Publisher - Broker and Broker - Subscribers happens over a WAMP-WebSocket session. Let us look at an example of a WAMP publisher and subscriber implemented using AutoBahn, Box 8.1 shows the commands for installing AutoBahn-Python, _loT Physical Servers & Cloud Offerings es Figure 8.3; Publish-subscribe messaging using WAMP-AutoBahn ‘nile you can setup the server ane chet pocests on lol mache for ying ou te ‘bls subcribe example, production emtroument, these component anon spare ‘achins. The server process (be brains othe "Thing Tank) is set ona clo asd Instance while te cin processes can rant cal ostsevices oi th eld. 83. Xively Cloud for 1oT ively i « commercial Plfoem-as--Service that can be wed fr creating soaions for Internet of Things. With Xivelyclowd, 1oT developers can foevs onthe fond 8.3 Xvely Cloud for oT Infrastrocte and devices for 1 (tat ene the dat) while ae be hacked data coleion infrastructure and devices for JoT (that generate the data), while the backend data collection infrastructure is managed by Xively, Figure 8.4: Screenshot of Xively dashboard - creating a new device ively platform comprises of a message bus for real-time message ‘management and Teens: data services for time series archiving, directory services that provides ssearhabie directory of objects and business services for device Provisioning and ‘management. Provides an extensive support for various languages and platforms, The Xively libraries ‘nternet of Things - A Hands-On Approach 84 Python Web Application Framework - Django nthe previous section, you eared about the Kiely Pas for collcing a rcesing at ‘som IT sytem: inte clo. You lea Bow tw the Xvely Po ray Te bl {oT appiatons tht ae acted by Xitel lado any oer clon Sons, Yo ‘ah asa 8 Figure 86: Screens of Xivly dashboard data set hc ‘ould eqs some tp of web appiaon framework, In this secton you wil er bout ‘ Pyhoo-ted weh aplication meer ald Django. Diag a cp uc web pean fnew or devo we plant in Pyton (116) 4 ‘Packages and best pacts tat allows developmen of web epplcaton and ynaeas regular-expression-based URL dispatcher. 8.4.1 Django Architecture Django is a Model-Template- View (MTV) framework wherein the roles of model, and view, respectively, are: Model ‘The model acts as a definition of some stored data and handles the interactions with database. na web application, the data can be stored ina relational database, database, an XML fie, etc. A Django mode! is a Python class that outlines the variables methods for a particular type of data. Template Ina typical Django web application, the template is simply an HTML page with a few placeholders. Django’s template language can be used to create various forms of text (XML, email, CSS, Javascript, CSY, ete.) View ‘The view tes the model to the template. The view is where you write the code that generates the web pages. View determines what data is to be displayed, retrieves the from the database and passes the data tothe template, 8.4.2 Starting Development with Django Appendix C provides the instructions for setting up Django. In this section you will how to start developing web applications with Django. Creating a Django Project and App. Box 8.5 provides the commands for creating a Django project and an application Project. ‘When you create a new django project a numberof files are created as described! ‘© —init_py: This file tells Python that this folder is a Python package ‘* manage.py: This file contains an array of functions for managing the sie. ‘ settings.py: This file contains the website's settings a ‘* urls.py: This file contains the URL patterns that map URL to ages, ., ‘A Django project can have multiple applications (“apps”). Apps are where you ‘code that makes your website function. Each project can have multiple apps and, ‘can be part of multiple projects, 8.6 Amazon Web Services for loT In this section you will learn how to use Amazon Web Services for IoT. 86.1 Amazon EC2 Amazon EC2 is an Infrastructure-as-a-Service (laaS) provided by Amazon. EC2 delivers ‘scalable, pay-as-you-go compute capacity in the cloud. EC2 is a web service that provides ‘computing capacity in the form of virtual machines that are launched in Amazon's cloud ‘computing environment. EC2 can be used for several purposes for IoT systems. For example, ‘oT developers can deploy oT applications (developed in frameworks such as Django) on 1EC2, setup IoT platforms with REST web services, etc. Let us look at some examples of using EC2. Box 8.23 shows the Python code for Jaunching an EC2 instance. In this example, a connection to EC2 service is frst established by calling boto.ec2.connect 10 region. The EC2 region, AWS access key and AWS secret key are passed to this function. After connecting to EC2 , a new instance is launched using the conn.run_instances function. The AMI-ID, instance type, EC2 key handle and ‘security group are passed ( this function, This function returns a reservation. The instances associated with the reservation are obtained using reservation. instances. Finally the status ‘of an instance associated with a reservation is obtained using the function. In the example shown in Box 8.23, the program waits till the status ofthe newly launched instance becomes running and then prints the instance details such as public DNS, instance IP, and launch time. Internet of Things - A Hands-On Approach (6.2 Amazon AutoScaling ‘Amazon AutScaing allows moma sealing Aaron EC2 cpa o own ‘coring tower defied cotons Therefore, with AuoScaling wesc ae tbe mame of EC? istics runing tir plications eames ing skein sn oe cae ‘Sciy hn he workon low to ve con Astin can bed fr 882 Amazon AutoScaling ‘Amazon AwtoScaling allows automatically scaling Amazon EC? capacity up or down ‘croring wo se died condoms. Tecfore, with AuoScaling tars cn nese the mmber of EC? instances runing thei applications scamlesly during spikes i the application workloads wo meet the application performance requirements and sale down Capacity when the workload is low to save costs. AvtoScaling canbe used for to scaling {oT aplication and I platforms deployed on Amazon EC2. Lets now lok at some examples of using AutoScalng. Box 825 shows the Python code for creating an AaScalng group. In this ctample, «connection to AutoScaling service ist established by calling boto.ec2.autoscale connect 4region fnction. ‘The BC2 region, AWS accesskey and AWS secret key are psd to this function. Imernet of Things - A Hands-On Approach ae {oT Physical Servers & Cloud Oterings ‘After connecting to AutoScaling service, a new launch configuration is created by calling

You might also like