Skip to content

Esp32s2: Expose more network parameters #3484

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

Merged
merged 13 commits into from
Oct 19, 2020

Conversation

astrobokonon
Copy link

@astrobokonon astrobokonon commented Sep 29, 2020

When connected to an access point, this adds the following (super helpful, for me at least) information to wifi.radio:

  • ap_rssi: RSSI
  • ap_ssid: SSID
  • ap_bssid: BSSID (usually it's MAC address)
  • ipv4_gateway: Gateway
  • ipv4_subnet: Subnet
  • ipv4_dns: Primary DNS

When not connected, these all just return None. I made sure RSSI is always the current one while walking around closer and farther from my AP in case someone wants to build a WiFi mapping toy robot, but I use it primarily for monitoring the current connection.

@astrobokonon astrobokonon marked this pull request as draft September 29, 2020 00:03
@astrobokonon
Copy link
Author

Forgot to add BSSID (and maybe regular SSID) so those are up next, and then this would be ready for review.

@anecdata
Copy link
Member

anecdata commented Sep 29, 2020

This will be very useful! BSSID is super useful in networks with multiple APs with same SSID. Encryption type is another element commonly returned by Arduino and CircuitPython ESP32SPI, although if you are connected you already know it ;-)

@astrobokonon astrobokonon marked this pull request as ready for review September 29, 2020 00:29
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these! Just a couple ideas/comments about the API. Code looks good, just want to make sure it's the API we want.

(mp_obj_t)&mp_const_none_obj },
};

//| ap_ssid: int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about re-using the Network object to represent the current network? I think it has all of the ap_ attributes you want here. Then you can just return None or a Network object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, I'll try that. That'd avoid pulling out everything individually and would probably be nicer to interact with too.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current network is usually represented as an ip_interface isn't it? See https://docs.python.org/3/library/ipaddress.html#ipaddress.ip_interface
The network object has the host bits and'ed away.

@hierophect hierophect added the espressif applies to multiple Espressif chips label Oct 6, 2020
@tannewt
Copy link
Member

tannewt commented Oct 8, 2020

@astrobokonon Any update on this?

@astrobokonon
Copy link
Author

@tannewt I haven't had a chance to circle back just yet, but I'm planning on carving out some time during the rest of this week/weekend! Still would like to get this done for sure.

@tannewt
Copy link
Member

tannewt commented Oct 9, 2020

Awesome! Thanks @astrobokonon

@astrobokonon astrobokonon requested a review from tannewt October 16, 2020 07:11
@astrobokonon
Copy link
Author

@tannewt Ok, I think this is ready again. Just tested it and it worked as before, and it is indeed nicer and cleaner.

I admit that makes me sorta want to do the same with all the ipv4_ prefixed properties to keep things more contained, but I'm a little hazy on how to best do that with the removal/depreciation of the network shared bindings so to be honest I stopped here. I suppose I could add something to ipaddress to further encapsulate the common configuration things (gateway/dns/subnet) but that seemed like a different PR.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One bug I think. Good otherwise.

}

// Make sure the interface is in STA mode
if (self->sta_mode){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (self->sta_mode){
if (!self->sta_mode){

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! But this made me wonder why my tests worked at all. I don't see any reference to anything actually setting self->sta_mode to True at any point...I'm just double checking to make sure I didn't goof up and remove that somewhere else or if it was just forgotten during start_station.

@astrobokonon
Copy link
Author

astrobokonon commented Oct 17, 2020

@tannewt The bug you found did actually uncover another one (self->sta_mode was never actually set to true) so I put in a quick fix to at least set self->sta_mode so it can actually be used.

Right now nothing will unset it, though. My guess is that won't really ever occur until an equivalent start_ap type of method is added.

@astrobokonon astrobokonon requested a review from tannewt October 17, 2020 07:43
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, oops! Thanks for fixing it up.

@tannewt tannewt merged commit d606a3e into adafruit:main Oct 19, 2020
@astrobokonon astrobokonon deleted the esp32s2-morenet branch October 19, 2020 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants