Banner Immage for Course

Wireless Networking aka “Wireless for IoT Class”

Course code: CS4222/CS5422

Semester 2, 2022/2023

Instructor: Professor Ambuj Varshney

Contact: ambujv@nus.edu.sg, COM3: #02-25



ASSIGNMENT 2 (Due, 3rd March 2023)

Assignment 2 (Due: 3rd March 2023)

Total Marks: 50 (9% weightage for CS4222/CS5422)

This is an INDIVIDUAL assignment.
Important: We will check for code similarity and potential cases of plagiarism
Important: Please do not use ChatGPT to write code for this assignment. We will particularly check for ChatGPT plagiarism.

Overview

In this assignment, you will learn how to use sensors, actuators and schedule events using timers in the Contiki OS. In addition, this assignment will familiarize you with using sensors and actuators. Essentially, you will sense different physical phenomena, conduct some processing, and correspondingly activate actuators.

Timers

Executions in Contiki is event-driven and use of timers are common. The Contiki system provides a set of timer libraries. In this assignment, you will look at using the etimer and rtimer. A timer uses the data structure struct timer. Three function calls are used to control a timer.

One difference between etimer and rtimer is the time resolution. etimer’s clock resolution depends on the number of clock ticks per second (CLOCK_SECOND), while rtimer uses RTIMER_SECOND.

Another difference is that programming style. Etimer uses a more “sequential” model while rtimer uses callback.

Sample code for etimer:

PROCESS_THREAD(example_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&timer_etimer, CLOCK_SECOND); /* Delay 1 second
*/
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer_etimer));
etimer_reset(&timer_etimer);
}
PROCESS_END();
}

Sample code for rtimer:

PROCESS_THREAD(process_rtimer, ev, data)
{
PROCESS_BEGIN();
init_opt_reading();
while(1) {
rtimer_set(&timer_rtimer, RTIMER_NOW() + RTIMER_SECOND, 0,
do_rtimer_timeout, NULL);
PROCESS_YIELD();
}
PROCESS_END();
}

You can read more about timers on the following link.

Sample Programs

We are providing you three sample programs that can provide you with hints to conduct this assignment.

Run the C programs and observe the output generated by the printf statements. Your Makefile should include names of all the new programs.

CONTIKI_PROJECT = etimer-buzzer rtimer-lightSensor rtimer-IMUSensor

TASKS: Clock Resolution

From the output of etimer-buzzer.c, note down the value of CLOCK_SECOND. Find out how many clock ticks corresponds to 1s in real time. From the output of rtimer-lightSensor.c. note down the value of RTIMER_SECOND. Find out how many clock ticks corresponds to 1s in real time.

TASKS: Implementing States

Write the program to implement the state transition diagram given below.

Banner Immage for Course

The program starts in the IDLE mode. On detecting “significant motion”, it moves into the ACTIVE mode. There are two states in the ACTIVE mode, BUZZ! and WAIT. In the BUZZ! state, the sensorTag uses the buzzer to generate a sound. In the WAIT state, the sensorTag does not generate any sound. When entering the ACTIVE mode from the IDLE mode, the system goes into the BUZZ! state and generate the sound for 3 seconds. After 3 seconds, it goes into the WAIT state (buzzer off) and remains in the WAIT state for 3 seconds before going back to the BUZZ! state. Thus, state transitioning from BUZZ! to WAIT or vice versa occurs every 3 seconds. While in the ACTIVE mode (system can be in either BUZZ! or WAIT state), the system moves to the IDLE state when it detects a significant change in light reading.

Evaluation

Submission instructions: Please submit a single zip file (“CS4222-Assignment2 - YourStudentNumber.zip” or “CS5422-Assignment2 - YourStudentNumber.zip”) to folder “Assignment2 Submission” on Canvas by the due date. If you submit multiple times, only the latest submission will be evaluated.

Your submission should include the following:

  1. A text file (readme.txt) that contains the following:
    • Value of CLOCK_SECOND
    • Number of clock ticks per second in 1s (real time) using etimer.
    • Value of RTIMER_SECOND
    • Number of clock ticks per second in 1s (real time) using rtimer.
    • Any instruction on how to run your program (buzz.c) if needed.
  2. A program called buzz.c that implements the state transition diagram described above. Grading will take into account the robustness and ease of using the sensor controlled buzzer.

Grading/demonstrate should be completed by 10th March 2023.

Late penalty is 10% per day after 10th March 2023.