Thursday, May 31, 2012

Networking concepts


Hub, Repeater, Switch, Bridge, Router and Gateway

   Major differences between different networking devices are mentioned in this table.



Network Devices
OSI layer corresponds to the Device
Functions
Hub
Physical
Multiport repeater.
Any electrical signal that comes into one port, goes out of all other ports.
Does not examine or manage traffic.
Repeater
Physical
Regenerates the signal.
Connects two segments of a network cable.
Extends physical length of network.
Is a re-generator not an amplifier.
Active hubs.
Switch
Data link
Connects n/w segments or n/w devices.
Is a multipoint network bridge(bridge with numerous o/p ports).
Process and routes data to the intended receiver.
Intelligent than hub.
Multilayer switch works on Data link and Network layer.
Reduces traffic and divide the collision domain into segments.
Uses MAC address for communication.
Bridge
Data link
A combination of hardware and software to link two similar networks.
Divides a large network to smaller segments.
Very much alike switch.
Does data filtering and separating the collision domain like switch.
Slower compared to switch since it uses s/w for switching.
Controls congestion and isolation.
Uses MAC address for communication.
Router
Network
Route data packets between different networks of same type.
Can connect networks with different architecture like Token Ring and Ethernet.
Cannot connect networks of different protocols like TCP/IP and IPX/SPX.
Controls both collision domains and broadcast domains.
Uses IP address for communication.
Ability to identify best route for the packet to travel using a routing table.
Gateway
Application, Network, Session
Interconnects networks with different network protocol technologies by performing the required protocol conversions.
Very intelligent device
Works at network layer and above, but mostly work at application layer.
Mostly it is a software installed in router.

Tuesday, May 29, 2012

Multiple sensors interfacing to Telosb through I2C connection

   Here i have interfaced two sensors, accelerometer and temperature sensor with Telosb mote using parallel I2C connection. Zigbee part is also integrated with the program.

Connection

TMP102 GND   -> TELOSB 9 pin (GND)
TMP102 VCC    -> TELOSB 1 pin (VCC)
TMP102 SDA    -> TELOSB 8 pin (SDA)
TMP102 SCL    -> TELOSB 6 pin (SCL)
TMP102 ADD0 -> TELOSB 9 pin (GND)
TMP102 ALT    -> Left unconnected

ADXL345 GND -> TELOSB 9 pin (GND)
ADXL345 VCC  -> TELOSB 1 pin (VCC)
ADXL345 CS     -> TELOSB 1 pin (VCC)
ADXL345 SDA  -> TELOSB 8 pin (SDA)
ADXL345 SCL  -> TELOSB 6 pin  (SCL)
ADXL345 SDO  -> TELOSB 9 pin (GND)


The circuit i created for interfacing the sensors with Telosb is given below. I have used an intermediate interfacing board for connection.





Program

   Transmitter Program

      Programming is done with Nesc in TinyOS. Four main files are here I2CAPPC.nc, , I2CC.nc, I2CRadio.h and Makefile.


I2CAPPC.nc
#include "I2CRadio.h"

configuration I2CAppC{
}

implementation {
   components MainC, I2CC as App;
   App.Boot -> MainC;

   components LedsC;
   App.Leds -> LedsC;

   components new TimerMilliC() as I2CTimer;
   App.I2CTimer -> I2CTimer;

   components new ADXL345C();
   App.axis -> ADXL345C.XYZ;
   App.AccelControl -> ADXL345C.SplitControl;

   components new SimpleTMP102C();
   App.Temp -> SimpleTMP102C.Read;

   components new AMSenderC(AM_I2C);
   App.Packet -> AMSenderC;
   App.AMPacket -> AMSenderC;
   App.AMSend -> AMSenderC;

   components ActiveMessageC;
   App.AMControl -> ActiveMessageC.SplitControl;

   components new AMReceiverC(AM_I2C);
   App.Receive -> AMReceiverC;
}

I2CAPPC.nc
#include "printf.h"
#include "ADXL345.h"
module I2CC {
   uses {
      interface Boot;
      interface Leds;
      interface Timer as I2CTimer;
      interface Read as axis;
      interface SplitControl as AccelControl;
      interface Read as Temp;

      interface Packet;
      interface AMPacket;
      interface AMSend;
      interface SplitControl as AMControl;

      interface Receive;
   }
}

implementation {

   bool busy = FALSE;
   message_t pkt;
   uint16_t counter = 0;

   nx_uint16_t X;
   nx_uint16_t Y;
   nx_uint16_t Z;
   nx_uint16_t Tem;

   event void Boot.booted() {
      call AccelControl.start();
   }

   event void AccelControl.startDone(error_t err) {
      printf("\n\n------Accelerometer started-----\n\n");
      call I2CTimer.startPeriodic(1000);
   }

   event void AccelControl.stopDone(error_t err) {
   }

   event void I2CTimer.fired() {
      counter++;
      call Leds.led0Toggle();
      call axis.read();
   }

   event void axis.readDone(error_t result, adxl345_readxyt_t data) {
      if (result == SUCCESS) {
         X = data.x_axis;
         Y = data.y_axis;
         Z = data.z_axis;
         printf("\nX [%d] Y [%d] Z [%d]\n",X,Y,Z);
         call Temp.read();
      }
      else printf("Error in reading Accelerometer sensor\n");
   }

   event void Temp.readDone(error_t err, uint16_t temp) {
      if (err == SUCCESS) {
         call Leds.led1Toggle();
         temp=temp*6.25;
Tem=temp;
         printf("Temperature = %d.%d\n\n",temp/100, temp%100);
         printfflush();
         call AMControl.start();
      }
      //***************AM Part********************
      else printf("Error in reading Temperature sensor\n");
   }
   
   event void AMControl.startDone(error_t res) {
      if (res == SUCCESS) {
 //        printf("****AM STARTED****\n");
         if (!busy) {
            I2CRadioMsg* i2cpkt=(I2CRadioMsg*)(call Packet.getPayload(&pkt,sizeof(I2CRadioMsg)));
            i2cpkt -> counter = counter;
            i2cpkt -> xaxis = X;
            i2cpkt -> yaxis = Y;
            i2cpkt -> zaxis = Z;
            i2cpkt -> temp = Tem;
            if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(I2CRadioMsg)) == SUCCESS) {
               busy = TRUE;
               call Leds.led2Toggle();
            }
         }
      }
      else {
         call AMControl.start();
      }
   }

   event void AMControl.stopDone(error_t error) {
   }

   event void AMSend.sendDone(message_t* msg, error_t error) {
      if (&pkt == msg) busy=FALSE;
      call AMControl.stop();
   }

   event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
   }
}

I2CRadio.h
#ifndef I2CRADIO_H
#define I2CRADIO_H

typedef nx_struct I2CRadioMsg {
   nx_uint16_t counter;
   nx_uint16_t xaxis;
   nx_uint16_t yaxis;
   nx_uint16_t zaxis;  
   nx_uint16_t temp;  
}I2CRadioMsg;

enum {
   AM_I2C = 7,
};
#endif

Makefile
COMPONENT=I2CAppC
CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -I$(TOSDIR)/chips/adxl345
CFLAGS += -I$(TOSDIR)/chips/tmp102

include $(MAKERULES)