Pages

Thursday, 11 August 2022

contiki ng -Terminal mode

open the terminal 

ctrl + alt + t


create a folder rk and copy helloworld.c and  makefile from examples folder

vl@ubuntu:~/contiki-ng/examples$ mkdir rk
vl@ubuntu:~/contiki-ng/examples$ ls
6tisch       ip64-router         nullnet            slip-radio
benchmarks   ledprg              platform-specific  snmp-server
coap         libs                rk                 storage
cplusplus    lwm2m-ipso-objects  rpl-border-router  websocket
dev          mqtt-client         rpl-udp
hello-world  multicast           sensniff
vl@ubuntu:~/contiki-ng/examples$ cd rk
vl@ubuntu:~/contiki-ng/examples/rk$ ls
vl@ubuntu:~/contiki-ng/examples/rk$ cp ../hello-world/hello-world.c .
vl@ubuntu:~/contiki-ng/examples/rk$ cp ../hello-world/Makefile .
vl@ubuntu:~/contiki-ng/examples/rk$ ls
hello-world.c  Makefile
 

Now rename hello-world.c to myown.c

vl@ubuntu:~/contiki-ng/examples/rk$ mv hello-world.c myown.c

set the Makefile to myown as shown


Now create myown.c file

#include "contiki.h"

#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(myown_process, "I am on My Own");
AUTOSTART_PROCESSES(&myown_process);
/*---------------------------------------------------------------------------*/
//Protothread
PROCESS_THREAD(myown_process, ev, data)
{
  static struct etimer timer;//static is used here to store the timer in RAM

  PROCESS_BEGIN();

  /* Setup a periodic timer that expires after 10 seconds. */
  etimer_set(&timer, CLOCK_SECOND * 5);

  while(1) { //super loop architecture
    printf("Hello Friends  Welcome to IoT\n");

    /* Wait for the periodic timer to expire and then restart the timer. */
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
    etimer_reset(&timer);
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/

Run:

vl@ubuntu:~/contiki-ng/examples/rk$ make
 

vl@ubuntu:~/contiki-ng/examples/rk$ ls
build  Makefile  myown.c  myown.native

vl@ubuntu:~/contiki-ng/examples/rk$ make TARGET=native
make: Nothing to be done for 'all'.
 

vl@ubuntu:~/contiki-ng/examples/rk$ make clean
TARGET not defined, using target 'native'
 

vl@ubuntu:~/contiki-ng/examples/rk$ make TARGET=native
 

vl@ubuntu:~/contiki-ng/examples/rk$ ./myown.native

 

No comments:

Post a Comment

Peer-to-Peer Networks

  Peer-to-Peer (P2P) networks are a decentralized type of network architecture where each device (or node) on the network can act as both a...