Hi, I am making a project with esp32. It is a robotic arm mounted on a car with an esp32cam as a camera. The camera is streaming independently to my app and that is working fine. I created a sta web server using esp32 to receive data from the app. it receives the data fine but forgets it as soon as new data is received.
The code for the car is as follows.
#include <WiFi.h>
#include <WebServer.h>
#include <WiFiManager.h>
#include <ESP32Servo.h>
Servo Gripper;
Servo Shoulder;
Servo Elbow;
Servo Base;
WebServer server(80);
String gripper;
String shoulder;
String elbow;
String base;
String command; //String to store app command state.
#define ENA 14 // Enable/speed motors Right GPIO14(D5)
#define ENB 15 // Enable/speed motors Left GPIO12(D6)
#define IN_1 21 // L298N in1 motors Right GPIO15(D8)
#define IN_2 17 // L298N in2 motors Right GPIO13(D7)
#define IN_3 18 // L298N in3 motors Left GPIO2(D4)
#define IN_4 19 // L298N in4 motors Left GPIO0(D3)
int speedCar = 800; // 400 - 1023.
int speed_Coeff = 3;
void setup() {
Serial.begin(115200);
Gripper.attach(33);
Shoulder.attach(27);
Elbow.attach(26);
Base.attach(25);
Gripper.write(90);
Shoulder.write(90);
Elbow.write(90);
Base.write(90);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN_1, OUTPUT);
pinMode(IN_2, OUTPUT);
pinMode(IN_3, OUTPUT);
pinMode(IN_4, OUTPUT);
WiFiManager wifiManager;
IPAddress _ip = IPAddress(192, 168, 1, 4);
IPAddress _gw = IPAddress(10, 0, 1, 1);
IPAddress _sn = IPAddress(255, 255, 255, 0);
//end-block2
wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
wifiManager.autoConnect("carm", "dsthebest");
Serial.print(WiFi.localIP());
server.on("/", handle_OnConnect);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started");
delay(2000);
}
void goAhead() {
Serial.println("forward");
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar);
}
void goBack() {
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
}
void goRight() {
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar);
}
void goLeft() {
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
}
void stopRobot() {
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
}
void loop() {
server.handleClient();
gripper = server.arg("claw");
int griper = gripper.toInt();
Serial.print(griper);
Gripper.write(griper);
shoulder = server.arg("shoulder");
int sholder = shoulder.toInt();
//Serial.println(sholder);
//Shoulder.write(sholder);
elbow = server.arg("elbow");
int ebow = elbow.toInt();
// Serial.println(ebow);
//Elbow.write(ebow);
base = server.arg("base");
int bas = base.toInt();
Serial.println(bas);
Base.write(bas);
command = server.arg("State");
Serial.print(command);
if (command == "F") goAhead();
else if (command == "B") goBack();
else if (command == "L") goLeft();
else if (command == "R") goRight();
else if (command == "0") speedCar = 400;
else if (command == "1") speedCar = 470;
else if (command == "2") speedCar = 540;
else if (command == "3") speedCar = 610;
else if (command == "4") speedCar = 680;
else if (command == "5") speedCar = 750;
else if (command == "6") speedCar = 820;
else if (command == "7") speedCar = 890;
else if (command == "8") speedCar = 960;
else if (command == "9") speedCar = 1023;
else if (command == "S") stopRobot();
}
void handle_OnConnect() {
server.send(200, "text/html", "welcome");
}
void handle_NotFound() {
server.send(404, "text/plain", "Not found");
}
im using sliders to send data for the arm. The code to send data is as follows