Internet of Things (IoT)

IoT
Extension Description
Add IoT to your project and control it across the globe.

Introduction

What is IoT?

The Internet of Things is the network of physical objects or “things” embedded with sensors, actuators, and internet connectivity, which enables these objects to collect and exchange data.

A “Thing” in the context of the IoT, is an entity or physical object that has a Unique identifier, which is a unique sequence of characters used to identify or refer to it, combined with an embedded system, and has the ability to transfer data over the internet.

These devices collect useful data and then autonomously flow and share it between other devices.

What is IoT Lifecycle?

Now we know in brief, what is IoT, let’s understand how the IoT ecosystem works in the real world using what is known as an IoT lifecycle.

The IoT life cycle comprises systems for

  1. Collection: Let’s start with the first phase i.e. the collection. For any device or any system to perform any action, first, it needs some data to act on. This data can either be generated from any sensors or any IoT devices about the thing. The data generated can be from any sensor be it temperature sensors, motion sensors, moisture sensors, air quality sensors, light sensors, you name it.
  2. Communication: Next, onto the Communication phase. The data collected from the sensors is then sent to the Internet to some destination with security and reliability. The devices like routers, switches, etc. are used to send data across the destination devices. The destination devices could be
    1. A cloud platform like Google or Alexa
    2. Private data centers like Indian Defence Data Centers
    3. Home networks like Smart-home networks.
  3. Analyzing: In the next phase, that is the Analysis phase, the data we collected needs to be analyzed to create a meaningful format. It could be
    1. Visualizing the data like temperature variation during the day
    2. Building reports to analyze the manufacturing system cause
    3. Setting up events like should you the Air Conditioner ON or OFF depending on the temperature.
  4. Acting: Now that we have the final form of data we need to perform an action according to it. The actions based on the information and data could be
    1. Communicating with another machine- like turning the AC ON or OFF
    2. Sending a notification (SMS, E-mail, or Text)- like notifying that the plants have been watered.
    3. And much more.

Application of IoT

We use IoT in normally all fields of life.

  1. Building and Home Automation
  2. Manufacturing
  3. Medical and Healthcare systems
  4. Environmental monitoring
  5. Energy management
  6. Transportation
  7. Better quality of life for the elderly and whatnot!

What is the Cloud?

In an IoT system, the most important component is the cloud service on which we can store or retrieve data as per the applications. A cloud service is any service made available to users on demand through the internet. Cloud services are designed to provide easy & scalable access to applications, resources, and services. Cloud is the collection of data servers used to provide services like computing, analyzing, networking, etc.

There are a number of cloud service providers out there, like Amazon, Microsoft, Salesforce, Apple, etc. One such cloud service is Adafruit.io which we are going to use.What is Cloud

IoT with Adafruit IO

Adafruit.io is a cloud service – that just means we run it for you and you don’t have to manage it. You can connect to it over the Internet. It’s meant primarily for storing and then retrieving data but it can do a lot more than just that!

PictoBlox supports the IoT applications for Adafruit IO in this extension.

Create an Account in Adafruit IO

Follow the steps:

  1. Go to the website and Sign up: https://accounts.adafruit.com/users/sign_in
  2. Add the details and click on Create Account.
  3. You will be signed in to the account.

From here, you’ll want to learn about two important features of Adafruit IO before proceeding further –  Feeds and Dashboards

Feeds

Feeds are the core of the Adafruit IO system. The feed holds metadata about the data you push to Adafruit IO. This includes settings for whether the data is public or private, what license the stored sensor data falls under, and a general description of the data. The feed also contains the sensor data values that get pushed to Adafruit IO from your device.

You will need to create one feed for each unique source of data you send to the system. For example, if you have a project with one temperature sensor and two humidity sensors, you would need to create three feeds. One feed for the temperature sensor, and one feed for each humidity sensor.

Creating a Feed

Follow the steps:

  1. Go to the Feeds tab. Click on New Feed.
  2. Add the name and description and click on Create.
  3. You will find the feed in the list.
  4. You can click on the feed name and visualize the data.

Dashboard

Dashboards allow you to visualize data and control Adafruit IO-connected projects from any modern web browser. Widgets such as charts, sliders, and buttons are available to help you quickly get your IoT project up and running without the need for any custom code.

Creating a Dashboard

Follow the steps:

  1. Go to the dashboard and click on New Dashboard.
  2. Add the Dashboard Name and Description and click on Create.
  3. Open the New Dashboard. Click on the Setting icon in the top right corner and then click on Create New Block.
  4. From the options, click on the line chart.
  5. Select the Temperature Feed and click on Next Step.
  6. Add the Block Title and the Y-Axis Minimum – Maximum value. Click on Create Block.
  7. You will find the block added on the dashboard.
  8. Add a Humidity block as well. Also, add two gauge elements showing the current temperature and humidity value.
  9. Click on the Setting button and Edit Layout to align all the buttons.

IoT with ThingSpeak

ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams in the cloud. You can send data to ThingSpeak from your devices, create instant visualization of live data, and send alerts.

PictoBlox supports the IoT applications for ThingSpeak in this extension.

Creating a ThingSpeak Account

Follow the steps:

  1. Go to https://thingspeak.com/ and click on create a new account.
  2. Add the details and click Continue.
  3. It will show – Personal Email Detected. Click Continue.
  4. Next, you have to verify your account.
  5. Once verified. Click on Continue. It will ask you to set the password.
  6. Once completed. You will be greeted by your dashboard.

Creating Channel in ThinkSpeak

Collect data in a ThingSpeak channel from a device, from another channel, or from the web.

Follow the steps:

  1. Click on New Channel.
  2. Add Channel information such as name, description, and field names. There can be 8 fields for 1 channel.
  3. Click on Save Channel.
  4. Your channel is created.

API for ThingSpeak

You will need the following data for making code in PictoBlox:

  1. Channel ID: This is the unique ID by which the channel data can be identified.
  2. Read and Write API: These is the unique API keys for performing data read and write operations. You can locate it in the API section of the channel.

Accessing IoT Extension in PictoBlox

Following is the process to add Internet of Things capability to the PictoBlox Project.

  1. Open PictoBlox and create a new file.
  2. Select the coding environment as Block Coding.
  3. Next, click on the Add Extension button and add the Internet of Things extension.
  4. You can find the Internet of Things blocks available in the project.
Read More

PictoBlox Blocks

The block connects the Quarky or ESP32 to the specified Wi-Fi and password. The block is only available in the Upload Mode when the code is uploaded to Quarky. 
The block set up the API connection between the PictoBlox and the Adafruit server with the specified username and AIO key. 
The block creates a new feed or deletes an existing feed with the specified name.
The block sends the specified data to the selected feed as a number or as a string.
The block gets the last data value of the specified feed as a number or as a string.
The block gets the last color value from the specified feed and stores it in PictoBlox. The value can be reported from the get () value block.
The block reports the red, green, or blue value of the color saved from the last data request from the get color from feed () block.
The block reports if the Wi-Fi is connected to the Quarky or ESP32 or not. This block is only available in Upload Mode.
The block connects the PictoBlox to the ThinkSpeak Channel with the specified write and the read API keys. Without this block, other functionality does not work related to ThinkSpeak.
The block sends the data to the ThingSpeak channel with a delay of the specified time seconds. The data is added to field 1 of the channel.
The block sends multiple data to the ThingSpeak channel with a delay of the specified time seconds. The data is mapped to the 8 fields of the ThingSpeak channel.
The block gets the data from the ThingSpeak channel and stores the 8 field values in PictoBlox.
The block reports the selected field data from the last read request from ThingSpeak.
The block makes the specified type of HTTP request (GET, POST, or DELETE) on the specified URL. The request can have a body or not.
The block defines the value of the body.
The block sets the body content type to the specified value.
The block reports the request-response code received.
The block reports the body or error value from the HTTP request.
The block reports the value of the JSON object from the body.
The block reports the object count of the JSON object from the body.
All articles loaded
No more articles to load

Block Coding Examples

All articles loaded
No more articles to load

Python Functions

The function creates an object to connect Quarky with Wi-Fi.
Syntax: wifi()
The function connects the Quarky or ESP32 to the specified Wi-Fi and password. The block is only available in the Upload Mode when the code is uploaded to Quarky.
Syntax: wifi.connecttowifi(WIFI = “Wi-Fi Name”, PASSWORD = “password”)
The function reports if the Wi-Fi is connected to the Quarky or ESP32 or not. This block is only available in Upload Mode.
Syntax: wifi.iswificonnected()
The function creates an Adafruit IO object that set up the API connection between the PictoBlox and the Adafruit server with the specified username and AIO key.
Syntax: adaio.connecttoadafruitio(username = “username”, AIO Key = “AIO key”)
The function creates a new feed with the specified name in the Adafruit IO account.
Syntax: adaio.createfeed(feed name = “feed name”)
The function deletes the feed with the specified name in the Adafruit IO account.
Syntax: adaio.deletefeed(feedname = “feed name”)
The function sends the specified data to the selected feed as a string.
Syntax: adaio.createdata(feedname = “feed name”, data = “0”)
The function returns the last data value of the specified feed as a string.
Syntax: adaio.getdata(feedname = “feed name”)
The function gets the last color value from the specified feed and stores it in PictoBlox or Quarky.
Syntax: adaio.getcolordata(feedname = “feed name”)
The function returns the red, green, or blue value of the color saved from the last data request.
Syntax: adaio.getRGB(color = “red”)
The function creates a Python object for the Thingspeak library.
Syntax: thingspeak()
The function connects the PictoBlox to the ThinkSpeak Channel with the specified write and the read API keys. Without this function, other functionality does not work related to ThinkSpeak.
Syntax: ts.connecttothingspeak(channel_ID = 1234567, read_API = “readAPI”, write_API = “writeAPI”)
The function sends the data to the ThingSpeak channel. The data is added to field 1 of the channel.
Syntax: ts.senddatatocloud(data = 100)
The function sends multiple data to the ThingSpeak channel. The data is mapped to the 8 fields of the ThingSpeak channel.
Syntax: ts.sendmultipledatatocloud(field_data_1 = 100, field_data_2 = 100, field_data_3 = 100, field_data_4 = 100, field_data_5 = 100, field_data_6 = 100, field_data_7 = 100, field_data_8 = 100)
The function gets the data from the ThingSpeak channel and stores the 8 field values in PictoBlox or Quarky.
Syntax: ts.getdatafromthingspeak()
The function reports the selected field data from the last read request from ThingSpeak.
Syntax: ts.getdatafromfield(field = 1)
The block makes the specified type of HTTP request (GET, POST, or DELETE) on the specified URL. The request can have a body or not.
Syntax: makeapirequest(request = “GET”, url = “url”, bodytype = “with”)
The function defines the value of the body.
Syntax: setbody(body = “{“value”:”5″}”)
The function sets the body content type to the specified value.
Syntax: setcontenttype(type = “application/x-www-form-urlencoded”)
The function reports the request-response code received.
Syntax: requestapicode()
The function reports the body or error value from the HTTP request.
Syntax: getresponse(type = “body”)
The function reports the value of the JSON object from the body.
Syntax: getapijson(json1 = “value”, json2 = “”, json3 = “”, json4 = “”, json5 = “”)
The function reports the object count of the JSON object from the body.
Syntax: getobjectcountapijson(json1 = “value”, json2 = “”, json3 = “”, json4 = “”)
All articles loaded
No more articles to load

Python Coding Examples

All articles loaded
No more articles to load
Table of Contents