Skip to content

Commit

Permalink
Networking fixes..
Browse files Browse the repository at this point in the history
  • Loading branch information
LA7ECA, Øyvind committed Mar 15, 2024
1 parent eef7c38 commit ef60365
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 61 deletions.
2 changes: 1 addition & 1 deletion components/networking/api_rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static esp_err_t trklog_put_handler(httpd_req_t *req)
static esp_err_t trackers_handler(httpd_req_t *req) {
rest_cors_enable(req);
cJSON *root = cJSON_CreateArray();
mdns_result_t * res = mdns_find_service("_http", "_tcp");
mdns_result_t * res = mdns_find_service("_https", "_tcp");
while(res) {
cJSON *obj = cJSON_CreateObject();
cJSON_AddStringToObject(obj, "name", res->instance_name);
Expand Down
55 changes: 3 additions & 52 deletions components/networking/cmd_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,6 @@ void register_wifi(void);



/********************************************************************************
* Join an access point
********************************************************************************/

/** Arguments used by 'connect' function */
static struct {
struct arg_int *timeout;
struct arg_str *ssid;
struct arg_str *password;
struct arg_end *end;
} join_args;


int do_join(int argc, char** argv)
{
int nerrors = arg_parse(argc, argv, (void**) &join_args);
if (nerrors != 0) {
arg_print_errors(stderr, join_args.end, argv[0]);
return 1;
}

bool connected = wifi_join(
join_args.ssid->sval[0],
join_args.password->sval[0],
join_args.timeout->ival[0]);

if (!connected)
printf("Connection failed\n");
else
printf("Ok\n");
return 0;
}


/********************************************************************************
* Connect to an internet server using tcp (like telnet command)
********************************************************************************/
Expand Down Expand Up @@ -119,6 +85,7 @@ int do_connect(int argc, char** argv)

int do_scan(int argc, char** argv)
{
wifi_suspend(false);
if (!wifi_startScan()) {
printf("Couldn't start scan of Wifi\n");
return 0;
Expand Down Expand Up @@ -211,10 +178,10 @@ int do_info(int argc, char** argv)

printf(" Stn status: %s\n", wifi_getStatus());
if (wifi_isConnected()) {
// tcpip_adapter_ip_info_t ipinfo = wifi_getIpInfo();
esp_netif_ip_info_t ipinfo = wifi_getIpInfo();
char buf[40];
printf(" Connected to: %s\n", (char*) wifi_getConnectedAp(buf));
// printf(" IP address: %s\n", ip4addr_ntoa(&ipinfo.ip) );
printf(" IP address: %s\n", ip4addr_ntoa(&ipinfo.ip) );
printf(" mDNS hostname: %s\n", mdns_hostname(buf));
}
uint8_t mac[6];
Expand Down Expand Up @@ -303,22 +270,6 @@ CMD_STR_SETTING (_param_fwcert, "FW.CERT", BBUF_SIZE, "", NULL);

void register_wifi()
{
join_args.timeout = arg_int0(NULL, "timeout", "<t>", "Connection timeout, ms");
join_args.timeout->ival[0] = 8000; // set default value
join_args.ssid = arg_str1(NULL, NULL, "<ssid>", "SSID of AP");
join_args.password = arg_str0(NULL, NULL, "<pass>", "PSK of AP");
join_args.end = arg_end(2);

const esp_console_cmd_t join_cmd = {
.command = "wifi-join",
.help = "Join WiFi AP as a station",
.hint = NULL,
.func = &do_join,
.argtable = &join_args
};

ADD_CMD_X(&join_cmd);

ADD_CMD("mdns", &do_mdns, "Scan for MDNS services", NULL);
ADD_CMD("wifi-scan", &do_scan, "Scan for wifi access points", NULL);
ADD_CMD("wifi-info", &do_info, "Info about WIFI connection", NULL);
Expand Down
6 changes: 3 additions & 3 deletions components/networking/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ void mdns_start(char* ident) {
mdns_instance_name_set(buffer);

/* Announce services */
mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
mdns_service_instance_name_set("_http", "_tcp", "Arctic Tracker HTTP Server");
mdns_service_add(NULL, "_https", "_tcp", 443, NULL, 0);
mdns_service_instance_name_set("_https", "_tcp", "Arctic Tracker HTTP Server");

mdns_txt_item_t txtData[1] = {
{"ident", ident}
};
/* Set txt data for service (will free and replace current data) */
mdns_service_txt_set("_http", "_tcp", txtData, 1);
mdns_service_txt_set("_https", "_tcp", txtData, 1);
}


Expand Down
4 changes: 3 additions & 1 deletion components/networking/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ bool wifi_softAp_isEnabled();
int wifi_softAp_clients(void);
bool wifi_isConnected(void);
void wifi_waitConnected(void);
bool wifi_join(const char* ssid, const char* pass, int timeout_ms);
void wifi_suspend(bool susp);
bool wifi_isSuspended();
void wifi_endPause();
void wifi_init(void);
void wifi_enable(bool);
void wifi_enable_softAp(bool);
Expand Down
16 changes: 15 additions & 1 deletion components/networking/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ static wifi_ap_record_t *apList = NULL;
static bool initialized = false;
static bool enabled = false;
static bool suspended = false;
static bool pause = false;
static bool softApEnabled = false;
static bool connected = false;
static char *status = "Off";
static cond_t scanDone;

char default_ssid[32];


Expand Down Expand Up @@ -278,6 +280,10 @@ void wifi_enable(bool en)
suspended = false;
}


/********************************************************************************
* Temprarily suspend the WIFI
********************************************************************************/

void wifi_suspend(bool susp)
{
Expand All @@ -302,6 +308,11 @@ bool wifi_isSuspended() {
}


void wifi_endPause() {
pause = false;
}



/********************************************************************************
* Set ap alternative
Expand All @@ -315,6 +326,7 @@ void wifi_setApAlt(int n, wifiAp_t* ap) {
char key[12];
sprintf(key, "AP.ALT.%d", n);
set_bin_param(key, (void*) ap, sizeof(wifiAp_t));
wifi_endPause();
}


Expand Down Expand Up @@ -559,7 +571,9 @@ static void task_autoConnect( void * pvParms )
ESP_LOGI(TAG, "Waiting - to save power");
if (!wifi_softAp_isEnabled())
wifi_suspend(true);
sleepMs(AUTOCONNECT_PERIOD*1000);
pause = true;
for (int i=0; i<AUTOCONNECT_PERIOD/10 && pause; i++)
sleepMs(10000);
wifi_suspend(false);
}
n++;
Expand Down
2 changes: 1 addition & 1 deletion main/cmd_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void register_system()
ADD_CMD("sysinfo", &do_sysinfo, "System info", NULL);
ADD_CMD("restart", &do_restart, "Restart the program", NULL);
ADD_CMD("tasks", &do_tasks, "Get information about running tasks", NULL);
ADD_CMD("log", &do_log, "Set loglevel (tags: wifi, wifix, http, config, shell)", "<tag> | * [<level>|delete]") ;
ADD_CMD("log", &do_log, "Set loglevel (for debugging/development)", "<tag> | * [<level>|delete]") ;
ADD_CMD("time", &do_time, "Get date and time", NULL);
ADD_CMD("nmea", &do_nmea, "Monitor GPS NMEA datastream", "[raw]");
ADD_CMD("tone", &do_tone, "tone generator test", "");
Expand Down
4 changes: 2 additions & 2 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ static char* logtags[] = {
"system", "main", "wifi", "wifix", "config", "httpd", "shell", "tracker",
"esp-tls", "radio", "ui", "hdlc_enc", "hdlc-dec", "gps", "uart", "digi", "igate",
"tcp-cli", "trackstore", "tracklog", "mbedtls", "rest", "adc", "httpd_txrx",
"httpd_uri", "httpd_parse"
"httpd_uri", "httpd_parse", "mdns"
};

#define NLOGTAGS 26
#define NLOGTAGS 27

uint8_t lglv_dfl = ESP_LOG_NONE;

Expand Down

0 comments on commit ef60365

Please sign in to comment.