willow icon indicating copy to clipboard operation
willow copied to clipboard

print the MAC address (for networks that require registration)

Open hamishcunningham opened this issue 2 years ago • 2 comments

Code from https://github.com/espressif/esp-idf/blob/master/examples/system/base_mac_address/main/base_mac_address_example_main.c to print out the WiFi MAC address (e.g. if using a network that requires pre-registration of devices).

hamishcunningham avatar May 17 '23 11:05 hamishcunningham

Please squash the commits.

stintel avatar May 17 '23 13:05 stintel

done!

hamishcunningham avatar May 17 '23 15:05 hamishcunningham

Try running clang-format -i main/main.c?

stintel avatar May 17 '23 20:05 stintel

$ clang-format -i main/main.c 
/home/hamish/willow-hc/.clang-format:26:3: error: unknown enumerated scalar
  Enabled:         true
  ^
Error reading /home/hamish/willow-hc/.clang-format: Invalid argument

hamishcunningham avatar May 17 '23 21:05 hamishcunningham

Looks like you're on an old version ... The action uses clang 15. Maybe comment out line 26 and see if you get further. Enforcing coding style is non-negotiable for me. The actual style can be up for discussion, though!

stintel avatar May 17 '23 21:05 stintel

How about running the formatter of your choice in the CI instead?

hamishcunningham avatar May 17 '23 22:05 hamishcunningham

That happens already and it tells us the style of your contribution does not comply. Modifying code in CI and having CI commit changes is not something I feel comfortable with.

stintel avatar May 17 '23 22:05 stintel

How about a deal? You tell me the difference between your code here

    ESP_LOGI(TAG, "audio_element_getinfo(hdl_ae_hs): sample_rate='%d' channels='%d' bits='%d' bps = '%d'",
             info.sample_rates, info.channels, info.bits, info.bps);

and the failing code:

ESP_LOGI("MAC address", "MAC address: %02x:%02x:%02x:%02x:%02x:%02x",
             mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

and I'll go and trawl through the various docker images with a more recent clang-format in them than the Ubuntu 22.04 version :)

hamishcunningham avatar May 17 '23 22:05 hamishcunningham

According to my testing 5 minutes ago Ubuntu 22.04 has clang-15.

stintel avatar May 17 '23 22:05 stintel

That being said, this is what running clang -i locally makes of it. I don't particularly like it, but enforcing a style is non-negotiable. Feel free to introduce a change to .clang-format and insert it before the "offending" commit. (I'm also looking into it, but it's been a few long days. Thanks for bearing with me).

diff --git a/main/main.c b/main/main.c
index 8ca5862..0cfb848 100644
--- a/main/main.c
+++ b/main/main.c
@@ -664,6 +664,16 @@ static esp_err_t init_input_key_service()
     return periph_service_set_callback(hld_psvc_iks, cb_iks, NULL);
 }

+#define MAC_ADDR_SIZE 6
+uint8_t mac_address[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
+static void get_mac_address()
+{
+    uint8_t mac[MAC_ADDR_SIZE];
+    esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
+    ESP_LOGI("MAC address", "MAC address: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4],
+             mac[5]);
+}
+
 void app_main(void)
 {
     esp_log_level_set("*", ESP_LOG_INFO);
@@ -811,6 +821,8 @@ void app_main(void)
     xTaskCreate(&task_debug_runtime_stats, "dbg_runtime_stats", 4 * 1024, NULL, 0, NULL);
 #endif

+    get_mac_address(); // should be on wifi by now; print the MAC
+
     while (true) {
 #ifdef CONFIG_WILLOW_DEBUG_MEM
         printf("MALLOC_CAP_INTERNAL:\n");

stintel avatar May 17 '23 22:05 stintel

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy
hamish-nuc-black ~/willow-hc $ sudo apt install clang-format
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
clang-format is already the newest version (1:14.0-55~exp2).
0 to upgrade, 0 to newly install, 0 to remove and 6 not to upgrade.
hamish-nuc-black ~/willow-hc $ clang-format --version
Ubuntu clang-format version 14.0.0-1ubuntu1
$ 

hamishcunningham avatar May 17 '23 22:05 hamishcunningham

➜ podman run --rm -it ubuntu:22.04
root@315adb7bc6d3:/# apt update
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [348 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
Get:8 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [499 kB]
Get:9 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [916 kB]
Get:10 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [36.3 kB]
Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Get:12 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [349 kB]
Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1151 kB]
Get:15 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [778 kB]
Get:16 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [42.2 kB]
Get:17 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [25.6 kB]
Get:18 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [49.4 kB]
Fetched 24.5 MB in 3s (7381 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@315adb7bc6d3:/# apt install clang-15
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binfmt-support binutils binutils-common binutils-x86-64-linux-gnu ca-certificates fontconfig-config fonts-dejavu-core gcc-11-base icu-devtools
  lib32gcc-s1 lib32stdc++6 libasan6 libatomic1 libbinutils libbrotli1 libbsd0 libc-dev-bin libc-devtools libc6-dev libc6-i386 libclang-common-15-dev
  libclang-cpp15 libclang1-15 libcrypt-dev libctf-nobfd0 libctf0 libcurl4 libdeflate0 libedit2 libexpat1 libffi-dev libfontconfig1 libfreetype6 libgc1
  libgcc-11-dev libgd3 libgomp1 libicu-dev libicu70 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libldap-2.5-0 libldap-common libllvm15 liblsan0 libmd0
  libmpdec3 libncurses-dev libnghttp2-14 libnsl-dev libobjc-11-dev libobjc4 libpfm4 libpipeline1 libpng16-16 libpsl5 libpython3-stdlib
  libpython3.10-minimal libpython3.10-stdlib libquadmath0 libreadline8 librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3-0 libssh-4
  libstdc++-11-dev libtiff5 libtinfo-dev libtirpc-dev libtsan0 libubsan1 libwebp7 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxml2-dev
  libxpm4 libyaml-0-2 libz3-4 libz3-dev linux-libc-dev llvm-15 llvm-15-dev llvm-15-linker-tools llvm-15-runtime llvm-15-tools manpages manpages-dev
  media-types openssl publicsuffix python3 python3-minimal python3-pkg-resources python3-pygments python3-yaml python3.10 python3.10-minimal
  readline-common rpcsvc-proto ucf
Suggested packages:
  binutils-doc clang-15-doc wasi-libc glibc-doc libgd-tools icu-doc ncurses-doc libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal
  libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql libstdc++-11-doc pkg-config llvm-15-doc man-browser python3-doc python3-tk
  python3-venv python3-setuptools python-pygments-doc ttf-bitstream-vera python3.10-venv python3.10-doc readline-doc
The following NEW packages will be installed:
  binfmt-support binutils binutils-common binutils-x86-64-linux-gnu ca-certificates clang-15 fontconfig-config fonts-dejavu-core gcc-11-base
  icu-devtools lib32gcc-s1 lib32stdc++6 libasan6 libatomic1 libbinutils libbrotli1 libbsd0 libc-dev-bin libc-devtools libc6-dev libc6-i386
  libclang-common-15-dev libclang-cpp15 libclang1-15 libcrypt-dev libctf-nobfd0 libctf0 libcurl4 libdeflate0 libedit2 libexpat1 libffi-dev
  libfontconfig1 libfreetype6 libgc1 libgcc-11-dev libgd3 libgomp1 libicu-dev libicu70 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libldap-2.5-0
  libldap-common libllvm15 liblsan0 libmd0 libmpdec3 libncurses-dev libnghttp2-14 libnsl-dev libobjc-11-dev libobjc4 libpfm4 libpipeline1 libpng16-16
  libpsl5 libpython3-stdlib libpython3.10-minimal libpython3.10-stdlib libquadmath0 libreadline8 librtmp1 libsasl2-2 libsasl2-modules
  libsasl2-modules-db libsqlite3-0 libssh-4 libstdc++-11-dev libtiff5 libtinfo-dev libtirpc-dev libtsan0 libubsan1 libwebp7 libx11-6 libx11-data libxau6
  libxcb1 libxdmcp6 libxml2 libxml2-dev libxpm4 libyaml-0-2 libz3-4 libz3-dev linux-libc-dev llvm-15 llvm-15-dev llvm-15-linker-tools llvm-15-runtime
  llvm-15-tools manpages manpages-dev media-types openssl publicsuffix python3 python3-minimal python3-pkg-resources python3-pygments python3-yaml
  python3.10 python3.10-minimal readline-common rpcsvc-proto ucf
0 upgraded, 109 newly installed, 0 to remove and 4 not upgraded.
Need to get 179 MB of archives.
After this operation, 915 MB of additional disk space will be used.
Do you want to continue? [Y/n] ^C
root@315adb7bc6d3:/#

stintel avatar May 17 '23 22:05 stintel

I considered

-ColumnLimit:     120
+ColumnLimit:     140

But that would trigger other failures... There should really be an option to allow putting first variable argument on a new line if the total line length > ColumnLimit.

stintel avatar May 17 '23 22:05 stintel

Alright. Easy solution: instead of using "MAC address" as first argument to ESP_LOGI, just use TAG. Printing "MAC address: MAC address ..." would be confusing anyway.

stintel avatar May 17 '23 22:05 stintel

This is a mess now, I'll start over :)

hamishcunningham avatar May 18 '23 06:05 hamishcunningham