Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Apr 7, 2015

Configuration for passive Wi-Fi

Gateway node for smart tracking

File 8 4 15 2 14 32 am Configurations for gateway node:

1) configure Wi-Fi username and password:

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

2) update server address:

cd ~/Desktop/data_gather

sudo vi probe_request_gather.py

Then, modify "SERVER_ADDRESS"

Nov 10, 2014

A test for my Arduino working with NRF24L01+PA transceiver

There are two computers, one is called Joker and the other is called Batman. They use Morse code to communicate. The microcontroller is Arduino and the wireless transceiver is NRF24L01+PA. I find that sometimes it works fine especially at night when few people are in the lab, but sometimes transmission failed (both of them can not talk to each other or just one-way communication works). Not sure if the reason is the interference from wifi.

Sep 29, 2014

A simple office desk safety alarm system

Something you need: 1 arduino microcontroller, 1 breadboard, 1 LED, 1 PIR sensor and some wires.

May 26, 2014

A shortcut to convert PDF to EPS

Just find a good way to convert pdf file to eps. This is quite useful when you edit a paper with Latex. Before we do it, we need to download the Texshop (http://pages.uoregon.edu/koch/texshop/):

To convert pdf → eps (Mac OS X will only do (e)ps → pdf & pdf → ps),

- open the pdf in TeXShop, choose the 'Selection' tool in the Preview window toolbar

- select the desired rectangle (or all, either with ⌘-A or manually),

- choose 'Preview>Save Selection to File...', & save as eps."

Jul 18, 2013

Add a new MAC protocol in NS2

I just install the NS2 in my machine. If you are not sure, please read:
http://itantenna.blogspot.com.au/2012/01/install-ns234-on-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2011/11/install-ns21b9a-tens-in-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2010/10/ns2macintosh.html;
Now let`s add a new MAC protocol.
1) Put your new MAC program files (newMAC.cc and newMAC.h) to ns-2.34/mac
2) Modify common/packet.h
#define HDR_NEWMAC(p) ((hdr_newmac *)hdr_mac::access(p)) // add newmac here
Find "enum packet_t{}" and add PT_NEWMAC. Notice that it must be added before PT_NTYPE.
Find "class p_info{}" and add name_[PT_NEWMAC] = "newmac". It must be before name_[PT_NTYPE] = "undefined".
3) Modify tcl/lib/ns-default.tcl
Add Mac/NEWMAC set syncFlag_ 1
Add Mac/NEWMAC set selfConfigFlag_ 1
Add Mac/NEWMAC set dutyCycle_ 10
……
In the later line,
Add Mac/NEWMAC set syncFlag_ 0
4) Modify tcl/lib/ns-packet.tcl
Find "foreach prot{}" and add NEWmac
5) Modify ns2.34/Makefile
Add mac/newmac.o \
6) Now a new MAC protocol has been added to NS2. We will modify some trace files in the next.
7) Modify trace/cmu-trace.h
Add void format_newmac(Packet *p, int offset);
8) Modify trace/cmu-trace.cc
Find "void CMUTrace::format_mac_common(Packet *p, const char *why, int offset)"
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_mac802_11 *mh;
struct hdr_smac *sh;
struct hdr_newmac *ph; // add newmac pointer
char mactype[SMALL_LEN];
strcpy(mactype, Simulator::instance().macType());
if (strcmp (mactype, "Mac/SMAC") == 0)
sh = HDR_SMAC(p);
else if (strcmp (mactype,"Mac/NEWMAC") == 0)
ph = HDR_LMAC(p);
else
mh = HDR_MAC802_11(p);
……
if (strcmp (mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp (mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
return;
Find "if(newtrace)"
offset = strlen(pt_->buffer());
if (strcmp(mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp(mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
(ch->ptype() == PT_SMAC) ? (
(sh->type == RTS_PKT) ? "RTS" :
(sh->type == CTS_PKT) ? "CTS" :
(sh->type == ACK_PKT) ? "ACK" :
(sh->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
(ch->ptype() == PT_NEWMAC) ? (
(ph->type == RTS_PKT) ? "RTS" :
(ph->type == CTS_PKT) ? "CTS" :
(ph->type == ACK_PKT) ? "ACK" :
(ph->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
packet_info.name(ch->ptype())),
ch->size());
……
if (strncmp (mactype, "Mac/SMAC", 8) == 0) {
format_smac(p, offset);
}
else if (strncmp (mactype, "Mac/NEWMAC", 8) == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
Add a new function
void CMUTrace::format_newmac(Packet *p, int offset)
{
struct hdr_newmac *ph = HDR_NEWMAC(p);
sprintf(pt_->buffer() + offset,
" [%.2f %d %d] ",
ph->duration,
ph->dstAddr,
ph->srcAddr);
}
9) Find "void CMUTrace::format(Packet* p, const char *why)"
Add
switch(ch->ptype()) {
case PT_MAC:
case PT_SMAC:
case PT_NEWMAC:
break;
case PT_ARP:
format_arp(p, offset);
break;
10) Finally, add the header files #include

Jan 29, 2013

Compile threshold.cc in NS2


In ns2, if you want to calculate the receiving power threshold of a node, you may want to use threshold tool which has been integrated in ns2 source code.

I don`t know why the threshold.cc is not compiled in the new version of ns2 like ns-allinone-2.35. So we have to do it by ourselves. In ubuntu, if you try to do "gcc threshold.cc", you will get an error message of "<iostream.h>".

So, we replace this line "#include<iostream.h>" by

#include<iostream>

#include<cstring>

using namespace std;


Then, compile it with g++,

g++ threshold.cc -o threshold

Dec 15, 2012

E: Internal Error, No file name for libssl1.0.0


The problem of libssl1.0.0 in Ubuntu 12.04 is "E: Internal Error, No file name for libssl1.0.0". So we can type:

sudo apt-get update

sudo apt-get clean

sudo apt-get install -fy

sudo dpkg -i /var/cache/apt/archives/*.deb

sudo dpkg --configure -a

sudo apt-get install -fy

sudo apt-get dist-upgrade

This method could solve the problem.

Nov 25, 2012

Ubuntu login from GUI and command line


Switch to command prompt: Ctrl + F1

Switch to GUI: Ctrl + F7

Command line to start GUI: sudo lightdm

Nov 11, 2012

Programming on Tinyos


Installation (a simple way)

1) deb http://tinyos.stanford.edu/tinyos/dists/ubuntu natty main

2) sudo apt-get update

3) sudo apt-get install tinyos

4) sudo apt-get install tinyos-2.1.1

5) Add the following line to your ~/.bashrc or ~/.profile file in your home directory to set up the environment for TinyOS development at login

#Sourcing the tinyos environment variable setup script

source /opt/tinyos-2.1.1/tinyos.sh

Oct 3, 2012

How to decompress multiple files on Linux


To unzip multiple zipped .zip files:

for file in *.zip; do unzip "${file}"; done

To unzip multiple zipped .gz files;

gunzip *.gz

To unzip multiple zipped .bz2 files;

bunzip2 *.bz2

To extract multiple .tar.gz files;

for file in *.tar.gz; do tar zxf "${file}"; done

To extract multiple .tar.bz2 files;

for file in *.tar.bz2; do tar jxf "${file}"; done

Aug 7, 2012

Command line to check the version


We can use this command to check whether the linux is 32 bits or 64 bits:

uname -m

if the output is i686, then it is 32 bits;

if the output is x86_64, then it is 64 bits.

Jun 2, 2012

Compile java files in all subfolders


On Windows...

Firstly create a batch file as complie.bat. Write these lines in that

for /r %%a in (*.java) do ( javac "%%a" )

now execute.

On Linux....

javac $(find ./rootdir/* | grep .java)

Jan 9, 2012

Record video in Ubuntu


In Ubuntu, I use XvidCap to record video on the screen. The package link is https://launchpad.net/ubuntu/natty/+package/xvidcap.

One of the most useful features of XvidCap is that it allows to select the recording area instead of the whole screen. And it also supports to output the video in MPEG format.

You may need to convert it to other video format, such as WMV, ASF, MOV and some for ipod or iphone. Since I am working on Mac OS, I recommend a free software which is called iSkysoft iMedia Converter. Actually, there is a video teaching you how to crack, http://www.youtube.com/watch?v=cLo-zuMxSNM.

Hopefully, these two softwares are helpful to you.

Jan 4, 2012

Set nodes` color in NS2 simulation program


This is a pretty tricky way to hit the target. And we can change the color at any time.


set ns [new Simulator]

set node [$ns node 0]

$ns at 0.0 "$node color red"

$ns at 1.0 "$node color blue"

One NS2 old trace format analysis


After NS2 simulations are finished, someone may need to analyze the trace file which is output by TCL program. I got the trace file format which is like this

"s 38.212991274 _2_ MAC --- 86 MYTYPE 178 [13a 3 2 800] ------- [2:0 3:0 30 3]"

"s 38.418136390 _3_ AGT --- 89 MYTYPE 100 [0 0 0 0] ------- [3:0 2:0 32 0]"


The first field is the event type, whose value can be s (send), r (receive), d (drop) or f (forward).

The second field the time this event happens.

The third field records the id of the node, on which this event takes place.

The fourth field shows the layer where this event happens. Its possible value may be one of the following four: AGT (agent), RTR (router), IFQ (interface queue), and MAC (mac).

The fifth field is normally a short broken line, which is reserved for special events. For example, when collision occurs, the broken line is replaced with COL.

The sixth field is the global sequence number for this packet, which is the integer number used to identify this packet in the whole network and distinguish it from others. Sequence number is only available for data packets and not allocated for control packets, like RTS/CTS/ACK and SYNC packets in S-MAC (using a zero instead).

The seventh field is the packet type. The actual value is determined by the application or MAC layer, which creates this packet. For example, cbr represents that it is a data packet generated by a CBR traffic source.

The eighth field is the packet size in bytes.

Since I use AODV routing protocol, the ninth field is AODV trace information including three numbers in brackets concerns MAC layer information. Usually, there will be four numbers in the brackets. Its format is like "[0x%x %d [%d %d] %f] (%s)" 1)| hexadecimal | Type | 2)| int | Hop Count | 3)|int | Destination | Destination Sequence Number | 4)|double | Lifetime | 5)|string | Operation (REPLY, ERROR, HELLO) |

The tenth field is IP trace info including | Source IP Address:Source Port Number | Destination IP Address:Destination Port Number | TTL Value | Next Hop Address, If Any |

Jan 2, 2012

Install ns2.34 on Ubuntu 10.04


1) Download ns2.34 allinone package from http://sourceforge.net/projects/nsnam/files%2Fallinone%2Fns-allinone-2.34/

2) Uncompress to your own directory by using command "tar -zvxf ns-allinone-2.34.tar.gz"

3) Install some development files,

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo apt-get install build-essential

sudo apt-get install libc6-dev g++ gcc-4.3

sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev

sudo apt-get install autoconf automake libxmu-dev libxmu-headers

4) Then,


$cd ns-allinone.2.34/

$./install

5) If got "otcl-1.13 make failed! Exiting" error,
i)edit the configure.in file in otcl-1.13, Line77 SHLIB_LD="ld -shared" -> SHLIB_LD="gcc -shared"
ii)edit the configure file in otcl-1.13, Line6304 SHLIB_LD="ld -shared" -> SHLIB_LD="gcc -shared"

6) Edit otcl-1.13/Makefile.in,

CC= @CC@ -> CC= gcc-4.3

7) Then,

$cd ns-allinone.2.34/

$./install

8) If got an error like

"`.gnu.linkonce.t._ZN11taskPending10taskStatusEh' referenced in section `.rodata' of wpan/p802_15_4mac.o: defined in discarded section `.gnu.linkonce.t._ZN11taskPending10taskStatusEh' of wpan/p802_15_4mac.o
collect2: ld returned 1 exit status
make: *** [ns] error 1"

, that is because you are using gcc3.3 to compile it. And you have to change gcc compiler version to gcc4 or above.

9) Then, it should work. Finally, dont forget to modify .bashrc file to add environment variables.

export PATH=$PATH:/YOURDIR/ns-allinone-2.34/bin:/YOURDIR/ns-allinone-2.34/tcl8.4.18/unix:/YOURDIR/ns-allinone-2.34/tk8.4.18/unix

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/YOURDIR/ns-allinone-2.34/otcl-1.13:/YOURDIR/ns-allinone-2.34/lib

export TCL_LIBRARY=$TCL_LIBRARY:/YOURDIR/ns-allinone-2.34/tcl8.4.18/library

May 19, 2011

How to record command line output

if we want to record the output in Linux command line, we could use "script" command.


script [-a] [-f] [-q] [-t] + file name


-a


Append the output to file or typescript retaining the prior contents.


-f


Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can supervise real-time what is being done using `cat foo'.


-q


Be quiet.


-t


Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays.


To exit the recording, we need to use "ctrl + d".


For example, we record the command line output to a log file whose name is "MyRecord".


$ script MyRecord.log


Then it will begin to record all the information displayed by command line. Finally, "ctrl + d" will exit and it will show "Script done, file is MyRecord.log"