Go Down

Topic: Arduino Mega Ethernet Shield + SainSmart 16 Relay Board + VS2013 ASP NET  (Read 1 time) previous topic - next topic

xklownx

I have an Arduino Mega connected via Ethernet cable I also have a Sain Smart 16 relay board connected via Ethernet cable. I have the Arduino talking to the relay board via Ethernet. I now need to implement an ASP NET APP to control the relay board by talking to the Arduino. I cannot find anything that gives a good example how to do this. Any help would be great. I provided my arduino code I just need some help in the direction of the ASP APP talking to the Arduino.
Code: [Select]
//address http://192.168.1.177:30000

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
IPAddress ip(192,168,1,177); // ip in lan
IPAddress gateway(192,168,1,1); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
IPAddress myserver(192,168,1,167);
EthernetServer server(30000); //server port
EthernetClient client;
String readString;


void setup(){

  
  Ethernet.begin(mac, ip, subnet, gateway);
  server.begin();
  //Serial.begin(9600);
}

void loop(){
  

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          //print to serial monitor for debuging
          //Serial.println(readString);  

           //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println("HTTP/1.1 204 ");
            client.println();
            client.println();  
          }
          else {
            //send new page
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println();

            client.println("<HTML>");
            client.println("<HEAD>");
            client.println("<TITLE>Web Server Test</TITLE>");
            client.println("</HEAD>");
            client.println("<BODY>");

            client.println("<H1></H1>");
            client.println("<p>Relay 1</p>");
            client.println("<p>--------</p>");
            client.println("<a href=\"/?R1on\" target=\"inlineframe\">ON</a>");
            client.println("<a href=\"/?R1off\" target=\"inlineframe\">OFF</a>");
            client.println("<p>--------</p>");
            client.println("<p>Relay 2</p>");
            client.println("<a href=\"/?R2on\" target=\"inlineframe\">ON</a>");
            client.println("<a href=\"/?R2off\" target=\"inlineframe\">OFF</a>");
            
            client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
            client.println("</IFRAME>");

            client.println("</BODY>");
            client.println("</HTML>");
          }

          delay(1);
          //stopping client
          client.stop();

          if(readString.indexOf("R1on") >0)
          {
            sendGETR1OFF()
          }
          if(readString.indexOf("R1off") >0)
          {
            sendGETR1ON()
          }
          if(readString.indexOf("R2on") >0)
          {
            sendGETR2OFF()
          }
          if(readString.indexOf("R2off") >0)
          {
            sendGETR2ON()
          }          
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

void sendGETR1ON()
{
  if (client.connect(myserver, 80)) {
    client.println("GET /30000/01 HTTP/1.0");
    client.println("Connection: close");
    client.println();
    
  }
}
void sendGETR1OFF()
{
  if (client.connect(myserver, 80)) {
    client.println("GET /30000/00 HTTP/1.0");
    client.println("Connection: close");
    client.println();
    
  }
}
void sendGETR2ON()
{
  if (client.connect(myserver, 80)) {
    client.println("GET /30000/03 HTTP/1.0");
    client.println("Connection: close");
    client.println();
    
  }
}
void sendGETR2OFF()
{
  if (client.connect(myserver, 80)) {
    client.println("GET /30000/02 HTTP/1.0");
    client.println("Connection: close");
    client.println();
    
  }
}

PaulS

Quote
I now need to implement an ASP NET APP
Why ASP.NET? That technology is obsolete.

The Arduino is a server. Why isn't a standard browser good enough for accessing the server?
The art of getting good answers lies in asking good questions.

xklownx

My boss wants me to create an Web APP that can be accessed from tablets. This is going to be a testing device. The user will enter a work order from the web app and then the app with grab information from our database about the lighting fixture. Then it will go through a series of tests like turning the light on full and then at 30 %.

PaulS

Quote
My boss wants me to create an Web APP that can be accessed from tablets.
And you can't convince him/her that that is not necessary?
The art of getting good answers lies in asking good questions.

Go Up