sábado, 24 de novembro de 2012

Using Arduino as WebService to provide RPC(Remote Procedure Call) on devices attached to serial ports

1. Introduction


This project, WebServiceSerialRPC, uses Arduino and Ethernet Shield to implement a WebService to provide RPC (Remote Procedure Call) to a device attached to serial port. You can attach serial  port to a Cisco Router console port RS-232.


2. Project

2.1. Deploy Diagram


//
// +--------------+ Cosole DB-9     Serial +-----------------+
// |              | Port RS232        Port | Arduino with    |
// | Cisco Router |---o <- - - - - --> o---| Ethernet Shield |
// |              |                        |                 |
// +--------------+                        +-----------------+
//                                                  | HTTP
//                                                  | Port
//                                                  o
//                                                  :
//                                                  :
// +-+       Ethernet Network                       :                  +-+
// | +-----------+----------------------------------+------------------+ |
// +-+           :                                                     +-+
//               :
//               o
//               |
//   +--------------+
// +-+ Client Device|
// +-+ HTTP Request |
//   +--------------+


2.2. Sequence Diagram


//  Client Device        Arduino           Cisco Router
//  -------------     -------------        -------------
//        | http request    |                     |
//        |---------------->|                     |
//        |                 |  send command       |
//        |                 |-------------------->|
//        |                 |   buffer read #1    |
//        |                 |<------------------- |
//        |                 |         :           |
//        |                 |<------------------- |
//        | http response   |   buffer read #n    |
//        |<----------------|                     |
//        |                 |                     |
//        |                 |                     |



2.3. State Chart Diagram


//      o
//      | startup
//      V
//  +---------+      HTTP
//  |         |    response
//  |  idle   |<---------------+
//  |         |                |
//  +---------+                |
//       |                     |
//       | HTTP request        |   +----+
//       V                     |   V    | buffer
//  +---------+   command  +---------+  | read
//  |         |  line sent |         |  |
//  | prompt  |----------->|executing|--+
//  |         |            |         |
//  +---------+            +---------+



3. Source Code

// ////////////////////////////////////////////////////////////////////////////
//        file: WebServiceSerialRPC.ino
// description: This project, WebServiceSerialRPC, uses Arduino and    Ethernet
//              Shield to implement a WebService to provide RPC (Remote Procedure
//              Call) to a device attached to serial port. You can attach serial 
//              port to a Cisco Router console port RS-232
//      author: Josemar Furegatti de Abreu Silva
// author-blog: http://josemarfuregattideabreusilva.blogspot.com.br/
// requirement: (Arduino Uno or Arduino Duemilanove) and Arduino Ethernet Shield
// Includes
#include <SPI.h>
#include <Ethernet.h>

4. References