Hello everyone.
I wrote this code to control a robotic arm by sending a query through the browser. I was testing out sending an int array. It works, but everytime I send a query like ?ints=1,2,3,4 after getting the input, it seems to run setup again.
#include <SPI.h>
#include <Ethernet.h>
#include "SoftwareSerial.h"
#include "LobotServoController.h"
#define LED 13
#define TOUCH 12 //Touch sensor
#define RxPin 8 //Define soft serial port
#define TxPin 9
int posStep = 5;
SoftwareSerial mySerial(RxPin, TxPin); //Set an example of SoftwareSerial
LobotServoController myController(mySerial); //Set an example of LobotSerialController
byte mac[] = {
0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX
};
// Create an EthernetServer object
EthernetServer server(80);
void setup() {
// Start the serial communication
mySerial.begin(9600);
Serial.begin(9600);
digitalWrite(LED, HIGH);
myController.moveServo(1, 500, 1000);
myController.moveServo(2, 500, 1000);
myController.moveServo(3, 260, 1000);
myController.moveServo(4, 750, 1000);
myController.moveServo(5, 445, 1000);
myController.moveServo(6, 500, 1000);
delay(1500);
// Initialize the Ethernet shield
Ethernet.begin(mac);
// Start the server
server.begin();
Serial.println(Ethernet.localIP());
Serial.println("test");
}
void loop() {
EthernetClient client = server.available();
if (client) {
String request = "";
while (client.available()) {
char c = client.read();
request += c;
}
if (request.indexOf("?ints=") != -1) {
String intsStr = request.substring(request.indexOf("?ints=") + 6);
int ints[10];
int i = 0;
while (intsStr.indexOf(",") != -1) {
ints[i++] = intsStr.substring(0, intsStr.indexOf(",")).toInt();
intsStr = intsStr.substring(intsStr.indexOf(",") + 1);
}
ints[i++] = intsStr.toInt();
}
//Run the servo motor to input value
myController.moveServo(1, ints[0], 1000);
myController.moveServo(2, ints[1], 1000);
myController.moveServo(3, ints[2], 1000);
myController.moveServo(4, ints[3], 1000);
myController.moveServo(5, ints[4], 1000);
myController.moveServo(6, ints[5], 1000);
delay(1500);
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><body>Received int array</body></html>");
delay(1000);
//client.stop();
}
}
Can someone help find the issue?