Skip to content

Commit 4408da9

Browse files
committed
fix: Update MQTT configuration and enhance command execution for pointer control
1 parent 9f99c85 commit 4408da9

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

Firmware/include/constants.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
#define LED_PIN 2
2222

2323
// MQTT Broker details
24-
#define MQTT_SERVER "192.168.240.180" // Replace with your broker's IP
24+
#define MQTT_SERVER "192.168.18.29" // Replace with your broker's IP
2525
#define MQTT_PORT 1883
2626
#define SUBSCRIBE_TOPIC "robot/control"
27+
#define SUBSCRIBE_TOPIC_Pointer "robot/pointer"
2728
#define PUBLISH_TOPIC "robot/status"
2829

2930
// WiFi credentials
30-
#define SSID "Umer"
31-
#define PASSWORD "umerghafoor1"
31+
#define SSID "812 "
32+
#define PASSWORD "bawagsial69"
3233

3334
#endif

Firmware/include/controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ enum Direction {
1717

1818

1919
void setup_actuaters();
20-
void executeCommand(String command, int speed, int angle, int stearAngle, bool continuous);
20+
void executeCommandControls(String command, int speed, int stearAngle, bool continuous);
21+
void excuteCommandPointer(int angle);
2122
void controlRobot();
2223
void moveForward(int speed);
2324
void moveBackward(int speed);

Firmware/src/controller.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void setup_actuaters() {
3636

3737
}
3838

39-
void executeCommand(String command, int speed, int angle, int stearAngle, bool continuous) {
39+
void executeCommandControls(String command, int speed, int stearAngle, bool continuous) {
4040
// Execute commands based on JSON input
4141
if (command == "FORWARD") {
4242
moveForward(speed);
@@ -85,15 +85,17 @@ void executeCommand(String command, int speed, int angle, int stearAngle, bool c
8585
currentDirection = BACKWARD_RIGHT;
8686
currentSpeed = speed;
8787
currentAngle = stearAngle;
88-
} else if (command == "SERVO") {
89-
myServo.write(angle);
90-
Serial.println("Servo moved to: " + String(angle));
9188
} else {
9289
Serial.println("Unknown command: " + command);
9390
}
94-
delay(500);
91+
// delay(500);
9592
}
9693

94+
void excuteCommandPointer(int angle)
95+
{
96+
myServo.write(angle);
97+
Serial.println("Servo moved to: " + String(angle));
98+
}
9799

98100
void controlRobot() {
99101
if (isMoving) {

Firmware/src/mqtt_broker.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void reconnect() {
3030
if (client.connect("ESP32_Robot")) {
3131
Serial.println("Connected to MQTT Broker!");
3232
client.subscribe(SUBSCRIBE_TOPIC);
33+
client.subscribe(SUBSCRIBE_TOPIC_Pointer);
3334
} else {
3435
Serial.print("Failed, rc=");
3536
Serial.print(client.state());
@@ -52,14 +53,18 @@ void callback(char* topic, byte* payload, unsigned int length) {
5253
Serial.println(error.f_str());
5354
return;
5455
}
56+
if (strcmp(topic, SUBSCRIBE_TOPIC) == 0){
57+
String command = doc["command"] | "";
58+
int speed = doc["speed"] | 255;
59+
int stearAngle = doc["stearAngle"] | 0;
60+
bool continuous = doc["continuous"] | false;
5561

56-
String command = doc["command"] | "";
57-
int speed = doc["speed"] | 255;
58-
int angle = doc["angle"] | 90;
59-
int stearAngle = doc["stearAngle"] | 0;
60-
bool continuous = doc["continuous"] | false;
61-
62-
executeCommand(command, speed, angle,stearAngle, continuous);
62+
executeCommandControls(command, speed,stearAngle, continuous);
63+
}
64+
else if (strcmp(topic, SUBSCRIBE_TOPIC_Pointer) == 0){
65+
int angle = doc["angle"] | 90;
66+
excuteCommandPointer(angle);
67+
}
6368
}
6469

6570
void send_message(String message) {

0 commit comments

Comments
 (0)