Question: Write a c++ Program To simulate the messages sent by the various IoT devices, a text le called device data.txt is provided that contains a
Write a c++ Program
To simulate the messages sent by the various IoT devices, a text le called device data.txt is provided
that contains a number of device messages sent,
with each line representing a distinct message. Each message contains a device name,
a status value and a Unix epoch value which are separated by commas.
Your c++
program will read this le line by line. It will separate the message into device name,
status value and epoch value and store it in a suitable struct. For each line, a new
thread will be created. The ID of the created thread will be added to the struct which
will then be sent to the new thread. The thread will convert the epoch value to a date
and time string and print all the elements of the struct.
Implementation:
The following steps show how your program should work:
1. Your program should rst request the name of a IoT device data input file.
2. It should then open the provided IoT device data input le and read the input file
line by line.
3. Thereafter it should separate the line into values and store the data in a suitable
struct.
4. For each input line, it should create a new thread with the pthread create()
function.
5. The program then should send the data to the newly created thread via the struct.
6. The thread then should transform the epoch value and print its own thread id as
well as all the data values from the struct.
IMPORTANT
-You have to dene a struct that contains at least the following elements: device
name, status value and epoch time.
-You are not allowed to send the thread id via the struct. Use the pthread self()
function to determine the thread id.
-You have to use the pthread create() function to create threads.
-You will need to use the command line option -pthread with the gcc/g++ com-
piler to successfully compile your program with the Pthread library.
-You have to print verbose output to clearly show what task each thread performs.
device_data.txt
FrontDoor,Closed,1532700000 LivingLight,Off,1532700000 LivingTemp,19,1532700000 LivingTemp,18.5,1532703600 FrontDoor,Open,1532707200 LivingTemp,18,1532707200 LivingLight,On,1532707203 FrontDoor,Closed,1532707205 LivingTemp,18.1,1532710800
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
