Skip to content

Commit

Permalink
feat: enable default mdns during network init
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwelltoo committed Dec 12, 2023
1 parent df0eb39 commit 8ad48fe
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions porting/el_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Network {
void init() {
this->init(nullptr);
};
void init(status_cb_t cb, mdns_record_t record) {
this->init(cb);
this->mdns = record;
}
virtual void deinit() = 0;
el_net_sta_t status() {
return this->network_status;
Expand Down
1 change: 1 addition & 0 deletions porting/himax/we2/boards/grove_vision_ai_we2/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#define VENDOR_PREFIX "grove"
#define VENDOR_CHIP_NAME "we2"
#define DEVICE_NAME "vision_ai"
#define PORT_DEVICE_NAME "Grove Vision AI (WE2)"

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions porting/himax/we2/el_network_at.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#define AT_LONG_TIME_MS 5000
#define AT_SHORT_TIME_MS 1500
#define AT_TX_MAX_LEN 8192 // 默认固件的AT指令长度阈值为256
#define AT_RX_MAX_LEN 8192 // 可能连续收到多条消息
#define AT_TX_MAX_LEN 16384 // 默认固件的AT指令长度阈值为256
#define AT_RX_MAX_LEN 4096 // 可能连续收到多条消息

#define SNTP_SERVER_CN "cn.ntp.org.cn"
#define SNTP_SERVER_US "us.pool.ntp.org"
Expand Down
1 change: 1 addition & 0 deletions porting/himax/we2/el_network_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ el_err_code_t NetworkWE2::join(const char* ssid, const char* pwd) {
}

if (this->mdns.is_enabled) {
// TODO: check parameter, and support multiple service
sprintf(at.tbuf, AT_STR_HEADER "MDNS=1,\"%s\",\"%s\",%d" AT_STR_CRLF,
this->mdns.host_name, this->mdns.serv_name, this->mdns.port);
err = at_send(&at, AT_SHORT_TIME_MS);
Expand Down
4 changes: 0 additions & 4 deletions porting/himax/we2/el_network_we2.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class NetworkWE2 : public Network {
~NetworkWE2() = default;

void init(status_cb_t cb) override;
void init(status_cb_t cb, mdns_record_t record) {
this->init(cb);
this->mdns = record;
}
void deinit() override;

el_err_code_t join(const char* ssid, const char *pwd) override;
Expand Down
3 changes: 3 additions & 0 deletions sscma/definations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@
#define SSCMA_MQTT_DEVICE_ID_FMT "sscma_%s_%s_%s"
#define SSCMA_MQTT_PUB_FMT "sscma/%s/%s_%s_%s/tx"
#define SSCMA_MQTT_SUB_FMT "sscma/%s/%s_%s_%s/rx"

#define SSCMA_MDNS_PORT 3141
#define SSCMA_MDNS_SERVICE_FMT "%s_%s_%s.%s._sscma"
17 changes: 16 additions & 1 deletion sscma/interface/wifi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace sscma {
using namespace edgelab;

using namespace sscma::types;
using namespace sscma::utility;
using namespace sscma::prototypes;

namespace types {
Expand Down Expand Up @@ -88,7 +89,21 @@ class WiFi final : public Supervisable, public StatefulInterface {

if (current_sta == wifi_sta_e::UNINTIALIZED) {
if (current_sta >= config.first) return true;
_network->init(); // driver init

const auto& device_id = to_hex_string(Device::get_device()->get_device_id());
char service_name[64]{0};
sprintf(service_name, SSCMA_MDNS_SERVICE_FMT,
VENDOR_PREFIX,
VENDOR_CHIP_NAME,
device_id.c_str(),
SSCMA_AT_API_MAJOR_VERSION);
mdns_record_t record = {
.host_name = "_sscma",
.serv_name = service_name,
.port = SSCMA_MDNS_PORT,
.is_enabled = 1
};
_network->init(nullptr, record); // driver init
current_sta =
try_ensure_wifi_status_changed_from(current_sta, SSCMA_WIFI_POLL_DELAY_MS, SSCMA_WIFI_POLL_RETRY);
}
Expand Down

0 comments on commit 8ad48fe

Please sign in to comment.