In part 1 of the tutorial, we created an IoT Platform starter project which created an app and two services. Post that, we moved on to create a device type and added Raspberry Pi to it as a gateway.
Here, we will see how to communicate with a device connected to Raspberry Pi from IBM Watson IoT platform. For this project, we will use Node-RED for communication with the assistance of IBM specific nodes.
Steps to be followed is as given below:
Write a code and upload in Arduino Nano that performs the following functions:
Code for Arduino Nano:
const int LEDPIN = 13; void setup() {  Serial.begin(9600);  pinMode(LEDPIN,OUTPUT); // LED actuator  delay(1000); } void loop() {  if (Serial.available()) {   int value = Serial.parseInt();    blink(value);  }   Serial.println(analogRead(A0));  delay(2000); } void blink(int n){  for (int i = 0; i < n; i++) {    digitalWrite(LEDPIN, HIGH);    delay(1000);    digitalWrite(LEDPIN, LOW);    delay(1000);  } }
Power up your Raspberry Pi.
Connect the Arduino Nano to one of the USB ports of Raspberry Pi.
Open node-red in Raspberry Pi.
Create a Node-red flow as given below or import the node-red flow using the link given below:
noderedflow1
Node-RED flow:
In the Node-RED flow, we will perform the following functions:
Deploy the flow and we can observe a blue dot beside the Raspi-01 (Device ID) in the IBM Watson IoT depicting that the gateway is online and connected.
Click on the Raspi-01 and view the recent events.
Go to Dashboard and select RaspberryGatewayNanoDevice Application.
Click on ‘Visit App URL’
Setup Node-RED in IBM Watson IoT.
noderedflow2
Deploy the flow and observe the functions that were tested.
Device Events: The LDR values from the sensor connected to Arduino Nano were obtained by the Raspberry Pi (which is the gateway) and partial processing was done in the gateway which converts LDR values to lux and filter the values with a threshold. The filtered value is obtained in the cloud, stored in a database and sent as a mail.
Commands: An integer value is sent from cloud to the gateway as a command which in turn is sent to the Arduino Nano. The LED connected to Arduino Nano blinks as per the input given by the user. In this example, the user input is 2. Hence the LED will blink two times.
Note: The IBM Watson UI updates frequently and there might be variation with respect to the images provided in this article.
Fill in the details to know more
Layers Of IoT That You Should Know in 2022 | UNext
September 27, 2022
12 Major Applications of IoT You Should Know
June 6, 2022
Confused about IoT? Here’s how you can cut through the noise!
March 23, 2021
30 Best Internet Of Things Examples In 2021
March 6, 2021
Embracing The World Of Java And Internet Of Things: Useful 3 Step Guide For Beginners
August 20, 2020
Using the IoT to Bolster Operational Security
January 22, 2020
What Is the Use of Wrapper Class in Java?
March 22, 2023
What Is Clean Coding in Java?
March 21, 2023
What Are the New Features of Java 17?
What Is File Handling in Java?
March 16, 2023
What Is Data and Time Function in Java?
March 11, 2023
Top 10 Emerging Technologies Blogs To Read In 2023
December 15, 2022
Add your details:
By proceeding, you agree to our privacy policy and also agree to receive information from UNext through WhatsApp & other means of communication.
Upgrade your inbox with our curated newletters once every month. We appreciate your support and will make sure to keep your subscription worthwhile