What I'm trying to do is reading the RSSI-value of a few access points as often as possible. Unfortunately, WiFi.scanNetworks is really slow. Fortunately, the implementation in WiFiScan.cpp provides an option to speed things up by setting some config variables:
So what I want to do should be really simple: Output the BSSID in a way I can read it so I can then assign it (manually) to config.bssid. I tried for quite a while but my attempt at reading it only gave me four byte (should be six I believe) and my attempt at writing always resulted in a crash. What's the right way of dealing with this?
Wow. That'll be a good reminder to never post at 2am, no matter how sure I am that I'm still coherent. I modified my original post. And yes, the question is about uint8_t - sorry.
I'm still stuck though and don't seem to get anywhere with Google. I realize it's probably an easy solution, but I can't find it. Help is much appreciated - thanks!
I'm still stuck though and don't seem to get anywhere with Google. I realize it's probably an easy solution, but I can't find it.
Perhaps if you posted more than snippets...
The function you show outputs the SSID of some network, as a pointer to some memory.
Whether config.ssid is a pointer that you could make point to the same location, or to a different location that you have copied the data that BSSID points to, or is an array or is something else entirely, is not at all obvious.
So, how to get the BSSID value into config.ssid remains a mystery. That mystery COULD be solved easily if you posted links to, or better descriptions of, the libraries you are using - links to non-standard libraries; better descriptions of libraries included with the IDE.
Thanks for the reply. I just posted the minimum I deemed necessary because I didn't want to waste anybody's time. Sorry if that was misguided. I can certainly post more! Thanks!
I'm working with an ESP32 and am using their libraries to work with WiFi. Specifically, for the current project, I make use of the function "scanNetworks" on line 57 of arduino-esp32/WiFiScan.cpp at master · espressif/arduino-esp32 · GitHub. This function take a lot of time to execute. However, on line 70-72 you'll see some config options which act as a filter which can really speed things up. I can set the ssid as well as the channel. I would also like to set the bssid and can't. This config-object is described at http://esp32.info/docs/esp_idf/html/dd/dee/structwifi__scan__config__t.html - you can see that bssid is a uint8_t *.
In the end, what I want to do is receive certain parameters as a json object from some server and set those filters accordingly, so only what's required is scanned. I'll probably have to create my own version of this library because there's currently no way to set the config object with an external call.
However, right now I'm still testing things and creating proofs of concepts. Specifically, I need to find out if setting the BSSID really speeds up things and by how much. It seems to me that hard coding this would be easiest for now. This requires me to do two things:
I need to be able to get a bssid so I know what to look for. Here's the code I'm using for this:
count = WiFi.scanNetworks();
for (uint8_t i=0; i<count; i++) {
String ssid;
uint8_t encryptionType;
int32_t RSSI;
uint8_t *BSSID;
int32_t channel;
WiFi.getNetworkInfo(i, ssid, encryptionType, RSSI, BSSID, channel);
Serial.print("ssid: ");
Serial.print(ssid);
Serial.print("That's where I'd like to display the BSSID in some way that's reusable... if possible.");
}
I'd have to be able to assign it to the config object of WiFiScan.cpp.
All of this said - I could maybe implement my own scanNetworks()-function that receives the BSSID from the above code which would mean I wouldn't have to "copy and paste" it. I just thought there would have to be a way to easily work with uint8_t, being that it seems to be a very basic type. And if there is, I figured it might already take me a long ways toward my ultimate goal (if everything else works) of defining this remotely through json. At least that's my thinking. Of course I'm open to other options.
Serial.print("That's where I'd like to display the BSSID in some way that's reusable... if possible.");
I don't understand what you mean by "display the BSSID in some way that's reusable". BSSID is a pointer to some memory where some data is stored. Pointer can be treated as arrays, if you know how much data is there, or if the data has some known terminator (as a NULL is in a string).
According to the documentation, bssid is a MAC address. MAC addresses are 6 bytes.
But, BSSID is a pointer, and the config.bssid is a pointer, so you can simply make config.bssid point to the location that BSSID points to, and let the software that uses config figure out how much data is pointed to.
This displays everything in base 10 and even though I have no idea if that's a safe and appropriate way of doing this, it seems to work... and I can now manually "reuse" this information (the mac address).
Also, in the scanNetwork-function, what I did is this:
Because I don't know what I'm doing and this finally worked. I mean... I'm really grateful for what all you knowledgeable guys are doing here... but I'm not too clear on what I could have done to avoid creating such a long thread for such a simple issue that still doesn't seem to contain a good solution.
This said, I'm not just looking for quick fixes and want to learn. From the little I understand, static memory allocation is called that because the memory is reserved at compile time. Wouldn't that mean I'd have to initialize "wifi_scan_config_t config" somewhere outside the function?
My complete code is basically up in post #5. As I described above, I'm merely doing some testing and benchmarking at this point and don't know yet how the code of the final product is going to look like. I really don't want to waste anybody's time, so it's probably better to leave this at this point and once I did my best with the final product, I'll be more than grateful for some pointers to some improvements.