Tuesday, 29 May 2012

Login as Root in Ubuntu 11.04

Type the command below to create a new password for the root user

$ sudo passwd root

Monday, 28 May 2012

Writing to expansion pins on Telos B

#include "contiki.h"
#include "httpd-simple.h"
#include "net/rpl/rpl.h"
#include "dev/leds.h"
#include <stdio.h>
#include <io.h>

#define P23_OUT() P2DIR |= BV(3)
#define P23_IN() P2DIR &= ~BV(3)
#define P23_SEL() P2SEL &= ~BV(3)
#define P23_IS_1  (P2OUT & BV(3))
#define P23_WAIT_FOR_1() do{}while (!P23_IS_1)
#define P23_IS_0  (P2OUT & ~BV(3))
#define P23_WAIT_FOR_0() do{}while (!P23_IS_0)
#define P23_1() P2OUT |= BV(3)
#define P23_0() P2OUT &= ~BV(3)


static uint8_t toggle;
PROCESS(web_sense_process, "Sense Web Demo");
PROCESS(webserver_nogui_process, "Web server");
PROCESS_THREAD(webserver_nogui_process, ev, data)
{
  PROCESS_BEGIN();
  httpd_init();
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    httpd_appcall(data);
  }
  PROCESS_END();
}
AUTOSTART_PROCESSES(&web_sense_process,&webserver_nogui_process);
/*---------------------------------------------------------------------------*/
static const char *TOP = "<html><head><title>Contiki Web Sense</title></head><body>\n";
static const char *BOTTOM = "</body></html>\n";
/*---------------------------------------------------------------------------*/
/* Only one single request at time */
static char buf[256];
static int blen;
#define ADD(...) do {                                                   \
    blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__);      \
  } while(0)
static
PT_THREAD(send_values(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);
 // SEND_STRING(&s->sout, TOP);
  if(strncmp(s->filename, "/index", 6) == 0 ||
     s->filename[1] == '\0') {
  } else if(s->filename[1] == '0') {
    /* Turn off leds */ 
    toggle=0;
    //leds_off(LEDS_ALL);
   //  SEND_STRING(&s->sout, "Turned off leds!");
  } else if(s->filename[1] == '1') {
    /* Turn on leds */ 
    toggle=1;
    //leds_on(LEDS_ALL);
   // SEND_STRING(&s->sout, "Turned on leds!");
  }
 
  //SEND_STRING(&s->sout, BOTTOM);
  PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
httpd_simple_script_t
httpd_simple_get_script(const char *name)
{
  return send_values;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(web_sense_process, ev, data)
{
  static struct etimer timer;
  PROCESS_BEGIN();
  etimer_set(&timer, CLOCK_SECOND * 2);
  P23_OUT();
  P23_SEL();
 

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
    etimer_reset(&timer);
    if(toggle==0)
    {  
          P23_1();  
          rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));     
    }
    else
    {
          P23_0();   
          rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
    }
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/

Watchdog for Contiki

#include "contiki.h"
#include "httpd-simple.h"
#include "dev/sht11-sensor.h"
#include "dev/light-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
#include "watchdog.h"

PROCESS(web_sense_process, "Sense Web Demo");
PROCESS(webserver_nogui_process, "Web server");
PROCESS_THREAD(webserver_nogui_process, ev, data)
{
  PROCESS_BEGIN();

  httpd_init();
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    httpd_appcall(data);
  }

  PROCESS_END();
}


AUTOSTART_PROCESSES(&web_sense_process,&webserver_nogui_process);


/*---------------------------------------------------------------------------*/
static int
get_light(void)
{
  return 10 * light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC) / 7;
}
/*---------------------------------------------------------------------------*/
static int
get_temp(void)
{
  return sht11_sensor.value(SHT11_SENSOR_TEMP);
}
/*---------------------------------------------------------------------------*/
/* Only one single request at time */
static char buf[256];
static int blen;
#define ADD(...) do {                                                   \
    blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__);      \
  } while(0)

static
PT_THREAD(send_values(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);

  if(strncmp(s->filename, "/index", 6) == 0 ||
     s->filename[1] == '\0') {
    /* Default page: show latest sensor values as text (does not
       require Internet connection to Google for charts). */
    blen = 0;
    ADD("%u\n"
        "%u",
        get_light(), get_temp());
    SEND_STRING(&s->sout, buf);

  }
  PSOCK_END(&s->sout);

}
/*---------------------------------------------------------------------------*/
httpd_simple_script_t
httpd_simple_get_script(const char *name)
{
  return send_values;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(web_sense_process, ev, data)
{
  static struct etimer timer;
 
  PROCESS_BEGIN();

  etimer_set(&timer, CLOCK_SECOND * 3000);
  SENSORS_ACTIVATE(light_sensor);
  SENSORS_ACTIVATE(sht11_sensor);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
    if(etimer_expired(&timer)) {                    // reboot the node        

         watchdog_start();
         while (1) {leds_on(LEDS_RED);};
    }
  }

  PROCESS_END();
}

MIB520 Driver

1. Download UISP from here
2. Goto the downloaded location from the shell and issue the following commands,
      # tar -xvzf uisp.tar.gz
      # cd uisp
      # ./bootstrap
      # ./configure
      # make
      # sudo make install

3. Try
      # make TARGET=micaz blink.upload PORT=/dev/ttyUSB0

     By the way, all FTDI devices now supported in Ubuntu 11.10, kernel 3.0.0-19.

Burn a mote (contiki tinyOS micaz telosb)

TinyOS

make micaz install mib510,/dev/ttyUSB0  // connect to PC via MIB520
make telosb install, /dev/ttyUSB0              // connect to PC directly
make intelmote2 install openocd                // connect to PC via ARM-USB-TINY cable  

         
ContikiOS

make TARGET=micaz blink.upload PORT=/dev/ttyUSB0   //  connect to PC via MIB520
make TARGET= telosb blink.upload                                     //   connect to PC directly

In our lab, many heterogeneous motes form a network.

The good thing is the network is powful for end-users.
The bad thing is so many heterogeneous burning commands to remember for me.

Cannot open /dev/ttyUSB0: No such file or directory.

Go to /dev directory


Unplug the USB device, check ttyUSB files.
Replug the USB device, new ttyUSB<number> file is created automatically.


On a UNIX system, everything is a fileif something is not a file, it is a process.

USB communications for sky-shell-exec

Send commands to USB port using echo:


  echo "make login" > /dev/ttyUSB0


Read data from serial port using cat :


  cat /dev/ttyUSB0


  cat /dev/ttyUSB0 > file.txt

Friday, 25 May 2012

install curl module for PHP

Down Curl module for PHP:

  sudo apt-get install curl libcurl3 libcurl3-dev php5-curl


Restart Apache:

  sudo /etc/init.d/apache2 restart

Monday, 21 May 2012

Javapath setting for xubuntos-2.1-vm


just input following command at terminal:

  export CLASSPATH=.:/opt/tinyos-2.1.0/support/sdk/java/tinyos.jar

//Choose right TinyOS version!


xubuntos-2.1-vm does not set up Javapath automatically,User should set up Javapath manully.


Frankly, I do not know what the command is. Anyway, I just copy and paste it every time.

Friday, 18 May 2012

What is callback function

There is a examples of callback function.


typedef struct
{
    int a;
    int b;
    int (* callback)(int a,int b);
}struct_b;


/*Assume that this is ur library i,e lower level function*/
int mylib(struct_b );


/*Assume that this ur higher level function*/
int add(int a,int b);


void main(void)
{
    int a,b;
    struct_b st_b;


/*Here u r passing higher level function to lower level function through structure*/
    st_b.callback = add;
    st_b.a = 10;
    st_b.b = 12;
    printf(“sum of a and b is = %d”,mylib(st_b));
}


/*This is ur higher level function definition*/
int add(int a,int b)
{
    return a+b;
}
int mylib(struct_b st_b)
{


/*Here u r calling higher level function with the help of call back function*/
    return st_b.callback(st_b.a,st_b.b);
}

Making Contiki and TinyOS interoperate.

Physical layer

The following  parameters should be the same between Contiki OS and Tiny OS.

1, IEEE PAN ID
2, Radio Channel


MAC Layer

For Contiki, disable RDC.
Use packetbuf_dataptr(void) to get pure IEEE 802.15.4 packet.

Other Layers

Then, I put my ideals in here!

BTW, I can not find the configuration file in Tiny OS, so I try to make Contiki OS adapt to Tiny OS.