Difference between revisions of "Preet's Relay Controller Project"

From Embedded Systems Learning Academy
Jump to: navigation, search
(RN-XV Initialization)
(RN-XV Initialization)
Line 75: Line 75:
  
 
<BR/>
 
<BR/>
'''Setup IP & Associate'''
+
==== Setup IP & Associate ====
 
RN-XV can be commanded through it's UART interface to initialize it:
 
RN-XV can be commanded through it's UART interface to initialize it:
 
*  Enter command mode: "$$$"
 
*  Enter command mode: "$$$"
Line 90: Line 90:
 
*:  "join <Your_SSID>"
 
*:  "join <Your_SSID>"
  
<BR/>
+
==== Setup TCP/IP Server ====
'''Setup TCP/IP Server'''
 
 
*  Enter command mode: "$$$"
 
*  Enter command mode: "$$$"
 
*  Use TCP/IP Protocol: "set ip protocol 1"
 
*  Use TCP/IP Protocol: "set ip protocol 1"

Revision as of 19:39, 21 September 2012

This article is under construction. You may have found it because you're lucky but it's not linked anywhere, and is not complete.

Overview

The motivation of this project is to control a relay board over the network (or even over the internet). More specifically, this project is an application of the relay control in the form of a sprinkler control system (SCS). Overall, the following functionality is targeted:

  • Schedule a run-time
  • Select days to water
  • Select run-times of each sprinkler
  • Turn System On or Off
  • Set 'Rainy days' (number of days to skip a scheduled run)

The extended functionality is the Web GUI*. The Web interface (WI) not only allows to control SCS, but also view the logs in a graphical way. For example, WI can request daily water-times from the SCS and plot a bar-graph to show the user the water history.



Features

Commandline Interface

The command-line interface is an intuitive interface that is a self-documented piece of SCS. To begin using the interface, all it takes is to connect SCS to a USB port on a computer, open a COM Port at 38400bps and type "help". Below are some screenshots of the command-line interface. TODO: Attach screenshots

SCS specific commands

To begin, "relay help" command can be issued to see the command-set. To schedule the SCS to water plants everyday, the following commands can be issued:

  • relay schedule 18:00
  • relay waterday everyday
  • relay minutes 1 1 1 1 2 2 2 2 3 3 3
  • relay power on

TCP/IP Commands

The commandline interface is the same over TCP/IP. All it takes is to open up a TCP/IP port of SCS and use the same commands. SCS uses fixed port number: 5555 of TCP/IP. To open command-line interface over TCP/IP, SCS IP needs to be first determined and then the Hercules* utility can be used to interface with SCS. TODO: Attach picture

Web-based Controls

SCS exposes its interface over a TCP/IP connection. It provides a simple, human readable command-line interface. This command-line interface is encapsulated in the WI that provides an even simpler interface to an end-user. The idea is that a person without any knowledge of the controller should be able to interact with the system.

Logs

There are several forms of logs that get saved in the file system accessible by FAT* library. The SCS software saves the log in the on-board 1Mb SPI flash memory. This provides capability to save data without relying on an external SD card.

Hourly Sensor Logs

Every hour, temperature and light sensor value is logged into a file in the format:
Timestamp, Temperature in Fahrenheit, Light Percent
9/16/2014, 76.25, 10

Nightly Logs

Every night, a log message saves the number of minutes SCS turned on relays in a 24-hour period. This serves as a daily log of the number of minutes of plants were watered.

Debugging Logs

Debugging and informational logs also get saved on demand or if the log-buffer becomes full. This can open the gate for long-term testing and debugging to ensure that the board is operating as expected.



Implementation

Hardware

In the hardware level, the following components form SCS:

  • SJ-One Board
  • RN-XV Wifi module
  • Relays attached to GPIOs

The wifi module is a simple UART based TCP/IP solution. The SCS software initializes RN-XV, sets up a TCP/IP port to listen to, and simply waits for data or command from UART and responds back to the command.

Embedded Software

FreeRTOS template project was used to provide the software framework. This software framework was extended by adding more command-line handlers.

RN-XV Initialization

The RN-XV Wifi module is initialized to obtain an IP from DHCP, and then act as a TCP/IP server on port 5555. The basic operation of RN-XV is as follows:

  • RN-XV boots with UART speed of 9600bps
  • To issue commands, send "$$$" preceded by 250ms of UART inactivity followed by another 250ms of UART inactivity.
  • To exit command mode, issue "exit\r\n"
  • If RN-XV is not in command mode, all data received over UART is treated as data for an established connection.

The following steps illustrate RN-XV initialization:


Setup IP & Associate

RN-XV can be commanded through it's UART interface to initialize it:

  • Enter command mode: "$$$"
  • Enable DHCP: "set ip dhcp 1"
  • Set SSID: "set wlan ssid <Your_SSID>"
  • Set WPA2 Security: "set wlan auth 4"
  • Set WPA2 Passphrase: "set wlan phrase <My_Sec_Phrase>"
  • Set Channel: "set wlan channel 0"
  • Use any channel: "set wlan mask 0x1FFF"
  • Save and reboot:
    "save"
    "reboot"
  • Finally, join your wireless router:
    "join <Your_SSID>"

Setup TCP/IP Server

  • Enter command mode: "$$$"
  • Use TCP/IP Protocol: "set ip protocol 1"
  • Use your port: "set ip local port 5555"
  • Save and reboot:
    "save"
    "reboot"

After performing these steps, RN-XV should have obtained an IP address and it is ready to communicate over TCP/IP port 5555.

Front-End Web Interface

While the SCS software can interact with a command-line interface, WI encapsulates commands with simple buttons. This provides a non-technical person the capability to control the system.



Testing

The testing was performed manually by verifying the command and expected output. The steps were:

  • Program the software
  • Test each command through UART interface
  • Test each command through Wifi interface



Conclusion

A very low powered relay system was developed that has capability to be controlled over the Internet. This solution is a completely encapsulated system that can be controlled by a USB/UART interface, or over a TCP/IP interface.