Created
November 11, 2018 17:57
-
-
Save arn-ob/914674a61a297dea6d6c93dcbe465bfe to your computer and use it in GitHub Desktop.
Ethernet based web server and based on request it manage box and taka managing process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| BoxAndTaka Processing | |
| created 18 Dec 2009 | |
| For HVL (Unilever Bangladesh Project) | |
| by Arnob Almazee | |
| ProjectCity TecTeam | |
| */ | |
| #include <SPI.h> | |
| #include <Ethernet.h> | |
| #include <Servo.h> | |
| // Taka Taking Process | |
| Servo myservo; | |
| int pos = 0; | |
| const int taka = 2; | |
| const int starts = 0; | |
| const int ends = 50; | |
| // box Taking Process | |
| int posBox = 0; | |
| int startsBox = 0; | |
| int endsBox = 6; | |
| const int openDelayBox = 50; | |
| // Actuator | |
| const int pin1 = 5; | |
| const int pin2 = 6; | |
| const int openDelay = 10000; | |
| // for server | |
| byte mac[] = { | |
| 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED | |
| }; | |
| IPAddress ip(192, 168, 0, 110); | |
| String readString; | |
| EthernetServer server(80); | |
| void setup() { | |
| Serial.begin(9600); | |
| EtherINIT(); | |
| myservo.attach(8); // attaches the servo on pin 8 to the servo object | |
| myservo.write(starts); // setup position | |
| pinMode(pin1, OUTPUT); | |
| pinMode(pin2, OUTPUT); | |
| get_close(); | |
| } | |
| 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') { | |
| Serial.println(readString); //print to serial monitor for debuging | |
| client.println("HTTP/1.1 200 OK"); //send new page | |
| client.println("Content-Type: text/html"); | |
| client.println(); | |
| client.println("<HTML>"); | |
| client.println("<HEAD>"); | |
| client.println("<TITLE>ProjectCity</TITLE>"); | |
| client.println("</HEAD>"); | |
| client.println("<BODY>"); | |
| client.println("<H1>ProjectCity Arduino Internal Server</H1>"); | |
| client.println("<hr />"); | |
| client.println("<br />"); | |
| client.println("</BODY>"); | |
| client.println("</HTML>"); | |
| delay(1); | |
| //stopping client | |
| client.stop(); | |
| //controls the Arduino if you press the buttons | |
| if (readString.indexOf("?box") > 0) { | |
| Serial.println("Box"); | |
| boxProcess(); | |
| Serial.println("Box Process Done"); | |
| } | |
| if (readString.indexOf("?taka") > 0) { | |
| Serial.println("TK"); | |
| takaProcess(); | |
| Serial.println("Taka Process Done"); | |
| } | |
| //clearing string for next read | |
| readString = ""; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| // Ethernet System INIT | |
| void EtherINIT(){ | |
| while (!Serial) { | |
| ; // wait for serial port to connect. Needed for native USB port only | |
| } | |
| Serial.println("Ethernet Based Control System"); | |
| Ethernet.begin(mac, ip); | |
| if (Ethernet.hardwareStatus() == EthernetNoHardware) { | |
| Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); | |
| while (true) { | |
| delay(1); | |
| } | |
| } | |
| if (Ethernet.linkStatus() == LinkOFF) { | |
| Serial.println("Ethernet cable is not connected."); | |
| } | |
| // start the server | |
| server.begin(); | |
| Serial.print("server Running at "); | |
| Serial.println(Ethernet.localIP()); | |
| } | |
| void takaProcess() { | |
| for (pos = starts; pos <= ends; pos += 1) { | |
| myservo.write(pos); | |
| delay(15); | |
| } | |
| delay(5000); | |
| for (pos = ends; pos >= starts; pos -= 1) { | |
| myservo.write(pos); | |
| delay(15); | |
| } | |
| delay(500); | |
| boxProcess(); | |
| } | |
| void boxProcess() { | |
| get_opens(); | |
| // open delay | |
| delay(3000); | |
| get_close(); | |
| delay(3000); | |
| } | |
| void get_opens() { | |
| // for (posBox = startsBox; posBox <= endsBox; posBox += 1) | |
| // { | |
| digitalWrite(pin1, LOW); | |
| digitalWrite(pin2, HIGH); | |
| delay(4200); | |
| // } | |
| digitalWrite(pin1, LOW); | |
| digitalWrite(pin2, LOW); | |
| } | |
| void get_close() { | |
| digitalWrite(pin1, HIGH); | |
| digitalWrite(pin2, LOW); | |
| delay(10000); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment