Fix unused vars additional_topics and soft start time
This commit is contained in:
63
main/main.c
63
main/main.c
@ -71,6 +71,24 @@ static void mqtt_connected_callback(void)
|
||||
mqtt_publish_pump_state(1, motor_is_running(MOTOR_PUMP_1));
|
||||
mqtt_publish_pump_state(2, motor_is_running(MOTOR_PUMP_2));
|
||||
|
||||
// Subscribe to additional topics
|
||||
static const char* additional_topics[] = {
|
||||
"plant_watering/pump/+/speed",
|
||||
"plant_watering/commands/test_pump/+",
|
||||
"plant_watering/commands/emergency_stop",
|
||||
"plant_watering/settings/+/+",
|
||||
NULL
|
||||
};
|
||||
|
||||
for (int i = 0; additional_topics[i] != NULL; i++) {
|
||||
esp_err_t ret = mqtt_client_subscribe(additional_topics[i], MQTT_QOS_1);
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Subscribed to: %s", additional_topics[i]);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to subscribe to: %s", additional_topics[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Publish motor statistics
|
||||
motor_stats_t stats;
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
@ -154,6 +172,39 @@ static void mqtt_data_callback(const char* topic, const char* data, int data_len
|
||||
} else if (strcmp(topic, "plant_watering/commands/emergency_stop") == 0) {
|
||||
ESP_LOGW(TAG, "Emergency stop command received!");
|
||||
motor_emergency_stop();
|
||||
} else if (strncmp(topic, "plant_watering/settings/pump/", 29) == 0) {
|
||||
// Parse settings commands like:
|
||||
// plant_watering/settings/pump/1/max_runtime
|
||||
// plant_watering/settings/pump/1/min_interval
|
||||
// plant_watering/settings/pump/1/min_speed
|
||||
// plant_watering/settings/pump/1/max_speed
|
||||
|
||||
int pump_id = 0;
|
||||
char setting[32] = {0};
|
||||
|
||||
// Extract pump ID and setting name
|
||||
if (sscanf(topic + 29, "%d/%31s", &pump_id, setting) == 2) {
|
||||
if (pump_id >= 1 && pump_id <= 2) {
|
||||
int value = atoi(data);
|
||||
|
||||
if (strcmp(setting, "max_runtime") == 0 && value > 0) {
|
||||
motor_set_max_runtime(pump_id, value);
|
||||
ESP_LOGI(TAG, "Set pump %d max runtime to %d ms", pump_id, value);
|
||||
} else if (strcmp(setting, "min_interval") == 0 && value > 0) {
|
||||
motor_set_min_interval(pump_id, value);
|
||||
ESP_LOGI(TAG, "Set pump %d min interval to %d ms", pump_id, value);
|
||||
} else if (strcmp(setting, "min_speed") == 0 && value >= 0 && value <= 100) {
|
||||
// Get current max speed to validate
|
||||
motor_stats_t stats;
|
||||
motor_get_stats(pump_id, &stats);
|
||||
motor_set_speed_limits(pump_id, value, 100); // Assuming max stays at 100
|
||||
ESP_LOGI(TAG, "Set pump %d min speed to %d%%", pump_id, value);
|
||||
} else if (strcmp(setting, "max_speed") == 0 && value > 0 && value <= 100) {
|
||||
motor_set_speed_limits(pump_id, MOTOR_MIN_SPEED, value);
|
||||
ESP_LOGI(TAG, "Set pump %d max speed to %d%%", pump_id, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,18 +379,6 @@ void app_main(void)
|
||||
motor_set_min_interval(MOTOR_PUMP_1, CONFIG_WATERING_MIN_INTERVAL_MS);
|
||||
motor_set_min_interval(MOTOR_PUMP_2, CONFIG_WATERING_MIN_INTERVAL_MS);
|
||||
|
||||
// Subscribe to additional MQTT topics after connection
|
||||
static const char* additional_topics[] = {
|
||||
"plant_watering/pump/+/speed",
|
||||
"plant_watering/commands/test_pump/+",
|
||||
"plant_watering/commands/emergency_stop",
|
||||
"plant_watering/settings/+/+",
|
||||
NULL
|
||||
};
|
||||
|
||||
// This would need to be done after MQTT connection
|
||||
// You might want to add this to the mqtt_connected_callback
|
||||
|
||||
// Start WiFi connection
|
||||
esp_err_t ret = wifi_manager_start();
|
||||
if (ret != ESP_OK) {
|
||||
|
||||
Reference in New Issue
Block a user