Internet of Things ( 20 CS002 ) Department of Computer Science and Engineering Vignan's Foundation for Science, Technology & Research
Embedded Software Embedded software is code that runs on custom-built special-purpose hardware which is designed to perform a single well-defined duty again and again. For example, a Bluetooth headphone’s one and only duty is to connect and receive music from another device via Bluetooth and play that out for us. You cannot install any apps on the Bluetooth headphone to change the behaviour of the device. Hence the software that controls the Bluetooth headphone is Embedded Software. Embedded software can also be found running on devices like washing machines, refrigerators, microwave ovens, Xbox controllers, Blood pressure monitors, smartwatches, and other devices that have custom hardware with a microcontroller being used as the main computing component.
Embedded Software Embedded software and firmware are the code that is developed, compiled and flashed into the hardware to allow devices to perform their specific functions. In fact, the very computer you are reading this with, is built with firmware inside, such as the BIOS that controls the motherboard for your PC, which is responsible for booting the OS and controlling the peripheral devices on the motherboard What’s the difference between “embedded software” and “software” that you use every day on your PC? Software that you know so well, such as Office 365 or Photoshop, are applications that run on an OS (operating system) within a computer, such as Windows 10, while embedded software typically runs on embedded devices (with or without a user interface) and they either operate with or without an OS. Ref: https://pyramidsolutions.com/network-connectivity/blog-nc/what-is-embedded-software/
Embedded Software Embedded software is typically pre-installed in a device and not loaded and executed by users. On boot-up, the device loads its operating environment and then executes its embedded software application to control the device. This includes devices that support the ability to communicate with the outside world.
Embedded Software vs. Firmware The firmware in a device is the fixed portion of the device’s low-level software that can’t be modified or executed by a user and is “flashed,” meaning it is burned (programmed) to a FLASH chip that stores the firmware executable image. Firmware’s primary function is to boot a device and control its hardware peripherals, while in contrast, embedded software‘s function is the overall operation and control of the device to perform its specific function.
Examples of Embedded Software
Example: Embedded Software inside the MP3 player Turn-on logic when device is turn on by long pressing the power button, then the event of “button press” is recorded through a GPIO hardware interrupt and a timer is started when the timer reaches the 2 second period another event is generated through a hardware timer interrupt. This calls a function to perform the initialization where the internal and external peripherals are initialized. Once initialized, the latest song that was playing is retrieved from the memory and fed to the DAC, which gives the output sound via the 3.5mm headphone jack.
Example: Embedded Software inside the MP3 player Turn-off logic when device is turn off by long pressing the power button, then the event of “button press” is recorded through a GPIO hardware interrupt and a timer is started once the timer expires 2 seconds another interrupt is given to our embedded software inside, this calls for the clean up procedure The latest song being played is noted down and saved in memory then all the internal peripherals are de-initialized so that they don’t consume power The microcontroller is put into a ultra-low power sleep where the only code that is being run is to listen for the next button press event. The code that you upload into an Arduino is Embedded Software! For example, if you upload a code to make the LED blink, all the code does is to do the “ specific action ” of turning ON the LED followed by a delay followed by Turning OFF the LED again and again and again, until you upload another code into the Arduino!
How Embedded Software Works Each device will have its embedded software developed using a specific programming language, which is typically “C” or “C++.” Higher level devices can also support Python, JavaScript and other languages. The embedded software can include its operating environment and application software. More complex devices will operate using commercially available operating systems such as FreeRTOS , uC /OS, ThreadX , VxWorks, and many other variants.
How Embedded Software Works Embedded software is developed using specific tools as shown below, each performing a different role to help create and build the software. Editor Complier Assembler Debugger Linker
Embedded Software System
Embedded Software System Application: The application–level software that controls the device’s specific function. System Interface: The interface to the OS and hardware provided by system libraries used by the application. RTOS: "Real Time Operating System,” is operating environment in which the application software runs. On some systems, referred to as “ Baremetal ,” there is no operating system, and the application runs direction above the hardware. Hardware Interface: Low–level firmware and driver software required to boot the device and control peripheral hardware devices. Hardware: The microprocessor and peripheral chips on a circuit board along with the FLASH memory that contains the embedded software and firmware and RAM which is used during runtime of the device.
Types of embedded software There are several types of embedded software and they can be broadly classified into the following types. Embedded Bare-metal software Embedded Linux Software Embedded RTOS software and Embedded Networking software Ref: https://embeddedinventor.com/what-does-an-embedded-software-engineer-do/
Embedded Bare-metal software This is the simplest type of embedded system which does its job without an operating system. All other types branched out of this one. Even though the entire software running on these systems look simple, they are actually the hardest to design. Since there is no operating system present here, everything needed by the application from drivers to schedulers must be designed and developed by the software engineering team. It’s called bare metal because of the fact that the software that write runs directly on the chip by manipulating the control registers and reading the status registers. Entire code is written for the specific application, the resulting system will the much more responsive and efficient compared to the other systems.
Embedded Linux Software Linux is famous among embedded engineers as it is an open-source operating system with a customizable kernel. Anyone can make their own operating system to suit their particular needs by keeping just the necessary parts thus keeping the size small yet support their device’s functionality. On top of the kernel, they can make their own application code to make an embedded device. Some famous examples of porting Linux to embedded devices include Raspberry Pi, Beagle Bone, and Jetson devices. This reduces the development time and costs so much compared to building your own embedded operating system.
Embedded RTOS Software Real-time systems act predictable (or deterministic) to events. Their main characteristic is the fact that they will react to events within the specified time constraints. Example of a computer keyboard: When typing something, expect the letter to appear on the screen as soon as type it. If the word comes in even with a 2-second delay then it is going to be a bad experience using your device for the end-user. So the time constraint here is a few milliseconds, They are of 2 types of hard and soft real-time systems Hard real-time systems have a hard deadline Soft real-time systems have a deadline that is not as firm as hard real-time systems.
Embedded Networking software A major part of any embedded software is not generating data, it is rather to transfer data from one module to another, in other words, to make 2 modules talk to each other. Networking is given a special category in embedded software Some examples of network stacks include Ethernet stack, wifi stack, and Bluetooth stack. Examples of such devices can include smartwatches that connect to our devices via Bluetooth or wifi , Bluetooth headphones and speakers etc
Python is fastest-growing language for embedded computing. Researchers migrating into the industry with experience programming drones, robots, or other projects frequently have an Arduino or Raspberry Pi background. While C/C++ is slow to write, error-prone, and frequently unreadable, Python is known for its writability, error reduction, and readability. Embedded algorithms are getting increasingly complex. Simple control loops are being replaced by neural networks and other heavily-involved processes that have helped Python gain its foothold. Python libraries like Theano will optimize Python code for these processes. While Theano is mostly written in C/C++, Python is used to interface with high-performance libraries in a human-friendly way. Python Vs C/C ++
When it comes to speed, however, runtime speed isn’t the only aspect of development to consider and also have to consider development speed. While Python may be less efficient than C/C++ at runtime, during development it’s much more efficient. Interpreters read each line of code, parse it, do runtime checks and call routines in order to execute the operations in the code. Running C/C++ code, where the same line of code might be compiled into just a couple of instructions. This can lead to slower runtime speeds and higher energy consumption with Python. Python Vs C/C ++
Libraries like Theano, there are optimizing extensions for Python like Cython , which is essentially Python with static typing and keywords to run math more quickly. Because Cython is statically typed, you can easily compile to C/C++ and run at C/C++ speeds. Just-In-Time (JIT) compilers are another good way to improve Python’s runtime speed. These compilers work in parallel with Python’s interpreter to generate compiled machine instructions for code inside loops. This allows subsequent passes by the interpreter to execute faster. The PyPy JIT compiler is able to increase Python’s execution speed by nearly a factor of two . JIT compilers should only be used if there’s enough space, though, and embedded systems don’t usually have a lot of that to spare. The best optimization is to use better data structures and algorithms, but this is the hardest task in software design and implementation. Improve Python’s Runtime Speed?
An embedded system is a device with a computer designed for a specific purpose. To achieve that, the device needs an operating system that can respond fast and is prepared to keep working in any event. An embedded operating system is an OS designed and optimized to: Improve the efficiency of managing the hardware resources Reduce response times specifically for the task the device created Embedded Operating System
Ref: https://blog.felgo.com/embedded/embedded-operating-systems Difference between Embedded OS vs General Purpose
COMPONENTS OF EMBEDDED OS Hardware Processors, Timers, Interrupt Controller, I/O Devices, Memories, Ports, etc. Application Software Which may perform concurrently the series of tasks or multiple tasks. Real Time Operating System (RTOS) RTOS defines the way the system work. Which supervise the application software. It sets the rules during the execution of the application program. A small scale embedded system may not need an RTOS. The use of an RTOS further simplifies the design process by splitting the application code Real-time computing is where system correctness not only depends on the correctness of logical result but also on the result delivery time.
EMBEDDED SYSTEM CONSTRAINTS An embedded system is software designed to keep in view three constraints : Available system memory. Available processor speed. The need to limit the power dissipation. When running the system continuously in cycles of wait for events , run, stop and wakeup.
Classification of Embedded Systems Small Scale Embedded System Medium Scale Embedded System Sophisticated Embedded System
Small Scale Embedded OS Single 8 bit or 16 bit Microcontroller. Little Hardware and Software complexity. They may even be battery operated. Usually “C” is used for developing these systems. The need to limit power dissipation when system is running continuously. Programming tools : Editor, Assembler and Cross Assembler.
Medium Scale Embedded OS Single or few 16 or 32 bit microcontrollers or Digital Signal Processors (DSP) or Reduced Instructions Set Computers (RICS). Both hardware and software complexity. Programming tools : RTOS, Source code Engineering tools, Simulator, Debugger and Integrated Development Environment (IDE).
Sophisticated Embedded OS Enormous hardware and software complexity. Which may need scalable processor or configurable processor and programming logic arrays. Constrained by the processing speed available in their hardware units. Programming tools : For these systems may not be readily available at a reasonable cost or may not be even be available at all. A compiler or retargetable compiler might have to be developed for this.
1. Design and Efficiency: The central processing core in embedded systems is generally less complicated, making it easier to maintain. The limited function required of embedded systems allows them to be designed to most efficiently perform their functions. 2 .Cost: The streamlined make-up of most Embedded systems allows their parts to be smaller less expensive to produce. 3. Maintenance: Embedded systems are easier to maintain because the supplied power is embedded in the system and does not require remote maintenance. 4. Accessibility: Embedded systems are difficult to service because they are inside another machine, so a greater effort is made to carefully develop them. However, if something does go wrong with certain embedded systems they can be too inaccessible to repair. This concern is sometimes addressed in the design stage, such as by programming an embedded system so that it will not affect related systems negatively when malfunctioning. Advantages of Embedded OS
Applications of IoT
Applications of IoT
Home Automation
Home Automation Smart Lighting Control lighting by remotely (mobile or web applications) Smart Appliances Provide status information to the users remotely Intrusion Detection Use security cameras and sensors (PIR sensors and door sensors) Detect intrusions and raise alerts The alerts form: an SMS or an email sent to the user Smoke/Gas Detectors Use optical detection, ionization, or air sampling techniques to detect the smoke Gas detectors can detect harmful gases Carbon monoxide (CO) Liquid petroleum gas (LPG) Raise alerts to the user or local fire safety department
Smart Cities
Smart Cities Smart Parking Detect the number of empty parking slots Send the information over the internet and accessed by smartphones Smart Roads Provide information on driving conditions, traffic congestions, accidents Alert for poor driving conditions Structural Health Monitoring Monitor the vibration levels in the structures (bridges and buildings) Advance warning for imminent failure of the structure Surveillance Use the large number of distributed and internet connected video surveillance cameras Aggregate the video in cloud-based scalable storage solutions Emergency Response Used for critical infrastructure monitoring Detect adverse events
Smart Environment
Smart Environment Weather Monitoring Collect data from several sensors (temperature, humidity, pressure, etc.) Send the data to cloud-based applications and storage back-ends Air Pollution Monitoring Monitor emission of harmful gases ( CO 2, CO, NO, NO 2 , etc.) Factories and automobiles use gaseous and meteorological sensors Integration with a single-chip microcontroller, several air pollution sensors, GPRS-modem, and a GPS module Noise Pollution Monitoring Use a number of noise monitoring stations Generate noise maps from data collected Forest Fire Detection Use a number of monitoring nodes deployed at different locations in a forests Use temperature, humidity, light levels, etc. Provide early warning of potential forest fire Estimates the scale and intensity River Floods Detection Monitoring the water level (using ultrasonic sensors) and flow rate (using the flow velocity sensors) Raise alerts when rapid increase in water level and flow rate is detected
Smart Energ y
Smart Energy Smart Grids Collect data regarding electricity generation, consumption, storage (conversion of energy into other forms), distribution, equipment health data Control the consumption of electricity Remotely switch off supply Renewable Energy Systems Measure the electrical variables Measure how much the power is fed into the grid Prognostics Predict performance of machines or energy systems By collect and analyze the data from sensors
Smart Retail
Smart Retail Inventory Management Monitoring the inventory by the RFID readers Tracking the products Smart Payments Use the NFC Customers store the credit card information in their NFC-enabled Smart Vending Machines Allow remote monitoring of inventory levels Elastic pricing of products Contact-less payment using NFC Send the data to the cloud for predictive maintenance The information of inventory levels The information of the nearest machine in case a product goes out of stock in a machine
Smart Logistics
Smart Logistics Route Generation & Scheduling Generate end-to-end routes using combination of route patterns Provide route generation queries Can be scale up to serve a large transportation network Fleet Tracking Track the locations of the vehicles in real-time Generate alerts for deviations in planned routes Shipment monitoring Monitoring the conditions inside containers Using sensors (temperature, pressure, humidity) Detecting food spoilage Remote Vehicle Diagnostics Detect faults in the vehicle Warn of impending faults IoT collects the data on vehicle (speed, engine RPM, coolant temperature) Generate alerts and suggest remedial actions
Smart Agriculture
Smart Agriculture Smart Irrigation Use sensors to determine the amount of moisture in the soil Release the flow of water Using predefined moisture levels Water Scheduling Green House Control Automatically control the climatological conditions inside a green house Using several sensors to monitor Using actuation devices to control Valves for releasing water and switches for controlling fans Maintenance of agricultural production
Smart Industry
Smart Industry Machine Diagnosis Sensors in machine monitor the operating conditions For example: temperature & vibration levels Collecting and analyzing massive scale machine sensor data For reliability analysis and fault prediction in machines Indoor Air Quality Monitoring Use various gas sensors To monitor the harmful and toxic gases ( CO, NO, NO 2 , etc.) Measure the environmental parameters to determine the indoor air quality Temperature, humidity, gaseous pollutants, aerosol
Health & Lifestyle Health & Fitness Monitoring Collect the health-care data Using some sensors: body temperature, heart rate, movement (with accelerometers), etc. Various forms : belts and wrist-bands Wearable electronic Assists the daily activities Smart watch Smart shoes Smart wristbands
When a firmware module is executing, it is called a process or task.A task is usually implemented in C by writing a function. A task or process simply identifies a job that is to be done within an embedded application. A task is a basic unit or atomic unit of execution that can be scheduled by an RTOS to use the system resources like CPU, Memory, I/O devices etc. The control signal that initiates the execution of a task is provided by the operating system. Task Support
At any instant of time a task can be in one of the following states: (i)Dormant (ii ) Ready (iii ) Running and (iv ) Blocked. When a task is first created, it is in the dormant task. When it is added to RTOS for scheduling, it is a ready task. If the input or a resource is not available, the task gets blocked. Embedded program (a static entity) = a collection of firmware modules. When a process is created, it is allocated a number of resources by the OS, which may include: – Process stack – Memory address space –Registers (through the CPU) – A program counter (PC) – I/O ports, network connections, file descriptors, etc. Task Support
Ref: Smart Refrigerator: An IOT and Machine learning based Approach IoT example: Refrigerator
IoT example: Refrigerator
IR sensor uses infrared rays to find an obstacle within in a range of 10cm. Two IR sensors are attached at the edge of the egg tray in the refrigerator. It continuously monitors the presence of the eggs and updates it in the app through firebase. Ultrasonic sensor , sound waves in ultrasonic range are continuously emitted. When it encounters an obstacle the sound waves get reflected. The range of the sensor varies from 2cm to 400cm with a precision of 3mm. Ultrasonic sensor is placed below the lid of milk container. Based on the above principle it measures the quantity of milk present in the container. Load cell is a transducer which transforms force or pressure into electrical signals. Load cell comes in various ranges like 5kg, 10kg, 100kg and more. HX711 amplifier is used with the weighing sensor to amplify the electrical signals generated by the load cell. Bread or any container is placed on the load cell, which measures its weight. Camera module is placed at the top corner of vegetables section of refrigerator model. The camera takes the picture of vegetables present in the fridge. IoT example: Refrigerator
Raspbian Stretch: Raspbian is used as an OS for Raspberry pi. Firebase database: Firebase is used as a cloud platform to store the data in the project. It is real time database which allows sharing the data across Android, IOS and Web apps. It is a cloud-hosted NoSQL database that allows to store and sync data in real time. Firebase data is also available offline, so that the app always has access to the data. The data is automatically synced once the app comes back online. Android Studio: The app is built using android studio platform. Android Studio is Google’s Official Software or IDE (Integrated Development Environment) to develop android Apps. MQTT Client: MQTT is used as a protocol between android app and camera module. OpenCV library: The opencv library is installed in raspberry pi for image processing. IoT example: Refrigerator
Case Study Weather Monitoring System Weather monitoring system is to collect data on environmental conditions such as temperature, pressure, humidity and light in an area using multiple end nodes. The end nodes send the data to the cloud where the data is aggregated and analyzed. The sensors are read after fixed intervals and the sensor measurements are stored.
Case Study Weather Monitoring System (controller service ) The controller service runs as a native service on the device and monitors temperature, pressure, humidity and light once every 15 seconds. The controller service calls the REST service to store these m e as u r e m ents in t h e cloud.
Case Study Weather Monitoring System (deployment design for the system ) The system consists of multiple nodes placed in different locations for monitoring temperature, humidity and pressure in an area. The end nodes are equipped with various sensors . The end nodes send the data to the cloud and the data is stored in a cloud database. The analysis of data is done in the cloud to aggregate the data and make predictions