Interfacing a power relay to a WiSense node

I got a board with eight power relays from a friend. These relays (26-12-1CKE) are manufactured by O/E/N India in Bangalore.  The board has a relay driver IC (ULN2803A from TI). This IC can drive up to 8 relays. This IC  allows a low voltage GPIO pin to safely control an inductive load such as a power relay. The relays require 12 V supply.

uln2803

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

I added a command “dioc” to the gateway application. This command can be used to set the output (on any node in an WiSense mesh network) of any pin (configured as digital out) to 0 or 1. This command takes 4 parameters.

  • The short address of the remote node
  • The port id (1 – 4)
  • The pin number (0 – 7)
  • Value ( 0 or 1).

Examples:

  • To set P2.1 on node (with short address 0x5) to 1, run “./gw.exe  /dev/ttyS10   dioc   0x5   2   1   1”.
  • To set P4.3 on node (with short address 0x7) to 0, run “./gw.exe  /dev/ttyS10  dioc   0x7   4   3   0

The application payload format of the message sent to specified remote node is given below. This message requests the app layer on the intended recipient to set digital output P2.6 to 0. All messages exchanged between WiSense nodes and external entities such as the gateway app consist of a 1 byte DIS message type followed by one more TLV (type-length-value) structures. The type and length fields are single byte fields. All TLV related macros are defined in the file “dis/inc/dis.h”. In the message below, you can see one top level container TLV (DIS_TLV_TYPE_DIGITAL_IO) which in turn contains three simple TLVs (DIGITAL_IO_PORT, DIGITAL_IO_PIN and DIGITAL_IO_VAL).

  • Byte 0 (DIS message type): 0xb (DIS_MSG_TYPE_CTRL_DIGITAL_IO)
  • Byte 1 (TLV type field):  0x34  (DIS_TLV_TYPE_DIGITAL_IO)
  • Byte 2 (TLV length field): 0x9  
  • Byte 3 (TLV type field): 0x31   (DIS_TLV_TYPE_DIGITAL_IO_PORT)
  • Byte 4 (TLV length field): 0x1  
  • Byte 5 (TLV value field): 0x2  (Port P2)
  • Byte 6 (TLV type field): 0x32  (DIS_TLV_TYPE_DIGITAL_IO_PIN)
  • Byte 7 (TLV length field):  0x1
  • Byte 8 (TLV value field): 0x6  (Pin number 6)
  • Byte 9 (TLV type field): 0x33  (DIS_TLV_TYPE_DIGITAL_IO_VAL)
  • Byte 10 (TLV length field) : 0x1  
  • Byte 11 (TLV value field): 0x0  (Set digital output to 0x0)

The test setup had one coordinator node connected to a laptop running the small script shown below. The network had one more node (an FFD) with port p2.1 configured as digital output and hooked up to one of inputs of the ULN2803A  on the relay board. This script toggled the digital output p2.1 on the FFD (address 0x2) every second. The relay gated AC power to a CFL bulb.

  • while  [ 1 ]
  •      ./gw.exe /dev/ttyS2  dioc  0x2   2   1   0
  •      sleep 1
  •      ./gw.exe /dev/ttyS2  dioc  0x2   2   1   1
  •      sleep 1
  • done

The coordinator (and the laptop) were in one room and the FFD/relay/bulb were in another room.

Here’s a pic of the setup.

ffd_relay_cntrl.

References:

Posted on February 2, 2015, in Uncategorized. Bookmark the permalink. 1 Comment.

  1. Wonderful! Now people will get a real sense of what’s possible in IoT and home automation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: