C代写:CS111181 Cignal

物联网(IoT)将Internet连接扩展到小型电子设备(例如传感器)。在物联网的保护下,软件应用程序与传感器进行远程通信,读取其数据并在必要时更改其配置。作业需要实现物联网软件系统Cignal的部分开发功能。

IoT

Introduction

Internet of Things (IoT) extends Internet connectivity to small electronic devices such as sensors. Under the IoT umbrella, software applications remotely communicate with sensors, read their data, and change their configuration if necessary. In this assignment, you will implement parts of the functionality of a sample IoT software system called Cignal.

Cignal implements a greenhouse temperature and humidity control system. A gateway controller manages the real- time operation of a remotely connected air conditioner (AC) by reading the temperature and humidity sensors data which are deployed in the environment. The Cignal system includes the following components.

  • Gateway Controller
  • Humidity and Temperature Sensors
  • Message (Which is named as Cignal in this assignment)
    • Handshake Cignal
    • Sensors Update Cignal
    • AC Condition Cignal

Gateway Controller

The gateway controller is mainly responsible for reading temperature and humidity sensors, and adjusting the AC system accordingly. The AC system has two components, the chiller (for cooling) and the dehumidifier. The gateway controller manages each of them independently. To do so, it adjusts the chiller configuration on ON or OFF based on the temperature sensor and it adjusts the dehumidifier condition based on the humidity sensors report. The gateway controller uses the sensors report to compare them against the pre-defined set-points for the temperature and humidity levels. The set-points are used as the ideal values for the temperature and humidity, and the gateway controller adjusts the AC system to ON or OFF to either increase or decrease the temperature and humidity variables to allow them to converge to the values denoted by the set-points.

Note: In real environments, the new AC adjustments will change the future sensors updates, since the sensors scan the environment and capture the changes. However, since we don’t have a real AC system in place, we simulate the behavior of one by informing the sensors of the AC condition. For instance, each temperature or humidity sensor sends its updates to the gateway controller. The gateway will evaluate the reports and respond to the sensors giving them a new AC condition. By reading the response from the gateway, the sensors know if they have to increase or decrease the value of the corresponding variable.

Humidity and Temperature Sensors

The two sensors simulate the behavior of a real sensor that reads the environment and reports the changes at a pre- defined frequency. The sensors in this assignment do the following tasks:

  • Handshake with the gateway controller. This process will register a device with the gateway. The gateway discard messages from unknown devices.
  • Generate temperature and humidity levels based on the AC condition reports. The initial sensor value is set in the starter code. This value is used when a sensor reports its reads for the first time to the gateway.
  • Create and maintain a TCP socket communication with the gateway controller. Note that the sensors create a new connection for each message (Cignal) they send to the server. The socket remain open until the gateway sends a message back to the client and then both server and client must close the connection.

Message (Cignal)

Messages are named Cignals in this assignment. Cignals are fixed-sized messages that carry either data or control commands. Each Cignal message has a header and a data payload.

The fix message size is 20 characters. The three message types will use the message header and payload as described in the followings:

  • Handshake. The sensors will set the Device_ID to -1 and Type to 1 to initiate a handshake. The gateway responds by changing the Device_ID to any number between 11-99 and leave the Type intact. The handshake process is a form of request/response communication that is first done by each sensor process to register itself on the gateway. Any future communication between the sensors and the gateway will use the associated Device_ID.
  • Sensor Update. Sensors will report their updates regularly. Each Cignal update will turn the Device_Type to 1 for temperature and 2 for humidity. The Type will be set to 2 and the associated Device_ID will be used to validate the device registration. The sensors value will be added to the Value as a floating number with 4 precision.
  • AC Condition. Upon the receipt of each sensor update, the gateway will respond with an AC condition report. The message will change the Type to 3 and change the value for Cooler or Humidity to either 0 or 1 depending on the type of the sensor’s update.

Code Organization

The code base of the Cignal Assignment includes the following components:

  • Message Library. The library defines the message data structure and a set of operations that prepares a message for transmission on the network.
  • Socket Library. The library implements necessary mechanisms to create TCP sockets and establish a communication.
  • Controller Library. The library implements mechanisms that process incoming messages to the gateway and prepare a proper response for them.
  • Gateway Source Code. The source code implements the gateway controller processes.
  • Temperature and Humidity Source Code –] They implement the sensors processes.

Note: We highly recommend that you spend some time reading through this assignment document and the source code first to understand the different components of the system, their role, and interaction model before you start coding.

Running the program

Run gateway <port number> in one terminal and run one or more temperature and or humidity programs in additional terminal windows. The server runs an infinite loop, so the only way to terminate it is to kill it. You can also use gdb on the clients and the server to help you debug your code. Remember to check for errors on all system calls.

Here is some sample output from the gateway for your reference:

The Cignal Gateway is now started on port: 4000

Waiting for Sensors update...
Waiting for Sensors update...
Waiting for Sensors update...
Waiting for Sensors update...
Waiting for Sensors update...
Waiting for a new connection...
New connection accepted from 127.0.0.1:50574
RAW MESSAGE: -1|1|1|22.0000|0|0|
********************END EVENT********************

Waiting for a new connection...
New connection accepted from 127.0.0.1:50575
RAW MESSAGE: 11|1|2|22.0000|0|0|
Temperature: 22.0000 --] Device_ID: 11
********************END EVENT********************

Waiting for a new connection...
New connection accepted from 127.0.0.1:50576
RAW MESSAGE: 11|1|2|21.5600|1|0|
Temperature: 21.5600 --] Device_ID: 11
********************END EVENT********************

What to do

There are three places in the starter code where you will implement the communication and message handling between the gateway and the sensors. This code all interacts, so you will likely need to implement all three parts at roughly the same time. There are TODO comments that mark where your code will be added.

  • Communication loop in gateway.c - The program will use select to multiplex between different connections. This loop will also handle the reading and writing to the sensors.
  • process_message in controller.c - This function processes an incoming message to determine how to respond. Please read the starter code and make use of the available helper functions.
  • The client communication in temperature.c and humidity.c - Implements the handshake and subsequent communication with the gateway server.

What to submit

Add, commit, and push your modified assignment code to the repository. No additional files should be added. Please remember not to add executable or object files to your repository.