libretiny-eu / libretiny

PlatformIO development platform for IoT modules
http://docs.libretiny.eu/
MIT License
402 stars 59 forks source link

Compilation error when using WiFiClientSecure #184

Closed TuanAIoT closed 11 months ago

TuanAIoT commented 12 months ago

I use CBU module with platformio.ini configuration [env:cbu] platform = libretiny board = cbu framework = arduino upload_speed = 921600 monitor_speed = 115200 lib_compat_mode = off lib_deps = 256dpi/MQTT@^2.5.1

Compile and Program operate normally and declare: WiFiClient WifiClient;

But got a compilation error when declaring: WiFiClientSecure WifiClientSecure;

Can someone help me fix it

image image image

TuanAIoT commented 12 months ago

I saw an article where the same error occurred with Esp32, but with the CBU module and libretiny platform, I don't know how to fix it. https://github.com/espressif/arduino-esp32/issues/5977

kuba2k2 commented 12 months ago

The error from the linked issue is not related and completely different.

This issue has been found before and resolved, but it's in a different branch (not finished yet). For now, you can paste the following block of code into your program:

__attribute__((weak)) String ipToString(const IPAddress &ip) {
    char szRet[16];
    sprintf(szRet, "%hhu.%hhu.%hhu.%hhu", ip[0], ip[1], ip[2], ip[3]);
    return String(szRet);
}

Make sure to put it in a .cpp file, and not in a .c file.

TuanAIoT commented 12 months ago

What is that code and where should I paste it?

kuba2k2 commented 12 months ago

This is the missing function. Paste it somewhere in your .cpp program file. For example after the line WiFiClientSecure WifiClientSecure. Also, it's better to name it something like clientSecure because your current name is too similar to the class name.

TuanAIoT commented 12 months ago

You mean paste it right after the line declaring WiFiClientSecure clientSecure; However, there is still a compilation error image image

kuba2k2 commented 12 months ago

Yes, that's what I meant, However, the secure client is not tested and not properly implemented on Beken. You might want to use raw mbedTLS directly instead.

TuanAIoT commented 12 months ago

I did as you said and continued to comment line 241 and compiled successfully I wonder if my commenting line 241 will affect the MQTT SSL/TLS connection image

I use attribute((weak)) right before declaring the command int mbedtls_net_set_nonblock( mbedtls_net_context *ctx ); It seems the compilation was successful but I don't know if the program works well image

kuba2k2 commented 11 months ago

You can't just comment out code - it's there for a reason. As I mentioned earlier, WifiClientSecure is not fully implemented and might not work at all, fail to compile, or even crash the chip.

TuanAIoT commented 11 months ago

You can't just comment out code - it's there for a reason. As I mentioned earlier, WifiClientSecure is not fully implemented and might not work at all, fail to compile, or even crash the chip.

So is there any way I can connect with MQTT SSL/TLS?

kuba2k2 commented 11 months ago

Try using ESPHome instead. Maybe it supports MQTT with TLS.

TuanAIoT commented 11 months ago

I think I prefer programming on the libretiny platform. MQTT SSL/TLS connectivity is essential for IoT projects. Are you continuing to develop on this topic, because I think the MbedTLSClient library is quite complete, there's just a little more left. Everyone also hopes that your project can replace Tuya SDK. I don't like TuyaOS and the Tuya WindIDE compiler