From 7a5b33fbd43687020636664be3d3e26004082ef6 Mon Sep 17 00:00:00 2001 From: test2 Date: Tue, 24 Mar 2020 01:20:22 +0200 Subject: [PATCH] info --- IoT-Wireless/Lab-I.adoc | 63 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/IoT-Wireless/Lab-I.adoc b/IoT-Wireless/Lab-I.adoc index 60a9c18..6e6cd45 100644 --- a/IoT-Wireless/Lab-I.adoc +++ b/IoT-Wireless/Lab-I.adoc @@ -37,8 +37,8 @@ https://en.wikipedia.org/wiki/Contiki[^] ---- unzip InstantContiki2.7.zip vmplayer ----- Start image +---- == Log In When the login screen appears, log in to Instant Contiki: @@ -122,6 +122,18 @@ We have now created our first simulation in COOJA. However, the simulation does To add nodes we need to first create a node type, and then add nodes to the simulation. + +[NOTE] +==== +- The *Network* window, at the top left of the screen, shows all the motes in the simulated network +- The *Timeline* window, at the bottom of the screen, shows all communication events in the simulation over time +- The *Mote* output window, on the right side of the screen, shows all serial port printouts from all the motes. +- The *Notes* window on the top right is where you can put notes for your simulation. +- And the *Simulation* control window is where you start, pause, and reload your simulation. +==== + + + === Create a node type Any simulated node in COOJA belongs to a node type. @@ -226,6 +238,55 @@ A node in the grey area cannot receive packets correctly +=== Extend the hello-world example + +- Create a folder +- Copy+paste the *contiki/examples/hello-world* folder in your new folder. + +==== Sensors, LEDs and Button + +We will extend the Hello World program to let it print sensor data and toggle the leds when the button is pressed. + +.ADD +---- +#include "dev/button-sensor.h" +#include "dev/light-sensor.h" +#include "dev/leds.h" +#include /* For printf() */ +---- + + + +Sensors needs to be activated in the main process: + + +[source,bash] +---- +SENSORS_ACTIVATE(button_sensor); +SENSORS_ACTIVATE(light_sensor); +---- + + +To print out the current light sensor value: + +[source,bash] +---- +printf("Light: \%u\n", light_sensor.value(0)); +---- + +To wait for an event and check if this event is a button press: + +[source,bash] +---- +PROCESS_WAIT_EVENT_UNTIL(ev == sensors_even && data == &button_sensor); +---- + +To toggle LEDs: + +[source,bash] +---- +leds_toggle(LEDS_AL +----