A homepage subtitle here And an awesome description here!

15 May 2020

FlowMonitor for third.cc file in ns3

Flow monitor in ns3

third.cc 

See the video for full instruction and hands on


Step 1: 
Include the header

#include "ns3/flow-monitor.h"
#include "ns3/flow-monitor-helper.h"

Step 2: 
include the follwing above the Simulator::Run()
// Flow monitor 
Ptr<FlowMonitor> flowMonitor;
FlowMonitorHelper flowHelper;
flowMonitor = flowHelper.InstallAll();

Include the following line after the Simulator::Run()

flowMonitor->SerializeToXmlFile("flowthird.xml", true, true);

$] ./waf --run scratch/third
thirdflow.xml

$] ./waf --run "scratch/third --nCsma=10 --nWifi=10"

We have done Step2: compilation


Step 3:
How to process .xml file

in ns3, there is a python file to rpocess the flowmonitor xml files.

copy the /home/pradeepkumar/ns-allinone-3.27/ns-3.27/src/flow-monitor/examples/flowmon-parse-results.py

Copy the file to ns-3.27/ or to the scratch/ folder.

To run this file

$] python scratch/flowmon-parse-results.py flowthird.xml
$] python scratch/flowmon-parse-results.py flowthirdex.xml

https://www.nsnam.com












09 May 2020

Virtual Sensor implementation in Contiki NG OS

Native Temperature, Humidity and Pressure Sensor in Contiki NG 

Implementation of Three sensors namely temperature, humidity and pressure sensor in contiki NG OS.

We need four files namely

Step 1: Create a Folder called temperature/ in the folder contiki-ng/examples/
and then copy paste the following four files to the above folder.

// mytemp.h
#ifndef MYTEMP_H
#define MYTEMP_H
struct Sensor {
 char name[15];
 float value;
};
struct Sensor read_temperature();
struct Sensor read_humidity();
struct Sensor read_pressure();
#endif


// mytemp.c
#include "mytemp.h"
#include <string.h>
#include <stdlib.h>

float random_value(float min, float max)
{
 float scale = rand() / (float) RAND_MAX;
 return min + scale * (max - min);
}

struct Sensor read_temperature()
{
 struct Sensor temp;
 strncpy(temp.name, "Temperature", 15);
 temp.value = random_value(0, 35);
 return temp;
}
struct Sensor read_humidity()
{
 struct Sensor humdidty;
 strncpy(humdidty.name, "Humidity", 15);
 humdidty.value = random_value(40, 80);
 return humdidty;
}

struct Sensor read_pressure()
{
 struct Sensor pressure;
 strncpy(pressure.name, "Pressure", 15);
 pressure.value = random_value(30, 78);
 return pressure;
}


// demo.c
#include "contiki.h"
#include "sys/etimer.h" //etimer Event Timer
#include "mytemp.h"
#include <stdio.h>

PROCESS(sensor_process, "Sensor process");
AUTOSTART_PROCESSES(&sensor_process);

static struct etimer timer;

PROCESS_THREAD(sensor_process, ev, data)
{
 PROCESS_BEGIN();
 printf("Native Sensor\n");
 
while(1) {
 etimer_set(&timer, CLOCK_SECOND*2);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));

 struct Sensor temp = read_temperature();
 printf("%s: %.2f\n", temp.name, (double)temp.value);

 struct Sensor hum = read_humidity();
 printf("%s: %.2f\n", hum.name, (double)hum.value);

struct Sensor pressure = read_pressure();
 printf("%s: %.2f\n", pressure.name, (double)pressure.value);
  
printf("------------\n");
 }
 PROCESS_END();
}



#Makefile
CONTIKI_PROJECT = demo
all: $(CONTIKI_PROJECT)

PROJECT_SOURCEFILES += mytemp.c

CONTIKI = ../../
include $(CONTIKI)/Makefile.include

To run this File

Open a Terminal  and go to contiki-ng/examples/temperature/

$] cd contiki-ng/examples/temperature
$] make TARGET=native 
$] ./demo.native

Please see the screenshot below:
Sensors
Sensors in Contiki NG

Sensors in Contiki NG
Sensors in Contiki NG





Counter Design in Contiki NG Operating System

Counter Design in Contiki NG OS

$] make TARGET=native

Step 1 - Files needed 

myowncounter.h, myowncounter.c and ngcounter.c Makefile.
Inside the folder contiki-ng/examples/myowncounter

Step 2: 
//myowncounter.h

#ifndef MYOWNCOUNTER_H
#define MYOWNCOUNTER_H

int next_round(int temp);

#endif

Step 3: 
//myowncounter.c

#include "myowncounter.h"

int next_round(int temp)
{
if(temp>59)
temp=1;
else 
temp++;
return temp;
}


Step 4: 

//ngcounter.c
#include "contiki.h"
#include "sys/etimer.h"
#include "mycounter.h"

#include <stdio.h>

PROCESS(mycounter_process, "My Counter Process");
AUTOSTART_PROCESSES(&mycounter_process);

static struct etimer et;
static int count=0;

PROCESS_THREAD(mycounter_process,ev,data)
{

PROCESS_BEGIN();
while(1)
{
etimer_set(&et, CLOCK_SECOND*2);
PROCESS_WAIT_EVENT_UNTIL(etimer_Expired(&et));

count=next_round(count);
printf("Count Value : %d\n",count);
}
PROCESS_END();
}

Step 5: Makefile
#Makefile Content
CONTIKI_PROJECT = ngcounter
all: $(CONTIKI_PROJECT)

PROJECT_SOURCEFILES += myowncounter.c

CONTIKI = ../..
include $(CONTIKI)/Makefile.include


How to Execute

To run this, Open the Terminal and Go to 

$] cd contiki-ng/examples/myowncounter
$] make TARGET=native

It will create a file called ngcounter.native file 

$] ./ngcounter.native


You will get the  Output Looks this this:
Contiki NG
Contiki NG

The above code is working on a Mote As Well in Z1 Zolertia Motes as shown below.
Zolertia Z1
Zolertia Z1





Complete Instructions are there in the Video.



Powered by Blogger.

About Me

Featured Post

5G Network Simulation in NS3 using mmWave | NS3 Tutorial 2024

5G Network Simulation in NS3 Using mmWave This post shows the installation of ns3mmwave in Ubuntu 24.04 and simulates 5G networks in ns3. In...

Contact form

Name

Email *

Message *

Total Pageviews

Search This Blog

Pages

Pages

Pages - Menu

Most Popular

Popular Posts