Skip to content

Commit eb8f864

Browse files
authored
Add Pico W WiFi Scan example
1 parent 165ade2 commit eb8f864

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

examples/arduino-wifi-scan/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
How to build PlatformIO based project
2+
=====================================
3+
4+
1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html)
5+
2. Download [development platform with examples](https://github.com/platformio/platform-raspberrypi/archive/develop.zip)
6+
3. Extract ZIP archive
7+
4. Run these commands:
8+
9+
```shell
10+
# Change directory to example
11+
$ cd platform-raspberrypi/examples/arduino-wifi-scan
12+
13+
# Build project
14+
$ pio run
15+
16+
# Upload firmware
17+
$ pio run --target upload
18+
19+
# Clean build files
20+
$ pio run --target clean
21+
```
22+
23+
## Notes
24+
25+
This example is only intended for the Raspberry Pi Pico W with the [Earle Philhower](https://github.com/earlephilhower/arduino-pico) core.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

examples/arduino-wifi-scan/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter, extra scripting
4+
; Upload options: custom port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
;
7+
; Please visit documentation for the other options and examples
8+
; https://docs.platformio.org/page/projectconf.html
9+
10+
[env]
11+
platform = raspberrypi
12+
framework = arduino
13+
14+
[env:rpipicow]
15+
board = rpipicow
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Simple WiFi network scanner application
2+
// Released to the public domain in 2022 by Earle F. Philhower, III
3+
#include <Arduino.h>
4+
#include <WiFi.h>
5+
6+
void setup() {
7+
Serial.begin(115200);
8+
}
9+
10+
const char *macToString(uint8_t mac[6]) {
11+
static char s[20];
12+
sprintf(s, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
13+
return s;
14+
}
15+
16+
const char *encToString(uint8_t enc) {
17+
switch (enc) {
18+
case ENC_TYPE_NONE: return "NONE";
19+
case ENC_TYPE_TKIP: return "WPA";
20+
case ENC_TYPE_CCMP: return "WPA2";
21+
case ENC_TYPE_AUTO: return "AUTO";
22+
}
23+
return "UNKN";
24+
}
25+
26+
void loop() {
27+
delay(5000);
28+
Serial.printf("Beginning scan at %d\n", millis());
29+
auto cnt = WiFi.scanNetworks();
30+
if (!cnt) {
31+
Serial.printf("No networks found\n");
32+
} else {
33+
Serial.printf("Found %d networks\n\n", cnt);
34+
Serial.printf("%32s %5s %17s %2s %4s\n", "SSID", "ENC", "BSSID ", "CH", "RSSI");
35+
for (auto i = 0; i < cnt; i++) {
36+
uint8_t bssid[6];
37+
WiFi.BSSID(i, bssid);
38+
Serial.printf("%32s %5s %17s %2d %4d\n", WiFi.SSID(i), encToString(WiFi.encryptionType(i)), macToString(bssid), WiFi.channel(i), WiFi.RSSI(i));
39+
}
40+
}
41+
Serial.printf("\n--- Sleeping ---\n\n\n");
42+
delay(5000);
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PIO Unit Testing and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html

0 commit comments

Comments
 (0)