Anda di halaman 1dari 88

IOT (Internet of Things) Programming

A Simple and Fast Way of Learning IOT

David Etter

Copyright2016 by David Etter


All Rights Reserved
Copyright 2016 by David Etter

All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form

or by any means, including photocopying, recording, or other electronic or mechanical methods, without

the prior written permission of the author, except in the case of brief quotations embodied in critical

reviews and certain other noncommercial uses permitted by copyright law.


Table of Contents

Introduction
Chapter 1- What is the IOT?
Chapter 2- Programming Connected Devices
Chapter 3- Programming Raspberry Pi with C and Python
Chapter 4- Raspberry Pi with Raspbian OS
Chapter 5- Galileo, Windows, and the IOT
Chapter 7- IOT Temperature Controller
Conclusion
Disclaimer

While all attempts have been made to verify the information provided in this book, the author does

assume any responsibility for errors, omissions, or contrary interpretations of the subject matter contained

within. The information provided in this book is for educational and entertainment purposes only. The

reader is responsible for his or her own actions and the author does not accept any responsibilities for any

liabilities or damages, real or perceived, resulting from the use of this information.

The trademarks that are used are without any consent, and the publication of the trademark is without

permission or backing by the trademark owner. All trademarks and brands within this book are for

clarifying purposes only and are the owned by the owners themselves, not affiliated with this document.
Introduction

There is a need for us to come up with mechanisms by which to sense changes in the factors surrounding

us and then take an action based on that. With the IoT, this is possible. In this case, we have a network

made up of physical devices, sensors, and other devices which help us to accomplish our tasks. When

these devices are connected and programmed, then we are capable of taking data from the environment,

transmiting it, and then making a decision based on that. This shows how interesting it is for one to learn

IoT programming. This book discusses this in detail. Enjoy reading!


Chapter 1- What is the IOT?

IoT stands for the Internet of Things and it is just a network made up of physical devices which have

been embedded with software, sensors, and electronics, allowing the devices to exchange data among

themselves. With these, it becomes easy for us to integrate computer-based systems with the physical

systems of the world.

This technology has been powered by leading technologies such as Big data and Hadoop, and this is

expected to be the next greatest thing to impact our lives in a number of ways. Although the IoT is a new

technology, it is believed that it will bring a huge change in the history of computing. Sensors built-in to

automobiles, implants for monitoring the heart, biochip transponders, and smart thermostat systems are

examples of these. It is possible for such devices to be tailor-made so as to meet the needs of the business.

The expectation is that IoT devices will be in a position to communicate with humans just as it happens

with real world devices. IoT devices are also expected to have sensors, and these are expected to capture

data such as pulse rate, the temperature of the body, and they should further transmit such data. The
devices should be capable of making decisions, and exercising control computation. It is believed that

the controllers will be used for the purpose of switching the devices. The devices should also have the

capability of storing data.


Chapter 2- Programming Connected Devices

Before beginning to do this, we should first prepare our environment. We want to demonstrate this using

Arduino and ArdOS.

Arduino is a hardware platform designed for the purpose of prototyping and hobby projects, but one can

still use it for designing more complex hardware.

Begin by downloading the latest version of the Arduino IDE from its official website. For Windows users,

you just have to download an installer, which has a FTDI USB driver and the IDE itself. Make sure that

you have installed the USB driver which is responsible for enabling communications between the IDE

and the Arduino device.

After installation of the software, plug the Arduinos USB cable into the laptop. You will see a pop-up

saying installing driver. After this completes, open the Device Manager by clicking on start->right

click on the Computer icon->Properties->Device manager.

We can then configure the IDE so that we can start to program.

Launch the IDE. From Tools->Boards, choose the board which you need to connect to.
Once the board has been selected, set the right serial port.
You will then have your environment ready for programming. Before moving further, let us explore the

basics of an Arduino C program. This takes the following basic structure:

void setup() {

// add the setup code here, to be run once:

void loop() {

// add the main code here, to be run repeatedly:

The setup() function will be run only once, but the loop() will be run repeatedly. The main logic has

to be implemented inside the loop.

Our First Program in Arduino

Use your Desktop shortcut to open Arduino, or do it from the Program files. You will observe a default
sketch in the IDE. You can then write the following program:

void setup()

pinMode(13,OUTPUT);

// add the setup code here, to be run once:


}

void loop()

// add the main code here, to be run repeatedly:

digitalWrite(13,HIGH);

delay(1000);

digitalWrite(13,LOW);

delay(1000);
}

We have just implemented a simple blinking program. Click on the upload button so that the sketch can

be uploaded to the board.


Getting Input from a Serial Port

First, we should implement a serial communication. This should be done by use of the Serial.begin

command. The method Serial.available() will return true if the data is being written by our other device

in the port. We should begin by checking for our serial data and if it found, we will print it. This is shown

below:

void setup()

pinMode(13,OUTPUT);

// add the setup code here, to be run once:

Serial.begin(19200);

void loop()
{

if(Serial.available())

int n=Serial.read();

Serial.println(n);

}
After uploading the sketch, the result can be checked by opening the Serial Monitor Window by hitting

Ctrl+Shift+M, or from the Tools menu option.

Once the window has been opened, you will see an input window at the top. Just type 1 and then hit enter,

and you will get a 49. If you type in 0, you will get 48. This is an indication that our Serial monitor is

taking in ASCII input from the keyboard. We now need to convert it to a normal number, in which case

we will subtract 48 followed by implementation of the on and off logic.

The program should be as shown below:

void setup()

pinMode(13,OUTPUT);

// add the setup code here, to be run once:

Serial.begin(19200);

Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");

void loop()

if(Serial.available())

int n=Serial.read();

// Serial.println(n);

n=n-48;

if(n==0)
{

Serial.println("LED is OFF");

digitalWrite(13,LOW);

else if(n==1)

Serial.println("LED is ON");

digitalWrite(13,HIGH);

}
else

Serial.println("Only 0 and 1 is accepted as input");

Just load the code to the Serial monitor, and you will observe that the LED will be turned on when you

type 1 and off when you type 0.


Digital Switches

A digital switch logically involves two points A and B which are connected when the switch is closed and

disconnected after the switch has been opened.

The following code shows how we can implement a simple digital with Arduino:

void setup()

pinMode(13,OUTPUT);

pinMode(8,INPUT);

// add the setup code here, to be run once:

Serial.begin(19200);
Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");

void loop()

{ int n=0;

n=digitalRead(8);

if(n==0)

digitalWrite(13,LOW);

else if(n==1)

digitalWrite(13,HIGH);

}
delay(200);// for avoiding over polling by continuously reading port data
}

The Sensors

A sensor is used for converting the physical parameters such as blood pressure, temperature, speed,

humidity, etc., into a signal which is measurable electrically.

Several physical activities can be measured by the use of different types of sensors. Consider the

following code:
void setup()

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

digitalWrite(12,HIGH);

pinMode(8,INPUT);

// add the setup code here, to be run once:

Serial.begin(19200);

Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");


}

void loop()

{int n=0;

n=analogRead(5);

Serial.println(n);

delay(500);

Arduino has two analog pins which have readily been connected to 10 bit ADC. The body of a human

being has a potential difference from the ground, and Arduino has the capability of detecting this. This

can be done by touching the analog pin of the Arduino with our body. This voltage usually ranges from

low to high. The voltage is usually measured between a particular point and the ground. The voltage of

the body acquired by the pins will have the Earth as the ground, and this is not common to the ground of

the microcontroller. This means that there will be too much potential difference.

Before the above program, a wire had been added to the analog pin 5. The program has then been used

for obtaining the analog voltage at our pin 5.


The output we get at the Serial monitor will be as follows:

We now need to minimize the effect of the variations. This can be done by taking the sensor value as the

average of our 10 readings. This is shown in the code given below:

void setup()

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

digitalWrite(12,HIGH);

pinMode(8,INPUT);

// add the setup code here, to be run once:

Serial.begin(19200);

Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");

int s=0;

int j=1;

int x=0;
void loop()

{int n=0;

n=analogRead(5);

s=s+n;

a=s/j;

j++;

if(j>10)

j=1;

s=0;

Serial.println(x);

delay(500);

It is good for you to note that our body voltage has to differ or vary, and the same applies to the open port

voltage of our devices, but the results you get will be closely related.

We now need to trigger an event at the point when the value of voltage exceeds 600 or in case it falls

below 200. In our case, we need to trigger the LED light on after touching the pin, and then switch it off

once the switch has been released. The following program code demonstrates how this can be done:

// Touch the Switch Program. Touch the Pin 5 to Switch on the LED, Release to Switch it off
void setup()

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);
digitalWrite(12,HIGH);

pinMode(8,INPUT);

// add the setup code here, to be run once:

Serial.begin(19200);

Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");

int s=0;

int j=1;
int x=0;

void loop()

{int n=0;

n=analogRead(5);

s=s+n;

a=s/j;

j++;

if(j>10)

j=1;

s=0;

Serial.println(x);

if(x>650 || x<200)

digitalWrite(13,HIGH);

else

{
digitalWrite(13,LOW);

delay(500);

}
User Defined Functions

In Arduino, we are allowed to define functions so that code can be grouped, and be able to call the

function instead of having to write the code again and again. The functions in Arduino are similar to the

functions in the C language. Our previous codes can be put together as shown below:

void SerialLogic()
{

int n=0;

if(Serial.available())

n=Serial.read();

Serial.println(n);

n=n-48;

if(n!=10) // Code for Entering

{
if(n==0)

Serial.println("LED is OFF");

digitalWrite(13,LOW);

else if(n==1)

Serial.println("LED is ON");

digitalWrite(13,HIGH);

}
else

Serial.print("Only 0 and 1 is accepted as input ");

Serial.println(n);

}
void SwitchLogic()

int n=0;

n=digitalRead(8);

if(n==0)

// digitalWrite(13,LOW);

// We can only switch off through Serial Command

else if(n==1)

digitalWrite(13,HIGH);

int s=0;

int j=1;

int x=0;
void SensorLogic()

int n=0;

n=analogRead(5);

s=s+n;

x=s/j;

j++;

if(j>10)

{
// Print a value one in each 5 Second

Serial.println(x);

j=1;

s=0;

// Serial.println(x);

if(x>650 || x<200)

digitalWrite(13,HIGH);

else

//digitalWrite(13,LOW);

// No Turning off:)

void setup()

{
pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

digitalWrite(12,HIGH);

pinMode(8,INPUT);

// add the setup code here, to be run once:

Serial.begin(19200);

Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");

void loop()

SerialLogic();

SwitchLogic();

SensorLogic();

delay(500);

So far, we have created three functions, SerialLogic(), SensorLogic(), and SwitchLogic(), and these

will handle the On and Off through the serial port, switching on via touch, and then switching on via

connection through +3v to pin 12 respectively.

After the loop() we have started to call the functions.

We need to add a little magic to our program. We need to blink the LED 5 times, and this should be done

only once after each 10 seconds. Here is the program for doing this:

void SerialLogic()
{

int n=0;

if(Serial.available())

n=Serial.read();

Serial.println(n);

n=n-48;

if(n!=10) // Code for Entering

{
if(n==0)

Serial.println("LED is OFF");

digitalWrite(13,LOW);

else if(n==1)

Serial.println("LED is ON");

digitalWrite(13,HIGH);

else

Serial.print("Only 0 and 1 is accepted as input ");

Serial.println(n);

}
void SwitchLogic()

int n=0;

n=digitalRead(8);

if(n==0)

// digitalWrite(13,LOW);
// We will switch off only through the Serial Command

else if(n==1)

digitalWrite(13,HIGH);

int s=0;

int j=1;

int x=0;

void SensorLogic()

int n=0;

n=analogRead(5);

s=s+n;

a=s/j;

j++;

if(j>10)
{

// Print the value only one in each 5 Seconds

Serial.println(x);

j=1;

s=0;

// Serial.println(x);

if(x>650 || x<200)
{

digitalWrite(13,HIGH);

else

//digitalWrite(13,LOW);

// No Turning off :)

void BlinkLogic()

Serial.println("Blinking");

for(int p=0;p<5;p++)

digitalWrite(13,HIGH);

delay(500);

digitalWrite(13,LOW);

delay(500);

}
Serial.println("Blinking Ends");

void setup()

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

digitalWrite(12,HIGH);

pinMode(8,INPUT);

// add the setup code here, to be run once:


Serial.begin(19200);

Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");

int t=0;

void loop()

SerialLogic();

SwitchLogic();

SensorLogic();

t++;

if(t>=10)

BlinkLogic();

t=0;

delay(500);

}
You can then upload the program to the board and the output that you get. You will notice that it shows

some problems associated with Arduino programs. The tasks will not be executed concurrently, and they

will naturally be blocking.


Ardos

The distribution of this is done as an Arduino library. Begin by downloading this from here. Give the

zip the name ArdOS.zip. You should remember that special characters are not allowed in Arduino during

the installation of a package or library. Click Sketch menu->Add Library, and then select the package you

have downloaded and renamed.

We want to write a sample program to demonstrate how ArdOS can be used, and then modify our previous

program using it.


Begin by importing the library in a blank sketch. The following should be its header files:

#include <kernel.h>

#include <mutex.h>

#include <queue.h>

#include <sema.h>

The ArdOS programs have to incorporate the programming logic inside the tasks with a signature. This

is shown below:

void task(void * p)

From the setup() method, tasks have to be initialized and then put inside a queue. The loop() should have

any code as the kernel has to look into it. Tasks should also include infinite loops so that the tasks will be

run infinitely.

#include <kernel.h>

#include <queue.h>

#include <sema.h>

#define NUM_TASKS 2

void task1(void *p)

char buffer[16];

unsigned char sreg;


int n=0;

while(1)

sprintf(buffer, "Time: %lu ", OSticks());

Serial.println(buffer);

OSSleep(500);

void task2(void *p)

unsigned int pause=(unsigned int) p;

char buffer[16];

while(1)

digitalWrite(13, HIGH);

sprintf(buffer, "==>Time: %lu ", OSticks());

Serial.println(buffer);

Serial.println("LED HIGH");

OSSleep(pause);

sprintf(buffer, "==>Time: %lu ", OSticks());

Serial.println(buffer);

digitalWrite(13, LOW);

Serial.println("LED LOW");

OSSleep(pause);

}
}

void setup()

OSInit(NUM_TASKS);

Serial.begin(19200);

pinMode(13, OUTPUT);

OSCreateTask(0, task1, NULL);

OSCreateTask(1, task2, (void *) 250);

OSRun();

void loop()

// Empty

In the above code, we have implemented two tasks, that is, task1 and task2. Task1 is responsible for

printing the time in terms of ticks. Task2 will blink the LED at some specific value which is passed as a

parameter and then print the On and Off states with the respective time. The tasks have been implemented

to run continuously via the while(1) loop structure. Note that in this case, we have used OSSleep() instead

of the delay function, as the latter will handle the delay more accurately without necessarily blocking

the other tasks.


You may need to know how critical ArdOS programming is. Just add the following lines to task1, and

then execute it. Here are the lines:

n=analogRead(5);

Serial.println(n);

The n should be declared before the while.

However, we need to increase the baud rate and then implement an analog read in an extra task so as to

get perfect results. This is shown in the following code:

#include <kernel.h>

#include <queue.h>

#include <sema.h>

#define NUM_TASKS 4

void task1(void *p)

{
char buffer[16];

unsigned char sreg;

int n=0;

while(1)

sprintf(buffer, "Time: %lu ", OSticks());

Serial.println(buffer);
OSSleep(1000);

void task2(void *p)

unsigned int pause=(unsigned int) p;

char buffer[16];

while(1)
{

digitalWrite(13, HIGH);

// sprintf(buffer, "==>Time: %lu ", OSticks());

// Serial.println(buffer);

//Serial.println("LED HIGH");

OSSleep(pause);

// sprintf(buffer, "==>Time: %lu ", OSticks());

// Serial.println(buffer);

digitalWrite(13, LOW);

//Serial.println("LED LOW");

OSSleep(pause);

void task3(void * p)

char buff1[16];

int n1=0;

while(1)
{

n1=analogRead(5);

n1=map(n1,0,1023,0,255);

sprintf(buff1, "APV: %d ", n1);

Serial.println(buff1);

OSSleep(1000);

void setup()
{

OSInit(NUM_TASKS);

Serial.begin(115200);

pinMode(13, OUTPUT);

OSCreateTask(0, task3, NULL);

OSCreateTask(1, task1, NULL);

OSCreateTask(2, task2, (void *) 1000);

OSCreateTask(3, task1, NULL);

OSRun();

void loop()

// Empty

}
The output from the above program will clearly demonstrate that it is possible for many tasks to try to

perform writing on a serial port in a parallel manner.

We now need to rewrite our previous code in ArdOS. This will result in a better performance in terms of

scheduling, event trigger, and parallelism. Here is the code for this:

#include <kernel.h>

#include <mutex.h>

#include <queue.h>

#include <sema.h>

void SerialLogic(void *p)

int n2=0;

while(1)

if(Serial.available())

n2=Serial.read();

Serial.println(n2);

n2=n2-48;

if(n2!=10) // Code for Entering

if(n2==0)

Serial.println("SERIAL OFF");

digitalWrite(13,LOW);
}

else if(n2==1)

Serial.println("SERIAL ON");

digitalWrite(13,HIGH);

OSSleep(500);

void SwitchLogic(void *p)

int n3=0;

while(1)

n3=digitalRead(8);

if(n3==0)

// digitalWrite(13,LOW);

// Switching off only through the Serial Command

else if(n3==1)

Serial.println("SWITCH ON");
digitalWrite(13,HIGH);

OSSleep(500);

int s=0;

int j;

int x=0;

void SensorLogic(void *p)


{

int n4=0;

while(1)

n4=analogRead(5);

if(n4>750 || n4<50)

Serial.println("SENSOR ON");

digitalWrite(13,HIGH);

else

//digitalWrite(13,LOW);

// No Turning off :)

OSSleep(1000);

}
void BlinkLogic(void * p)

while(1)

Serial.println("Blinking");

for(int p=0;p<2;p++)

{
digitalWrite(13,HIGH);

OSSleep(500);

digitalWrite(13,LOW);

OSSleep(500);

Serial.println("Blinking Ends");

OSSleep(20000);

void setup()

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

digitalWrite(12,HIGH);

pinMode(8,INPUT);

// add the setup code here, to be run once:

Serial.begin(115200);

// Serial.println("Type 1 to Turn LED on and 0 to Turn it OFF");


OSInit(4);

OSCreateTask(0, SerialLogic, NULL);

OSCreateTask(1, SwitchLogic, NULL);

OSCreateTask(2, SensorLogic, NULL);

OSCreateTask(3, BlinkLogic, NULL);

OSRun();
}

int t=0;

void loop()

}
Chapter 3- Programming Raspberry Pi with C and Python

It is important for us to explore some of the aspects of the operating system we will be using so as to

program our device.

File Manager

This is just a files explorer similar to the Windows explorer on the Windows operating system. This can

be found below the Accessories menu, and it can help you to move your files with no need to use the

command line. With this, you are allowed to browse for files by use of icons and folders in the same way

you do it in an operating system with a GUI.


Web Browser

Midori is the default web browser, and it has been designed to be lightweight and to be used on the small

processors. The most common browsers such as Chrome and Safari are too heavy, as they usually do so

much in the background. However, there are some features which the Midori browser does not support.

Examples of such features include Java plugin and Flash. Also, it does not support all the tags in HTML5.

Netsurf is also another browser which is commonly used in the Raspberry Pi.

Text Editor

Leafpad is the default text editor in the Raspbian OS. Other editors such as the emacs and the Vim can be

installed later, as these do not come installed.


Shell

In the Pi device, most tasks are performed from the command line. The LXTerminal program is used

when we need to run commands from the command line. BASH (Bourne Again Shell) is the default Shell

on the Raspbian OS.

Pi and Python

Python is still one of the best programming languages, due to the clarity of the code and the ease of

programming. The language is interpreted, meaning that there is no need for us to compile it before

execution to get the desired results. There are two ways that we can invoke the Python interpreter:

1. The Python interpreter can be run as an interactive shell, where individual commands have to be

executed.

2. A command line program can also be run for the purpose of executing standalone scripts which

have been written in Python.

The Pythons IDE for Raspberry OS is referred to as IDLE. We now need to demonstrate the above two

ways by use of a Hello there program in Python.

First Method
1. Launch IDLE3 by clicking on the icon from the program menu or from the desktop. You may

have to wait for some time for the IDLE to be loaded.

2. After the IDE has been loaded, a Python Shell window will be loaded.

3. Type the following command on the Python Shell window:

Print (&ldquo;Hello there&rdquo;)

4. Hit the Enter key and you will see the window print Hello there.

Second Method

1. Launch IDLE3 by clicking on the icon from the program menu or from the desktop. You may

have to wait for some time for the IDLE to be loaded.

2. After the IDE has been loaded, a Python Shell window will be loaded.

3. On the Shell window, click on new Window from the file menu.

4. On this new window, type the code given below:

Print (&ldquo;Hello there&rdquo;)

5. Save the file, and give it the name Hellothere.py.

6. You can now open the LX terminal, and then type the command given below so as to execute

your program in the file:


Python Hellothere.py

You may be good in Arduino, and you may be used to writing loops, which are normally referred to as

sketches.

The code given below shows how a sketch or a loop can be written in Python:

#Setup part

initNum = 0

#repeating the loop

While True:

initNum=initNum+1

if((initNum%2)==0):

print(n)

With the above program, we will keep on printing all the even numbers. To run the program from IDLE,

just select the Run Module option from your run menu and then save the file. In the above program, as

you may have noticed, we have used white spaces rather than brackets so as to separate the code blocks.

Python Functions
In Python, white spaces are used for the purpose of separating chunks of code from the main program.

When functions are used, they can be called from anywhere in the program.

Let us implement our previous program again, but in this case, we will use functions and function calls:

#declaring var globally

j=0

#Defining the Setup function

def setup():

global j

j = 100

#Defining the loop function

def loop():

global j

j=j+1
if((j%2)==0):

print(j)

#Main program

setup()

while True:

loop()
Installation of Vim

Most people are familiar with using the Vi editor. This editor can be installed by execution of the

following command:

sudo apt-get install vim

For us to edit a file, we have to open it in the editor as shown below:

vim myfile.py

The Vim editor also comes with a GUI version, and we can choose to install this separately. The following

command can be used for doing this:

sudo apt-get install vim-gnome


Python Installation

In most cases, one will find the latest Python version readily installed in the Pi. If this is not the case, you

can update or install it using the following command:

sudo apt-get install python-dev

Install RPi.GPIO

This is a module which we are allowed to install after installing Python. Its purpose is to allow us access

to the pins for General Purpose Input Output (GPIO) in the Pi.

The module can be installed or updated by use of the following command:

$sudo apt-get install python-rpi.gpio

Debugging in Python

When we are writing our Python programs, sometimes we will land into trouble. This calls for us to debug

the program so as to know the root cause of the problem.


The best tool for doing this is the IDLE interactive mode. The Debug mode provides us with a number

of tools which can help us to analyze our program or code. The two common types of errors which can

occur in this case are syntax errors, which has to do with the structure of the program, and semantic errors

which are as a result of errors in the logic of the program.


Programming in C

The C library for the Raspberry Pi can be downloaded from http://www.airspayce.com/mikem/bcm2835/.

This library will provide us with access to the GPO and the IO functions on the Broadcom BCM 2835

chip, and this usually gives us access to the GPO pins on the 26 pin IDE plug on the RPI board so that we

may be in a position to interface and control the external devices.

It also provides us with functions which we can use to read digital inputs and then set the digital outputs,

by use of SPI and 12C, and these will also help us to access the system timers. The Pin event detection is

usually supported by polling.

Note that the library is compatible with C++, and it is installed as a non-shared library and header file in

Linux distributions.

This can be installed by execution of the following commands, and these have to be executed in a

sequence.

To obtain the tar file from the website, execute the following command:

wget <a href="http://www.airspayce.com/mikem/bcm2835/bcm2835-1.35.tar.gz">

http://www.airspayce.com/mikem/bcm2835/bcm2835-1.35.tar.gz</a>

The tar file can then be unzipped by use of the following command:
tar xvzf bcm2835-1.35.tar.gz

You can then change the directory to an untarred directory as follows:

cd bcm2835-1.35

You can then run the configure command as follows:

./configure

To build the library, execute the following command:

Make

You can then check for the compilation:

sudo make check

Finally, install the library as follows:

sudo make install

At this point, you can test the installation. You just have to run the program given below so as to test

whether the LED will blink after every 500 milliseconds:


#include <bcm2835.h>

#define MY_PIN RPI_GPIO_P1_11

BOOLEAN main(int argc, char **argv)

if (!bcm2835_init())

return FALSE;

bcm2835_gpio_fsel(MY_PIN, BCM2835_GPIO_FSEL_OUTP);

while (1=1)

bcm2835_gpio_write(MY_PIN, HIGH);

bcm2835_delay(700);

bcm2835_gpio_write(MY_PIN, LOW);

bcm2835_delay(700);

bcm2835_close();

return TRUE;

Use the GNU C compile so as to compile your code. This is shown below:

gcc -o blink blink.c -lbcm2835

Lastly, run or execute the code as the admin:

sudo ./blink
Installing Wiring Pi

This can be installed by following the steps given below:

sudo apt-get update

sudo apt-get upgrade

apt-get install git-core

git clone git://git.drogon.net/wiringPi

cd wiringPi

git pull origin

cd wiringPi

./build

We can then test to be sure that the installation was successful. This can be done as follows:

gpio -v

gpio readall

We need to demonstrate how to use C in this case by implementing a program which will help us sense

the intensity of light and then print it on the screen. Here is the code for this:

#include <wiringPi.h>

#include <stdio.h>

#define G_1 0

#define G_2 1
#define G_3 2

typedef unsigned char gchar;

gchar get_Result(void)

gchar j;

gchar dat1=0, dat2=0;

digitalWrite(G_1, 0);

digitalWrite(G_2,0);
digitalWrite(G_3,1);

delayMicroseconds(2);

digitalWrite(G_2,1);

delayMicroseconds(2);

digitalWrite(G_2,0);

digitalWrite(G_3,1);

delayMicroseconds(2);

digitalWrite(G_2,1);

delayMicroseconds(2);

digitalWrite(G_2,0);

digitalWrite(G_3,0);

delayMicroseconds(2);

digitalWrite(G_2,1);

digitalWrite(G_3,1);

delayMicroseconds(2);

digitalWrite(G_2,0);

digitalWrite(G_3,1);
delayMicroseconds(2);

for(j=0;j<8;j++)

digitalWrite(G_2,1);

delayMicroseconds(2);

digitalWrite(G_2,0);

delayMicroseconds(2);

pinMode(G_3, INPUT);

dat1=dat1<<1 | digitalRead(G_3);

for(j=0;j<8;j++)

dat2 = dat2 | ((gchar)(digitalRead(G_3))<<i);

digitalWrite(G_2,1);

delayMicroseconds(2);

digitalWrite(G_2,0);

delayMicroseconds(2);

digitalWrite(G_1,1);

if(dat1==dat2)

return dat1 ;

else
return 0;

int main(void)

gchar rawValue;

gchar calc_Value;

if(wiringPiSetup() == -1){
printf("Failure when calling the wiringPi method!");

return 1;

pinMode(G_1, OUTPUT);

pinMode(G_2, OUTPUT);

while(1){

pinMode(G_3, OUTPUT);

rawValue = get_Result();

calc_Value = 210 - rawValue;

printf("Current calc_Value j: %d\n", calc_Value);

delay(500);

return 0;

}
Chapter 4- Raspberry Pi with Raspbian OS

The Raspberry Pi is a small scale computer which carries enough power for running games, word

processors such as open office, image editors such as Gimp, and other programs of such magnitude.

The Pi was made and introduced as a gadget for educational purposes and for prototyping by the

individuals who need to learn computer programming skills, and especially children. However, this
cannot be used as a substitute for the Linux, Windows, or Mac OS.

The Raspian OS is a free operating system, so feel to download and use it. This OS was developed based

on the Debian Linux, and it has been well optimized so that it can work efficiently on the Pi device.
How to Setup the Raspbian OS

We should begin by connecting the board with all our necessary accessories so that we can install and run

the operating system. The following steps are necessary:

1. Take the Pi out of the antistatic cover and then place it on a non-metal table.

2. Connect the display by connecting the HDMI cable to the HDMI port on your pi and the other

end of the HDMI cable to the HDMI port of the TV.

3. Connect an Ethernet cable from a router to the Ethernet port on the Pi.

4. Connect the USB mouse to one of the USB ports found on the Pi.

5. Connect the USB keyboard to the next USB port on the Pi.

6. Connect your micro USB charger to the Pi, but do not connect it to your power supply.

7. Use the Raspbian OS to flash the flash card.

For the car to be prepared to be used with the Pi, the OS has to be put in the card. The OS files cannot be

dragged and dropped in the card, but it is also not difficult for us to flash the card. Since we need to install

the Raspbian OS, we can begin by downloading it from the link http://www.raspberrypi.org/downloads/.

Once the download is completed, create a folder on your machine and then unzip the contents in it. After

extraction, you will notice that one of the files is a .img, and this is the file which is to be flashed into

the card.
To flash in Linux, follow the steps given below:

1. Launch the terminal on Linux.

2. Insert the SD card into the SD card reader in the machine.

3. List the available disks by typing the sudo fdisk l command.

4. You can then use the cd command so as to navigate to the directory having the .img file you

extracted from the download.

You can then enter the command sudo dd if=imagename.img of=/dev/sdX bs=2M for writing the

imagename.img to the SD card which has been connected to your device address. Note that the

imagename.img has to be replaced with the name of the file which was extracted from the zip archive.

Note that this step will take a bit of time, so be patient for it to complete.

For Windows users, the flashing can be done as follows:

We will use the Image writer which provides us with a graphical user interface (GUI) for doing this.

1. Download the binary image writer for the Windows zip file, and then extract it to a particular

folder in your machine.

2. Plug the SD card into the SD card reader which has readily been connected to the machine.

3. Double click the file Win32DiskImager.exe so as to open the program. You can then click on the

blue folder icon so as to open the dialogue browser for the file browser.
4. Browse to the imagename.img which you had extracted from the download, and then click on the

Open button once you have reached it.

5. Select the drive letter which corresponds to the SDcard from the dropdown dialogue box for the

devices. In case you are not sure of the drive letter to choose, you can open Windows Explorer or

My Computer and check for it.

6. Click on the Write button so that the image can be flashed to the SD card.

Once you are done with flashing the image to the SD card, you can insert it into the SD card slot in the

Pi device. Connect your MicroUSB to your power source, and then power it on. The system should now

boot, and you should see the LEDs on the board blink. At this point, you can use your username and

password for the Pi/Raspberry to login. Some people are not used to using the command line, but they

like using the GUI interface. If you fall under that group, just type startx.

At that point, you will have your OS setup and the Pi will be running.
File System Layout

This refers to the data structure which has been chosen and the defined methods by which to access such

data. It can also refer to the way the disks in the system have been partitioned.

In Linux, files are placed in a branch under the root file system. To see the open branches, just launch the

terminal and then type the following command:

ls /
Programming in Raspberry

As you are aware, the Raspberry Pi comes pre-installed with Python IDE. Let write our sample program

in Python:

1. Launch the Python IDLE 3 from the start menu.

2. Click on the File menu so as to launch a new window.

3. Type the following code in the opened window:

#our first Pi-thon program

print (Hello there)

username = input("Type in your name? ")


print (Welcome to the Pi world, ' + username + ' have a nice time!')

From the file menu, click on Save and then give the file a name. You can then hit F5 on your keyboard,
or click on Run from the Run menu When asked about your name, type it in, and then hit Enter. You will

see the necessary message.

Working with the GPIO Library

We use GPIO pins on the Pi for the purpose of interfacing with the input and output devices. We need

to demonstrate how this can be used by implementing a program for switching on a Green LED. Python

provides us with a library named RPi.GPIO which we can use for the purpose of accessing the GPIO pins.
This comes readily pre-installed in the Raspbian. However, it is important for us to import the library and

then update it in case we have an outdated one.

The following command can be used for this purpose:

sudo apt-get install RPi.GPIO

Now that we have installed the GPIO library, we can go ahead and install the feedparser library which

will help us to parse the feed that we get from Gmail. The following command can be used for installing
this:

sudo pip install feedparser

We should open a new window in the IDLE, and then begin to write our code in it. The first line in our

code should serve to import all the files that we need, and these include the following:

GPIO

Feed Parser

Time

The following import statement can be used for importing these:

import RPi.GPIO as GPIO, feedparser, time

A numbering system can then be assigned to our pins which we need to use. This can be done as follows:

#assign numbering to the GPIO by use of BCM


GPIO.setmode(GPIO.BCM)

#assign a number for the GPIO by use of the Board

#GPIO.setmode(GPIO.BOARD)

After that, we can declare some of the variables that we will be using. This can be done as follows:

USERNAME = "YOUR_USERNAME" #only the part before @ sign, just add yours here
PASSWORD = "YOUR_PASSWORD"

NEWMAIL_OFFSET = 0

MAIL_CHECK_FREQ = 2 # check the mail after every 2 seconds

In the next step, we want to implement the logic which will help us check for the feed which is coming

from the Gmail, and then see if the unread count will be great than 0 and then set our GPIO GREEN to

true, which will mean that we light the GREEN LED.

Otherwise, we should light the RED light. Note that the Green LED has been connected to the pin 18 on

the Pi and the Red LED to the pin 23. As a result of that, the initial values for such variables have been

set to the same. This is shown below:

GREEN_LED = 18

RED_LED = 23

GPIO.setup(GREEN_LED, GPIO.OUT)

GPIO.setup(RED_LED, GPIO.OUT)

while True:

nmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD


+"@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])

if nmails > NEWMAIL_OFFSET :

print("You have", nmails, "new emails!")


GPIO.output(GREEN_LED, True)

GPIO.output(RED_LED, False)

else:

print("You have not received new emails!")

GPIO.output(GREEN_LED, False)

GPIO.output(RED_LED, True)

time.sleep(MAIL_CHECK_FREQ)
Chapter 5- Galileo, Windows, and the IOT

We want to implement an application which uses the Internet, sends some data, and also receives some

commands from a server.

The application will work as follows:

Read temperature.

Send the temperature to the server.

Execute server commands to launch or stop a fan

We should begin by creating the Galileo application. The following are the constants to be used:

// Converting the voltage

double voltage_to_celsius(double voltage) {

//+1 for the schema


return 100 * voltage + 1;

The next one is as follows:

void toggle_motor(bool motor_is_on) {

if (motor_is_on) {

// Turn off the motor


motor_is_on = false;

analogWrite(MOTOR_PIN, 0);

else {

// Turn on the motor

motor_is_on = true;

//for the schema

analogWrite(MOTOR_PIN, 250);

//our old code


//delay(1);

//analogWrite(MOTOR_PIN, 50);

The Windows C++ code for opening the web page should be as follows:

int SendTemperatureAndGetCommand(int deviceId, double temperature, bool fanRunning)


{

char hostname[] = "169.254.178.34";

WSADATA WsaData;

size_t socketResult;

WSAStartup(0x0101, &WsaData);

socketResult = socket(AF_INET, SOCK_STREAM, 0);

if (socketResult == -1)

return -100;

}
struct addrinfo addrinfoHints;

struct addrinfo *pAddrinfo = NULL;

struct addrinfo *pAddrinfoResult = NULL;

int result = -7;

// Setup addrinfoHints address structure of info

// which is to be passed to getaddrinfo() function

ZeroMemory(&addrinfoHints, sizeof(addrinfoHints));
addrinfoHints.ai_family = AF_INET;

DWORD dwReturnValue = getaddrinfo(hostname, PORT, &addrinfoHints,


&pAddrinfoResult);
if (dwReturnValue != 0)

return -101;

// loop through the results and then connect to first we can


for (pAddrinfo = pAddrinfoResult; pAddrinfo != NULL; pAddrinfo = pAddrinfo-
>ai_next)
{
if ((socketResult = socket(pAddrinfo->ai_family, pAddrinfo->ai_socktype,
pAddrinfo->ai_protocol)) == -1)

perror("client: socket");

continue;

if (connect(socketResult, pAddrinfo->ai_addr, pAddrinfo->ai_addrlen) == -1) {


perror("client: connect");
DWORD lasterr = WSAGetLastError();

continue;

break;

if (pAddrinfo == NULL)

{
return -102;

freeaddrinfo(pAddrinfoResult);

char msg[500];
sprintf_s(msg, "GET http://WebSite/SiteName/
Temperatures.aspx?id=%d&temp=%f&fan=false \r\n\r\n ", deviceId, temperature);
if (fanRunning)
sprintf_s(msg, "GET http://WebSite/SiteName/
Temperatures.aspx?id=%d&temp=%f&fan=true \r\n\r\n ", deviceId, temperature);
send(socketResult, msg, (int)strlen(msg), 0);
char buffer[10000];

recv(socketResult, buffer, 10000, 0);

char listen[] = "Listen";

char start[] = "Start";

char stop[] = "Stop";

if (strstr(buffer, listen) != NULL)

result = -1;

}
else

if (strstr(buffer, start) != NULL)

result = 1;

else

if (strstr(buffer, stop) != NULL)

result = 0;
}

closesocket(socketResult);

WSACleanup();

return result;

The motor will be commanded by use of the result from our method.

int result = SendTemperatureAndGetCommand(3, temp_in_c, motor_is_on);

if (result==1) {

if (!motor_is_on) //very sure

toggle_motor(motor_is_on);

motor_is_on = true;

Log(L"Motor On\r\n");

else if (result==0) {
if (motor_is_on) //very sure

toggle_motor(motor_is_on);

motor_is_on = false;

Log(L"Motor Off\r\n");

}
Creating the Server Applications

Our server app should be ASP.Net web site. The parameters should be read as follows:

int deviceId = 0;

double curentTemperature = 0;

bool fanRunning = false;


int commandFanToRun = -1;

if (this.Request["ID"] != null)

{
deviceId = Convert.ToInt32(this.Request["ID"], CultureInfo.InvariantCulture);

if (this.Request["temp"] != null)

{
curentTemperature = Convert.ToDouble(this.Request["temp"],
CultureInfo.InvariantCulture);
}

if (this.Request["fan"] != null)

{
fanRunning = Convert.ToBoolean(this.Request["fan"], CultureInfo.InvariantCulture);
}

The headers can be suppressed by addition of markups, and here is the code to be used, and the result

string should be the command:


Response.Clear();

Response.ClearContent();

Response.ClearHeaders();

Response.Write(result);

Response.ClearHeaders();
Chapter 7- IOT Temperature Controller

We need to create an IoT temperature controller with Arduino.

We should begin by creating an Azure service project. This can be done directly from the Azure

Management Portal. You should use the latest version of Visual Studio. Just choose "New," and then "Web

+ Mobile," and then "Mobile App." Ensure that you give a unique name to your service, and then it will
be easy for you to navigate through the rest of the settings.

Creation of Tables and Controllers

For us to get the mobile database quickly, we can use the Entity Framework code-first approach. To create

an entity object, right click on the folder named DataObjects, then choose "Add->Class." If you are asked

to choose the type, choose the Class type and ensure that the name of the data object ends with a .cs.

Consider the example given below, which shows a device class:

using System;

using System.Linq;

using System.Collections.Generic;

using Microsoft.Azure.Mobile.Server

using System.Web;
namespace cloudcookerService.DataObjects

/// A Device is just a PID controller or another monitor which acts as an IoT device for
reporting information about smoker, sous vide, oven etc.
public class Device : EntityData

public string SerialNumber { get; set; }

public string SharedSecret { get; set; }


public string Name { get; set; }

public string DeviceTypeID { get; set; }

public virtual DeviceType DeviceType { get; set; }

public string OwnerID { get; set; }

public virtual User Owner { get; set; }

public string imageurl { get; set; }

public ICollection<User> Users { get; set; }

public ICollection<Cook> Cooks { get; set; }

The device object should have properties such as the serial number and the name, and these have to be

created as database columns.


After that, you should create a controller class for each of the data objects. With Visual Studio, this is easy

for you. Right click the Controllers folder, and then choose New Scaffolded Item. An interface for

Add Scaffold will be presented to you. Just choose Microsoft Azure Apps Table Controller.

The Add Controller Dialog will then be presented to you. Select one of the classes and then the data

context.

Once you click, your controller will be created. The methods GET/PATCH/POST/DELETE will also be

created for your tables, and then added to your mobile device.
Seeding the Database

We are not required to add the seed data unless our data model will depend on the data to be available in a

table. The seed method can be found from WebApiConfig.cs under the App_Start. The seed code should

create the data objects by use of the dataobject classes which have been defined, and then these should be

added to the mobile device service. Consider the example given below:

protected override void Seed(cloudcookerContext context)

base.Seed(context);

//Add the users

var Users = new List<User>

new User { Id = Guid.NewGuid().ToString("N"),

FirstName = "John", LastName = "Joel",

Email="name@gmail.com" },
new User { Id = Guid.NewGuid().ToString("N"),

FirstName = "Test1", LastName = "User1",

Email="test1@mysite.com" },

new User { Id = Guid.NewGuid().ToString("N"),

FirstName = "Test2", LastName = "User2",

Email="test3@mysite.com" }

};

Users.ForEach(u => context.Users.AddOrUpdate(x=>x.Email,u));


DeviceType TestDeviceType = new DeviceType { Id = Guid.NewGuid().ToString("N"), Name
= "Arduino Prototype 1" };

//Add the devices


Device BGEDevice = new Device { Id = Guid.NewGuid().ToString("N"), Name = "Big Green
Controller", SerialNumber = "14356ABCDE12764", SharedSecret =
"1cc2ae04e95642jol17743cd4d765f51", Owner = Users[0], DeviceType = TestDeviceType };
BGEDevice.Users = new List<User> { };

BGEDevice.Users.Add(Users[0]);
context.Devices.AddOrUpdate(x=>x.SerialNumber, BGEDevice);

The Web App will feature a handy web page which we will use for testing our APIs.

The Azure App Services provides us with an authentication support for Facebook, Google, Microsoft, and

the Azure Active Directory, as well as supporting custom authentication. It is easy for us to implement the

authentication just like signing up with the identity provider and obtaining the necessary keys. Consider

the example given below:

using System.Linq;

using System.Web.Http;

using System.Web.Http.Controllers;

using System.Threading.Tasks;

using System.Web.Http.OData;

using Microsoft.Azure.Mobile.Security

using cloudcookerService.DataObjects;

using Microsoft.Azure.Mobile.Server;

using cloudcookerService.Models;

namespace cloudcookerService.Controllers

[AuthorizeLevel(AuthorizationLevel.User)]
public class CookController : TableController<Cook>

{
protected override void Initialize(HttpControllerContext controllerContext)
{

base.Initialize(controllerContext);

cloudcookerContext context = new cloudcookerContext();


DomainManager = new EntityDomainManager<Cook>(context, Request, Services);
}

The above code demonstrates how the [AuthorizeLevel(AuthorizationLevel.User)] can be added to the
table controller methods or classes which we need to restrict.

Custom APIs

The Azure App services provide us with custom APIs which we can use for implementation of interfaces

which are to be used by our devices. In this example, we need to demonstrate this by starting with an

interface which will directly update our cloud service. Remember that we are implementing an Arduino

app for updating the temperature of food and grill.

We should begin by creating the classes for the objects for data transfer. We have created two classes

for the API. We will use the DirectUpdate class for receiving data from the device, and the

DirectUpdateResponse for relaying data back to the device. Here is the code for DirectUpdate.cs class:

using System;

using System.Linq;

using System.Collections.Generic;

using System.Web;
namespace cloudcookerService.DataObjects

public class DirectUpdate

public string SerialNumber { get; set; }

public string SharedSecret { get; set; }

public string CookConfigurationID { get; set; }

public int CurrentTemperature { get; set; }

public int CurrentFoodTemperature { get; set; }


public bool ControlElementActive { get; set; }

public class DirectUpdateResponse

public string CookConfigurationID { get; set; }

public int SetpointTemperature { get; set; }

public int TargetFoodTemperature { get; set; }

Next, we should create a controller which will be accepting post requests from our Arduino devices. The

class for this is DirectUpdateController.cs, and below is its code:

public async Task<HttpResponseMessage><httpresponsemessage>


PostDeviceUpdate(DirectUpdate item) {
HttpResponseMessage r = new HttpResponseMessage();

//Validate the Device


Device device = context.Devices.Include("Cooks.Configurations").Where(x => x.SerialNumber
== item.SerialNumber).Where(x => x.SharedSecret == item.SharedSecret).FirstOrDefault();
if (device == null) {

r.StatusCode = (HttpStatusCode)403;
r.Content = new StringContent("Invalid Serial Number or the Device has not paired.");
return r;

//Valid Device, then:


CookConfiguration updateCC = await
context.CookConfigurations.FindAsync(item.CookConfigurationID);
if (updateCC != null)

var newDeviceUpdate = new DeviceUpdate {

Id = Guid.NewGuid().ToString("N"),

CookConfiguration = updateCC,

reportDate = DateTime.Now,

currentTemperature = item.currentTemperature,

currentFoodTemperature = item.currentFoodTemperature,

ControlElementActive = item.ControlElementActive

};

context.DeviceUpdates.Add(newDeviceUpdate);

context.SaveChanges();

CookConfiguration currentCC = getCookConfigurationForDevice(device);


if (currentCC==null) {

r.StatusCode = (HttpStatusCode)204;

return r;

}
if (currentCC == updateCC) {

r.StatusCode = (HttpStatusCode)201;

return r;

else {
DirectUpdateResponse directupdateresponse = new DirectUpdateResponse {
CookConfigurationID = currentCC.Id,

setpointTemperature = currentCC.setpointTemperature,
targetFoodTemperature = currentCC.targetFoodTemperature };
r.StatusCode = (HttpStatusCode)250;
r.Content = new StringContent(JsonConvert.SerializeObject(directupdateresponse));
return r;

</httpresponsemessage>

The Azure HTTP request can be created as follows:

if (client.connect(MobileServiceHostName, 80))

Serial.println("Connection to Azure Established");


//Manually create the JSON in global buffer for the POST Request. This is too less expensive
//than when using the JSON Libraries.

sprintf(buffer, "{");
sprintf(buffer + strlen(buffer), "\"serialNumber\": \"%s\",",serialNumber);
sprintf(buffer + strlen(buffer), "\"sharedSecret\": \"%s\",",sharedSecret);
sprintf(buffer + strlen(buffer), "\"cookConfigurationID\":
\"%s\",",currentCookConfigurationID);
sprintf(buffer + strlen(buffer), "\"currentTemperature\": \"%d\",",currentTemperature);
sprintf(buffer + strlen(buffer), "\"currentFoodTemperature\":
\"%d\",",currentFoodTemperature);
sprintf(buffer + strlen(buffer), "\"controlElementActive\": \"%s\"",controlElementActive ?
"true" : "false");
sprintf(buffer + strlen(buffer), "}");

//

// OUR HTTP REQUEST

client.println("POST /api/DirectUpdate HTTP/1.1");

client.print("Host: ");

client.println(MobileServiceHostName);
client.print("X-ZUMO-APPLICATION: ");

client.println(MS_ApplicationKey);

client.println("Content-Type: application/json");

client.print("Content-Length: ");

client.println(strlen(buffer));

client.println();

client.println(buffer);

The code for handling the HTTP response should be as follows:

if (client.connect(MobileServiceHostName, 80))

finder.find("HTTP/1.1");

int statuscode = finder.getValue();

Serial.print("Statuscode = ");
Serial.println(statuscode);

switch(statuscode)

case 200:

setNetworkStatusLED(colorYellow);

client.stop();

break;

case 201:

setNetworkStatusLED(colorGreen);
client.stop();

break;

case 204:

setNetworkStatusLED(colorWhite);

currentCookConfigurationID[0]=0;

setpointTemperature=0;

targetFoodTemperature=0;

client.stop();

break;

case 250:

JSON object.

finder.find("\"CookConfigurationID\"");
finder.getString("\"","\"",currentCookConfigurationID,200);
setpointTemperature = finder.getValue();

targetFoodTemperature= finder.getValue();

client.stop();

break;

case 403:

setNetworkStatusLED(colorBlue);
currentCookConfigurationID[0]=0;

setpointTemperature=0;

targetFoodTemperature=0;

client.stop();

break;

default:

setNetworkStatusLED(colorRed);

client.stop();

}
}

else

Serial.println("Connection to Azure has Failed");

setNetworkStatusLED(colorRed);

}
Conclusion

We have come to the end of this book. IoT stands for the Internet of Things, and it refers to a network

comprised of physical devices which have been embedded with sensors, sensors, and other physical

devices which usually facilitate exchange of data among them. This technology has been powered by big

IT companies in the world, and it is expected to bring much change in the history of computing. There

is a need for you to know how to program the devices used in the IoT. There are various programming

languages which can be used for this purpose. However, the Arduino programming language has been
found to be the best for this purpose, and this is why it is commonly used in programming the IoT.

Anda mungkin juga menyukai