Changes between Version 6 and Version 7 of wade/embedded/arduino/example/example_7_1_ethernet_web_admin


Ignore:
Timestamp:
Apr 28, 2010, 5:16:11 PM (14 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • wade/embedded/arduino/example/example_7_1_ethernet_web_admin

    v6 v7  
    88
    99/*
    10  * Web Admin 透過 web service 提供網頁監控功能。
     10 * Web Admin 透過 web service 提供網頁監控功能。透過 GET 送命令取回 http 資料。
    1111 * 接法:
     12 * digital pin2:DC SWITCH
     13 *         pin10:W5100
     14 *         pin11:W5100
     15 *         pin12:W5100
     16 *         pin13:W5100(SPI)
    1217 * analog pin1:CT sersor
    13  *
     18 * GET 命令:
     19 *         b=00:第一行傳現在裝置狀態
     20 *         b=01:DC on
     21 *         b=02:DC off
     22 *         b=03:AC on
     23 *         b=04:AC off
    1424 */
    1525
    1626#include <Ethernet.h>
     27#include <NewSoftSerial.h>
    1728//#include <string.h>
    1829
    19 byte mac[] = {
    20   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    21 byte ip[] = {
    22   192, 168, 1, 240 };
     30// W5100 configuration
     31byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
     32byte ip[] = { 140, 110, 138, 240 };
     33Server server(80);
    2334
    24 Server server(80);
     35// set pin 9 as RX
     36uint8_t ssRX = 6;
     37// set pin 10 as TX
     38uint8_t ssTX = 7;
     39// enable soft serial nss
     40NewSoftSerial nss(ssRX, ssTX);
     41
     42// initial
     43#define id 1           // device ID
     44#define DC_read 0
     45#define DC_control 2
     46#define AC_read 1
     47#define AC_control 3
     48int analog_val;        // analog value read from UART
    2549
    2650void setup()
     
    2953  server.begin();
    3054  Serial.begin(9600);
    31   pinMode(2, OUTPUT);
    32   pinMode(3, OUTPUT);
     55  nss.begin(9600);
     56  pinMode(DC_control, OUTPUT);
     57  pinMode(AC_control, OUTPUT);
     58  pinMode(6, OUTPUT);
     59  pinMode(7, OUTPUT);
    3360}
     61
     62
    3463
    3564void loop()
     
    5483          client.println("Content-Type: text/html");
    5584          client.println();
    56 
     85         
     86         
    5787          // output the value of each analog input pin
    58           for (int i = 0; i < 6; i++) {
    59             client.print("analog input ");
    60             client.print(i);
    61             client.print(" is ");
    62             client.print(analogRead(i));
    63             client.println("<br />");
    64           }
     88          //for (int i = 0; i < 6; i++) {
     89          client.print("DC VAL = ");
     90          //  client.print(i);
     91          //  client.print(" is ");
     92          client.print(analogRead(DC_read));
     93          client.println("<br />");
     94          client.print("AC VAL = ");
     95          client.print(analogRead(AC_read));
     96          client.println("<br />");
     97          //}
    6598          client.println("<form  method=get name=form>");
    66           client.println("<button name=b value=01 type=submit>01</button>");
    67           client.println("<button name=b value=02 type=submit>02</button>");
    68           client.println("<button name=b value=03 type=submit>03</button>");
    69           client.println("<button name=b value=04 type=submit>04</button>");           
     99          client.println("<button name=b value=01 type=submit>DC On</button>");
     100          client.println("<button name=b value=02 type=submit>DC Off</button><br />");
     101          client.println("<button name=b value=03 type=submit>AC On</button>");
     102          client.println("<button name=b value=04 type=submit>AC Off</button>");                 
    70103          client.println("</form>");
    71104          break;
     105         
    72106        }
    73107        if (c == '\n') {
     
    88122            command[i] = c;
    89123          }
     124          // send all status
     125          if (!strcmp(command, "00") )
     126          {
     127            client.print("ID="); client.print(id); client.print(",");
     128            client.print("DC_val="); client.print(analogRead(DC_read)); client.print(";");
     129            client.print("DC_control="); client.print(digitalRead(DC_control)); client.print(";");
     130            client.print("AC_val="); client.print(analogRead(AC_read)); client.print(";");
     131            client.print("AC_control="); client.print(digitalRead(AC_control)); client.println(";");
     132          }
     133          // DC control
    90134          if (!strcmp(command, "01") )
    91135          {
    92             Serial.println("high pin 2");
    93             digitalWrite(2, HIGH);
    94             delay(500);
    95             digitalWrite(2, LOW);
     136            //Serial.println("high pin 2");
     137            digitalWrite(DC_control, HIGH);
     138            //nss.print("A");
     139            //nss.print(byte(0x00));
    96140          }
    97141          if (!strcmp(command, "02") )
    98142          {
    99             Serial.println("high pin 3");
    100             digitalWrite(3, HIGH);
    101             delay(500);
    102             digitalWrite(3, LOW);
     143            //Serial.println("low pin 3");
     144            digitalWrite(DC_control, LOW);
     145            //nss.print("A");
     146            //nss.print(byte(0x02));
     147          }
     148          // AC control
     149          if (!strcmp(command, "03") )
     150          {
     151            //Serial.println("high pin 2");
     152            digitalWrite(AC_control, HIGH);
     153            //nss.print("A");
     154            //nss.print(byte(0x00));
     155          }
     156          if (!strcmp(command, "04") )
     157          {
     158            //Serial.println("low pin 3");
     159            digitalWrite(AC_control, LOW);
     160            //nss.print("A");
     161            //nss.print(byte(0x02));
    103162          }
    104163        }
     
    108167    delay(1);
    109168    client.stop();
     169   
     170    // read from XBee
     171    /*
     172    if (nss.available())
     173    {
     174      analog_val = nss.read();
     175      Serial.print("I read analog_val ");
     176      Serial.println(analog_val);
     177    }
     178    */
    110179  }
    111180}
     181
    112182}}}