Actually there's no error. Code is working fine, but that warning is annoying me.
lib/uwc_event/wifi_event.c: In function 'uwc_wifi_init_sta':
lib/uwc_event/wifi_event.c:33:24: warning: initialization of 'unsigned char' from 'uint8_t *' {aka 'unsigned char *'} makes integer from pointer without a cast [-Wint-conversion]
.ssid = {(uint8_t *)&WIFI_SSID[0]},
^
lib/uwc_event/wifi_event.c:33:24: note: (near initialization for 'wifi_config.sta.ssid[0]')
lib/uwc_event/wifi_event.c:34:28: warning: initialization of 'unsigned char' from 'uint8_t *' {aka 'unsigned char *'} makes integer from pointer without a cast [-Wint-conversion]
.password = {(uint8_t *)&WIFI_PASW[0]},
^
lib/uwc_event/wifi_event.c:34:28: note: (near initialization for 'wifi_config.sta.password[0]')
And this is the part code where warning show:
wifi_config_t wifi_config = {
.sta =
{
.ssid = {(uint8_t *)&WIFI_SSID[0]},
.password = {(uint8_t *)&WIFI_PASW[0]},
.threshold.authmode = WIFI_AUTH,
},
};
Where .ssid
is declared (I'm not sure, see: (https://github.com/espressif/esp-idf/blob/master/components/esp_wifi/include/esp_wifi_types.h)) with:
typedef struct {
uint8_t ssid[32];
uint8_t password[64];
// another code...
WIFI_SSID
and WIFI_PASW
are declared by myself with:
extern char WIFI_SSID[32];
extern char WIFI_PASW[32];
So how do I remove those warning? What makes that warning happen?
CodePudding user response:
ssid
and password
are arrays so you are trying to initialize the (rhs) address into the first element of an array. Instead you want to copy the data with for example strcpy()
:
strcpy(wifi_config.sta.ssid, WIFI_SSID);
strcpy(wifi_config.sta.password, WIFI_PASW);
CodePudding user response:
The data member ssid
is declared as an array of objects of the type uint8_t
uint8_t ssid[32];
You are trying to initialize its first element with a pointer
.ssid = {(uint8_t *)&WIFI_SSID[0]},
The initialization above is equivalent to
.ssid = {[0] = (uint8_t *)&WIFI_SSID[0]},
That is the element ssid[0]
is initialized with a pointer.
So the compiler issues a diagnostic message.
The same problem exists with the data member password
.
To set values of these data members you need to use either strcpy
if these arrays contain strings
extern char WIFI_SSID[32];
extern char WIFI_PASW[32];
or memcpy
if the arrays do not contain strings.
CodePudding user response:
Thanks for @AllanWind and @VladfromMoscow, my final code will be:
wifi_config_t wifi_config = {
.sta =
{
.threshold.authmode = WIFI_AUTH,
},
};
strncpy((char *)wifi_config.sta.ssid, (char *)&WIFI_SSID[0], 32);
strncpy((char *)wifi_config.sta.password, (char *)&WIFI_PASW[0], 64);
And here the compiler result without warning anymore:
* Executing task: C:\Users\User\.platformio\penv\Scripts\platformio.exe run
Processing esp32cam (platform: espressif32; board: esp32cam; framework: espidf)
------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32cam.html
PLATFORM: Espressif 32 (5.0.0 sha.e66e12c) > AI Thinker ESP32-CAM
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-espidf @ 3.40401.0 (4.4.1)
- tool-cmake @ 3.16.4
- tool-esptoolpy @ 1.30300.0 (3.3.0)
- tool-idf @ 1.0.1
- tool-mconf @ 1.4060000.20190628 (406.0.0)
- tool-ninja @ 1.9.0
- toolchain-esp32ulp @ 1.22851.191205 (2.28.51)
- toolchain-xtensa-esp32 @ 8.4.0 2021r2-patch3
Reading CMake configuration...
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...
Dependency Graph
|-- esp32-camera @ 2.0.0
|-- uwc_event
| |-- uwc_cam_cfg
| | |-- esp32-camera @ 2.0.0
| |-- uwc_eol_remover
| |-- uwc_tag
| |-- uwc_uart
| |-- uwc_wifi_cfg
| | |-- uwc_tag
Building in release mode
Compiling .pio\build\esp32cam\liba67\uwc_event\wifi_event.o
Archiving .pio\build\esp32cam\liba67\libuwc_event.a
Linking .pio\build\esp32cam\firmware.elf
Retrieving maximum program size .pio\build\esp32cam\firmware.elf
Checking size .pio\build\esp32cam\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 10.1% (used 33120 bytes from 327680 bytes)
Flash: [======= ] 72.0% (used 755277 bytes from 1048576 bytes)
Building .pio\build\esp32cam\firmware.bin
esptool.py v3.3
Creating esp32 image...
Merged 25 ELF sections
Successfully created esp32 image.
================== [SUCCESS] Took 21.36 seconds ==================
* Terminal will be reused by tasks, press any key to close it.