mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Fixes
This commit is contained in:
@@ -14,12 +14,12 @@ void ConfigManager::init_config() {
|
|||||||
nvs_open(NVS_FLASH_NAMESPACE, NVS_READWRITE, &config_handle);
|
nvs_open(NVS_FLASH_NAMESPACE, NVS_READWRITE, &config_handle);
|
||||||
|
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
if (ESP_ERR_NVS_NOT_FOUND == nvs_get_u16(config_handle, "id", &id)) {
|
if (ESP_ERR_NVS_NOT_FOUND == nvs_get_u16(config_handle, MODULE_ID_KEY, &id)) {
|
||||||
nvs_set_u16(config_handle, MODULE_ID_KEY, DEFAULT_MODULE_ID);
|
nvs_set_u16(config_handle, MODULE_ID_KEY, DEFAULT_MODULE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
if (ESP_ERR_NVS_NOT_FOUND == nvs_get_u16(config_handle, "id", &type)) {
|
if (ESP_ERR_NVS_NOT_FOUND == nvs_get_u16(config_handle, MODULE_TYPE_KEY, &type)) {
|
||||||
nvs_set_u16(config_handle, MODULE_TYPE_KEY, DEFAULT_MODULE_TYPE);
|
nvs_set_u16(config_handle, MODULE_TYPE_KEY, DEFAULT_MODULE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,12 @@
|
|||||||
|
|
||||||
// todo: - add message routing to correct client
|
// todo: - add message routing to correct client
|
||||||
// - authenticate (don't just return true from the auth function)
|
// - authenticate (don't just return true from the auth function)
|
||||||
|
// - tx from board
|
||||||
|
|
||||||
TCPServer::TCPServer(const int port) {
|
TCPServer::TCPServer(const int port) {
|
||||||
this->m_port = port;
|
this->m_port = port;
|
||||||
this->m_mutex = xSemaphoreCreateMutex();
|
this->m_mutex = xSemaphoreCreateMutex();
|
||||||
this->m_clients = std::unordered_set<int>();
|
this->m_clients = std::unordered_set<int>();
|
||||||
|
|
||||||
|
|
||||||
this->m_task = nullptr;
|
this->m_task = nullptr;
|
||||||
this->m_rx_task = nullptr;
|
this->m_rx_task = nullptr;
|
||||||
this->m_tx_task = nullptr;
|
this->m_tx_task = nullptr;
|
||||||
@@ -153,7 +152,7 @@ TCPServer::~TCPServer() {
|
|||||||
close(sock);
|
close(sock);
|
||||||
to_remove.emplace_back(sock);
|
to_remove.emplace_back(sock);
|
||||||
} else {
|
} else {
|
||||||
// todo: send to rx queue
|
// todo: send to rx queue instead of printing
|
||||||
buffer[len] = 0; // temp: Null-terminate whatever is received and treat it like a string
|
buffer[len] = 0; // temp: Null-terminate whatever is received and treat it like a string
|
||||||
printf("TCP Server Received %d bytes: %s\n", len, buffer);
|
printf("TCP Server Received %d bytes: %s\n", len, buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,10 +104,10 @@ int WifiManager::init_connection() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
esp_wifi_set_mode(WIFI_MODE_STA);
|
||||||
esp_wifi_set_config(static_cast<wifi_interface_t>(ESP_IF_WIFI_STA), &wifi_configuration);
|
esp_wifi_set_config(static_cast<wifi_interface_t>(ESP_IF_WIFI_STA), &wifi_configuration);
|
||||||
|
|
||||||
esp_wifi_start();
|
esp_wifi_start();
|
||||||
esp_wifi_set_mode(WIFI_MODE_STA);
|
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -5,9 +5,12 @@
|
|||||||
#ifndef DISCOVERYSERVICE_H
|
#ifndef DISCOVERYSERVICE_H
|
||||||
#define DISCOVERYSERVICE_H
|
#define DISCOVERYSERVICE_H
|
||||||
|
|
||||||
class mDNSDiscoveryService {
|
class mDNSDiscoveryService final {
|
||||||
public:
|
public:
|
||||||
mDNSDiscoveryService();
|
mDNSDiscoveryService() = delete;
|
||||||
|
~mDNSDiscoveryService() = delete;
|
||||||
|
|
||||||
|
static void setup();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //DISCOVERYSERVICE_H
|
#endif //DISCOVERYSERVICE_H
|
||||||
|
|||||||
@@ -13,12 +13,20 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
// todo: clean this up (strange to be a constructor) also need to add more details
|
// todo: clean this up (strange to be a constructor) also need to add more details, need to add to routing table
|
||||||
mDNSDiscoveryService::mDNSDiscoveryService() {
|
void mDNSDiscoveryService::setup() {
|
||||||
mdns_init();
|
mdns_init();
|
||||||
mdns_hostname_set(std::format("botchain-{}", ConfigManager::get_module_id()).c_str());
|
mdns_hostname_set(std::format("botchain-{}", ConfigManager::get_module_id()).c_str());
|
||||||
mdns_instance_name_set(std::format("BotChain Robot Module {}", ConfigManager::get_module_id()).c_str());
|
mdns_instance_name_set(std::format("BotChain Robot Module {}", ConfigManager::get_module_id()).c_str());
|
||||||
|
|
||||||
mdns_service_add(nullptr, "_robotcontrol", "_tcp", TCP_PORT, nullptr, 0);
|
mdns_service_add(nullptr, "_robotcontrol", "_tcp", TCP_PORT, nullptr, 0);
|
||||||
mdns_service_instance_name_set("_robotcontrol", "_tcp", "Robot Control TCP Server");
|
mdns_service_instance_name_set("_robotcontrol", "_tcp", "Robot Control TCP Server");
|
||||||
|
|
||||||
|
mdns_txt_item_t service_txt_data[3] = {
|
||||||
|
{"module_id",std::to_string(ConfigManager::get_module_id()).c_str()},
|
||||||
|
{"module_type",std::to_string(ConfigManager::get_module_type()).c_str()},
|
||||||
|
{"connected_modules","2,3,4,5,6,7,8,9"},
|
||||||
|
};
|
||||||
|
|
||||||
|
mdns_service_txt_set("_robotcontrol", "_tcp", service_txt_data, 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ extern "C" [[noreturn]] void app_main(void) {
|
|||||||
const auto manager = std::make_unique<WifiManager>();
|
const auto manager = std::make_unique<WifiManager>();
|
||||||
manager->connect();
|
manager->connect();
|
||||||
|
|
||||||
const auto discovery = std::make_unique<mDNSDiscoveryService>();
|
mDNSDiscoveryService::setup();
|
||||||
|
|
||||||
const auto tcp_server = std::make_unique<TCPServer>(TCP_PORT);
|
const auto tcp_server = std::make_unique<TCPServer>(TCP_PORT);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user