I'm trying to combine 2 programs i want to move servos with a key stroke over wifi but i don't know how to get the program to read what it resaves
#include <Arduino.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WebSerial.h>
#include <Servo.h>
Servo servo1; //wrist
Servo servo2; //hand
Servo servo3; //shoulder
Servo servo4; //elbow
Servo servo5; //bottom
//define initial positions of servos
const int init1 = 90;
const int init2 = 90
;
const int init3 = 90;
const int init4 = 90;
const int init5 = 90;
//define the increment in degrees. This is what we will use to move the servos
int inc = 1;
//define the delay between each iteration of movement. I will call it speed_ for simplicity
int speed_ = 10;
//define the initial postions of the servos
int pos1 = init1;
int pos2 = init2;
int pos3 = init3;
int pos4 = init4;
int pos5 = init5;
AsyncWebServer server(80);
const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Your WiFi SSID
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Your WiFi Password
void recvMsg(uint8_t *data, size_t len){
WebSerial.println("Received Data...");
String d = "";
for(int i=0; i < len; i++){
d += char(data[i]);
}
i need help here!!!!i think
}
void setup() {
Serial.begin(115200);
servo1.attach(7);
servo2.attach(6);
servo3.attach(5);
servo4.attach(4);
servo5.attach(3);
servo1.write(pos1);
servo2.write(pos2);
servo3.write(pos3);
servo4.write(pos4);
servo5.write(pos5);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("WiFi Failed!\n");
return;
}
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// WebSerial is accessible at "/webserial" in browser
WebSerial.begin(&server);
WebSerial.msgCallback(recvMsg);
server.begin();
}
void loop() {
//possibly not needed?
Serial.flush();
//val is the variable we store the received data in
int val = Serial.read(d);
//and here
//condtional needed for loops to work properly
int i = 1;
//--------------------------------MOVE servo5 METHOD-----------------------------------------
while(val=='w' && i==1){
val = Serial.read();
//and and this point
//limitations that I put in so I can't break the servo cords
if(pos5 <= 180){
//increment position to move servo
pos5=pos5+inc;
servo5.write(pos5);
//used to break out of the loop and move different servo or do nothing
if(val!='w'){
i=0;
}
delay(speed_);
}
}
//---------------------------------change speed of arm method------------------------
if(val=='n' && i==1){
val = Serial.read();
if(inc < 5 && inc >= 1){
//changing the increment size changes the speed essentially
inc = inc - 1;
i=0;
}
if(inc == 5){
inc = inc - 1;
i = 0;
}
}
if(val=='m' && i==1){
val = Serial.read();
if(inc < 5 && inc >= 1){
inc = inc + 1;
i=0;
}
if(inc == 0){
inc = 1;
i=0;
}
}
}