-
Notifications
You must be signed in to change notification settings - Fork 37
Add support for non-WiFi networks #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ShardulNalegave
wants to merge
1
commit into
espressif:main
Choose a base branch
from
ShardulNalegave:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,10 @@ | |
| #include "esp_insights_encoder.h" | ||
| #include "esp_insights_cbor_decoder.h" | ||
|
|
||
| #ifdef CONFIG_ESP_INSIGHTS_THREAD_ENABLED | ||
| #include "esp_openthread.h" | ||
| #endif | ||
|
|
||
| #ifdef CONFIG_ESP_INSIGHTS_CMD_RESP_ENABLED | ||
| #define INSIGHTS_CMD_RESP 1 | ||
| #endif | ||
|
|
@@ -133,12 +137,15 @@ static void esp_insights_first_call(void *priv_data) | |
| xTimerStart(entry->timer, 0); | ||
| } | ||
|
|
||
| /* Returns true if wifi is connected and insights is enabled, false otherwise */ | ||
| static bool is_insights_active(void) | ||
| /* Returns true if ethernet is connected, false otherwise */ | ||
| static bool is_ethernet_connected(void) | ||
| { | ||
| wifi_ap_record_t ap_info; | ||
| bool wifi_connected = esp_wifi_sta_get_ap_info(&ap_info) == ESP_OK; | ||
| return wifi_connected && s_insights_data.enabled; | ||
| esp_netif_t *eth = esp_netif_get_handle_from_ifkey("ETH_DEF"); | ||
| if (eth == NULL) { | ||
| return false; | ||
| } | ||
|
|
||
| return esp_netif_is_netif_up(eth); | ||
| } | ||
|
|
||
| /* Returns true if wifi is connected, false otherwise */ | ||
|
|
@@ -149,6 +156,46 @@ static bool is_wifi_connected(void) | |
| return wifi_connected; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if connected to a thread network with a border router, false if not. | ||
| * In case its unable to identify a BR, returns true. | ||
| */ | ||
| static bool is_thread_with_br_connected(void) | ||
| { | ||
| #ifdef CONFIG_ESP_INSIGHTS_THREAD_ENABLED | ||
| esp_netif_t *ot = esp_netif_get_handle_from_ifkey("OT_DEF"); | ||
| if (ot == NULL) return false; | ||
|
|
||
| if(!esp_netif_is_netif_up(ot)) return false; | ||
|
|
||
| otInstance *instance = esp_openthread_get_instance(); | ||
| if (!instance) return false; | ||
|
|
||
| otNetworkDataIterator it = OT_NETWORK_DATA_ITERATOR_INIT; | ||
| otBorderRouterConfig cfg; | ||
|
|
||
| while (otNetDataGetNextOnMeshPrefix(instance, &it, &cfg) == OT_ERROR_NONE) { | ||
| if (cfg.mDefaultRoute) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| #else | ||
| return false; | ||
| #endif | ||
| } | ||
|
|
||
| /* Returns true if connected to the internet and insights is enabled, false otherwise */ | ||
| static bool is_insights_active(void) | ||
| { | ||
| bool wifi_connected = is_wifi_connected(); | ||
| bool ethernet_connected = is_ethernet_connected(); | ||
| bool is_thread_with_br = is_thread_with_br_connected(); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be more clear, let's add new variable named, |
||
| return (wifi_connected || ethernet_connected || is_thread_with_br) && s_insights_data.enabled; | ||
| } | ||
|
|
||
| /* This executes in the context of timer task. | ||
| * | ||
| * There is a dynamic logic to decide the next instance when the insights | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not create on the new config for thread enabled. We can use the global one.