嵌入式系统代写代做代考 Embedded Systems Reconfigurable computing

Reconfigurable computing

Small Embedded Systems

Unit 5.4
Accessing the Internet of Things

Internet of Things
Useful objects report status to Internet and can be controlled via Internet
Status of objects can trigger further actions (tweets, emails, …)
Uses cloud services from various providers (some free, some paid)
There is some kind of authentication token to protect access
We’re going to use a service called Blynk

Heating
Lighting
Slow cooker
Coffee machine
Burglar alarm

Protocols for the Internet of Things
TCP/IP is used to route messages between Internet devices, but what application protocol should we use on top of TCP/IP to formulate our messages and their responses?
HTTP can be (and often is) used, but has disadvantages:
Server and client must be on at the same time
Only the client can initiate communication
Communication is normally 1-to-1:
Broadcast/multicast is complicated and expensive
HTTP requires a reasonable amount of memory and processing power in the devices
IoT systems often use alternative approaches that remedy these concerns
We’ll look at the most widely used: MQTT
We’ll introduce a similar protocol, Blynk, and how this can be used with Arduino

Publish-Subscribe Service
Distributed network of devices (“clients”)
Clients that have data that others may want upload (“publish”) their data to a server called a “broker”. The data is tagged with a “topic”.
Clients that may want to access a particular topic register their interest (“subscribe to that topic”) with a broker
https://uk.mathworks.com/help/supportpkg/raspberrypi/ref/publish-and-subscribe-to-mqtt-messages.html

Publish-Subscribe Service
When the broker receives a new published message, it pushes the message out to all clients that are subscribed to the message topic
Nodes can simultaneously be publishers for some topics and subscribers for others
Advantages of the publish-subscribe pattern:
The publishers and subscribers never contact each other directly. The connection between them is handled by the broker.
Publishers do not need to know or care about the number or location of subscribers and how the network is laid out
Publishers operate independently of subscribers. Publishers and subscribers do not need to be online at the same time
Good scalability

MQTT
Name originally stood for Message Queue Telemetry Transport
Developed by IBM and Arcom Systems
Designed for resource-constrained devices and low bandwidth, high latency networks
Lightweight publish/subscribe messaging transport for machine-to-machine (M2M) and Internet of Things (IoT)
Example real-world applications:
Communications in IECC Railway Signaling Control System
Telemetry in Microsoft Azure IoT Hub
Example implementations that are easy to get into:
Adafruit.io (from the makers of the Feather boards, e.g. the Huzzah): free cloud service for IoT hobbyists and experimenters
Node Red: browser-based development tool that can implement MQTT for Raspberry Pi and other SBCs

Blynk
Blynk is an IoT rapid application development (RAD) platform
Mobile app capable of interfacing with hardware platforms such as Arduino or Raspberry pi.
Available free from App Store or Google Play
Blynk requires a server to act as an interconnection layer between the hardware and the mobile app.
Can use the Blynk server based in the Cloud accessed over the public global Internet or can set up your own local server

Getting the Hardware ready for Blynk
When you use a computer for the first time, you will need to install the Blynk library files into the Arduino environment
Files (Blynk_Release_v0.6.1.zip) are at at https://github.com/blynkkk/blynk-library/releases

Using the Blynk app
Download the Blynk app to your mobile device and go online
Create an account and login
Create a new project

Using the Blynk app
When you create a project, you will be given an authorization token
This provides security as your hardware board will be programmed only to respond to messages that contain that authorization token
Within a project you can use various widgets and connect them to actions within your hardware board

Widgets can be connected to
Pins on the board
e.g. GP0 for the red LED
“Virtual pins” (not really pins, but data items that can be connected to variables within your code)
e.g. V5: this can be used to send values to variables in your code
The free version gives you a budget of 2000 energy units

Switch a GPIO Value
Create a button

#define BLYNK_PRINT Serial // Enable prints to console
#include
#include
char auth[] = “XXXXXXXXXXXXXXXXXXXX”; // Your token here
char ssid[] = “XXXXXXXXXXX”; // Your network name here
char pass[] = “XXXXXXXXXXX”; // Your network password here

void setup() {{
Serial.begin(115200); // Debug console
Blynk.begin(auth, ssid, pass);
}

void loop() { {
Blynk.run();
// Add your own code here, but avoid using the delay() function!
}

Switch a GPIO Value
Connect the button to GP0

#define BLYNK_PRINT Serial // Enable prints to console
#include
#include
char auth[] = “XXXXXXXXXXXXXXXXXXXX”; // Your token here
char ssid[] = “XXXXXXXXXXX”; // Your network name here
char pass[] = “XXXXXXXXXXX”; // Your network password here

void setup() {{
Serial.begin(115200); // Debug console
Blynk.begin(auth, ssid, pass);
}

void loop() { {
Blynk.run();
// Add your own code here, but avoid using the delay() function!
}

Send Data to a Virtual Pin
Create a slider and connect it to virtual pin V1

// Everything up here is same as previous

void loop() { {
Blynk.run();
// Add your own code here, but avoid using the delay() function!
}

BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin
// V1 to a variable
analogWrite(2,pinValue); // Brighten/fade the blue LED
Serial.print(“V1 Slider value is: “);
Serial.println(pinValue);
}

Reading Data from a Virtual Pin
When you create a project, you will be given an authorization token

// Everything up here is same as previous
BlynkTimer timer;

void setup() {
Serial.begin(115200); // Debug console
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
}

void loop() {
Blynk.run();
timer.run(); // Initiates BlynkTimer
}

void myTimerEvent() {
Blynk.virtualWrite(V5, millis() / 1000);
}

Summary
IoT services
Publish-subscribe services
MQTT
Blynk
Blynk code examples

/docProps/thumbnail.jpeg