sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
236 stars 125 forks source link

problems when porting code from Arduino to Platformio #124

Closed sgrizzi closed 3 years ago

sgrizzi commented 3 years ago

Hi, Platformio is offering, in my view, a better development environment wrt. Arduino IDE and I am trying to port my ESP32 code from Arduino to Platformio. The code is running fine in Arduino. I "translated" the .ino files into .cpp and .h combinations.

1) The code compiles, loads and runs correctly, but I cannot see the usual json traffic to/from Sinric on the serial output (serial is working as I see my own diagnostics). I made various attempts commenting and uncommenting lines... but I cannot enable the diagnostics. What am I doing wrong? (my platformio.ini is attached) main.cpp contains these lines (as with Arduino) // Uncomment the following line to enable serial debug output

define ENABLE_DEBUG

ifdef ENABLE_DEBUG

   #define DEBUG_ESP_PORT Serial
   #define NODEBUG_WEBSOCKETS
   #define NDEBUG

endif

2) if I upgrade the Sinric library from 2.7.6 to 2.8.1 -the latest version I see- then the code compiles correctly by I get the following error at runtime, just after the initialization:

[E][WiFiClientSecure.cpp:132] connect(): start_ssl_client: -10368 [E][ssl_client.cpp:33] _handle_error(): [start_ssl_client():199]: (-15104) PK - The pubkey tag or value is invalid (only RSA and EC are supported) [E][WiFiClientSecure.cpp:132] connect(): start_ssl_client: -15104 [E][ssl_client.cpp:33] _handle_error(): [start_ssl_client():199]: (-16256) PK - Memory allocation failed [E][WiFiClientSecure.cpp:132] connect(): start_ssl_client: -16256 [E][ssl_client.cpp:33] _handle_error(): [start_ssl_client():199]: (-10368) X509 - Allocation of memory failed [E][WiFiClientSecure.cpp:132] connect(): start_ssl_client: -10368 [E][ssl_client.cpp:87] start_ssl_client(): Connect to Server failed! [E][WiFiClientSecure.cpp:132] connect(): start_ssl_client: -1

Clearly the connection with the portal is not established and nothing works anymore. Apart from upgrading the Sinric library nothing else has been changed (actually 2.8.1 was initially loaded by default - I downgraded to 2.7.6 and got the code running).

Any idea? Sinric 2.7.6 is the same library installed in the Arduino IDE.

Best regards, Gabriele

platformio.ini.txt

sivar2311 commented 3 years ago

Since SDK 2.8.0, SSL is enabled by default. This requires latest ESP-Arduino Core and WebSocket library.

sgrizzi commented 3 years ago

Hi Boris,

can you please tell me exactly which libraries are needed (in Platformio)?

If I load “WebSockets by Markus Sattler” version 2.3.3, released 3 days ago, it still does not work, and I am using Espressif 32 v.2.1.0, which should be the latest according to the Release Notes.

Can you also please tell me how to resume the json debugging stream on serial ??

Thanks a lot,

Gabriele

From: Boris Jäger notifications@github.com Reply to: sinricpro/esp8266-esp32-sdk reply@reply.github.com Date: Sunday, 10 January 2021 at 16:35 To: sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Gabriele Rizzi gabriele.rizzi@smartsol.it, Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

Since SDK 2.8.0, SSL is enabled by default. This requires latest ESP-Arduino Core and WebSocket library.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

sivar2311 commented 3 years ago

Versions seems to be okay. That's the same i use. Please use platformio.ini file from examples folder. Change the board to your need.

Debug on PIO is enabled via platformio.ini.

I think it's best you start with a simple project, like switch.

sgrizzi commented 3 years ago

Boris, I did use the platformio.ini from the example folder and edited to suit my needs.

Here below, whether I comment (or not) the enclosed lines, nothing changes. In Platformio, is this the only place where debugging can be enabled?

If I can get debugging running I might be able to understand more also of the versioning problems.

 

build_flags = ; set your debug output (default=Serial) -D DEBUG_ESP_PORT=Serial ; comment the folowing line to enable Websockets debugging -D NODEBUG_WEBSOCKETS ; comment the folowing line to enable WiFi debugging -D NDEBUG ; comment the following line to enable SinricPro debugging -D NODEBUG_SINRIC

“I think it's best you start with a simple project, like switch.”

This is easier said than done… For the moment I will stay with the old libraries and in parallel I will try and understand why the new ones are not working. And will get back to you if I have additional findings and the problem remains.

Best regards, Gabriele

From: Boris Jäger notifications@github.com Reply to: sinricpro/esp8266-esp32-sdk reply@reply.github.com Date: Sunday, 10 January 2021 at 18:11 To: sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Gabriele Rizzi gabriele.rizzi@smartsol.it, Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

Versions seems to be okay. That's the same i use. Please use platformio.ini file from examples folder. Change the board to your need.

Debug on PIO is enabled via platformio.ini.

I think it's best you start with a simple project, like switch.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

sivar2311 commented 3 years ago
build_flags =
; set your debug output (default=Serial)
 -D DEBUG_ESP_PORT=Serial
; comment the folowing line to enable Websockets debugging
 -D NODEBUG_WEBSOCKETS
; comment the folowing line to enable WiFi debugging
 -D NDEBUG
; comment the following line to enable SinricPro debugging
; -D NODEBUG_SINRIC

This will enable SinricPro Debug.

sgrizzi commented 3 years ago

No, it does not work. It is exactly my configuration, but, to play it safe, I copied your text… and again no output.

As an example, if I press my doorbell (one of the devices supported) I can see “ding-dong” on the portal and hear the notification in Alexa, as well as read my diagnostic message that the expecting event has been received – but no json ping-pong with Sinric (which is what I see if I run the same with Arduino). Could it be that the output stream in platformio is routed somewhere else ??

Rgds, Gabriele

From: Boris Jäger notifications@github.com Reply to: sinricpro/esp8266-esp32-sdk reply@reply.github.com Date: Sunday, 10 January 2021 at 18:41 To: sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Gabriele Rizzi gabriele.rizzi@smartsol.it, Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

build_flags = ; set your debug output (default=Serial) -D DEBUG_ESP_PORT=Serial ; comment the folowing line to enable Websockets debugging -D NODEBUG_WEBSOCKETS ; comment the folowing line to enable WiFi debugging -D NDEBUG ; comment the following line to enable SinricPro debugging ; -D NODEBUG_SINRIC This will enable SinricPro Debug.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

sivar2311 commented 3 years ago

Serial Monitor is configured in platformio.ini too,

monitor_speed = xxxxxx
monitor_port = COMyy

Baudrate must match the same settings as used in sketch. When using platformio, you have to remove the debug defines in sketch sketch:

#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
sgrizzi commented 3 years ago

This is really weird… here is my config in platformio.ini (I am using a Mac)

upload_speed = 921600

monitor_speed = 115200

upload_port = /dev/cu.SLAB_USBtoUART

monitor_port = /dev/cu.SLAB_USBtoUART

The option monitor_port was not there before. I added it and nothing changed.

I had already removed the “define…” block in the original sketch.

Serial output does work. Here the end of the initialization:

finished restoring EEPROM

[Wifi]: Connecting via Autoconnect Started, IP:192.168.1.76

Scanning BLE...

hopefully scanning in the background...

Connected to SinricPro

Temperaturesensor turned on (via SinricPro)

Temperature: 0.0 Celsius.Humidity: 0.0%

I also tried with another serial monitor app (coolterm), just to avoid any possible problems with Platformio, and I get the same results.

From: Boris Jäger notifications@github.com Reply to: sinricpro/esp8266-esp32-sdk reply@reply.github.com Date: Sunday, 10 January 2021 at 19:38 To: sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Gabriele Rizzi gabriele.rizzi@smartsol.it, Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

Serial Monitor is configured in platformio.ini too, monitor_speed = xxxxxx monitor_port = COMyy Baudrate must match the same settings as used in sketch. When using platformio, you have to remove the debug defines in sketch sketch:

define ENABLE_DEBUG

ifdef ENABLE_DEBUG

define DEBUG_ESP_PORT Serial

define NODEBUG_WEBSOCKETS

define NDEBUG

endif

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

sgrizzi commented 3 years ago

I found the problem – but now I have another one!!

Checking SinricProDebug.h I realized that DEBUG_ESP_PORT was not seen as active.

At the bottom of the .ini file I had used another build_flags option to generate a linker map and probably this entry was “erasing” the first one with the debug flags.

Now this problem is fixed but the code does not compile. ?!?

I get a series of these errors:

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h: In member function 'void websocketListener::setExtraHeaders()':

.pio/libdeps/ESP32/SinricPro/src/SinricProDebug.h:13:41: error: expected primary-expression before '.' token

define DEBUG_SINRIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )

                                         ^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h:92:3: note: in expansion of macro 'DEBUG_SINRIC'

   DEBUG_SINRIC("[SinricPro:Websocket]: headers: \r\n%s\r\n", headers.c_str());

   ^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h: In member function 'void websocketListener::begin(String, String, String, SinricProQueue_t*)':

.pio/libdeps/ESP32/SinricPro/src/SinricProDebug.h:13:41: error: expected primary-expression before '.' token

define DEBUG_SINRIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )

                                         ^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h:113:3: note: in expansion of macro 'DEBUG_SINRIC'

   DEBUG_SINRIC("[SinricPro:Websocket]: Connecting to WebSocket Server (%s)\r\n", server.c_str());

   ^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h: In member function 'void websocketListener::webSocketEvent(WStype_t, uint8_t*, size_t)':

.pio/libdeps/ESP32/SinricPro/src/SinricProDebug.h:13:41: error: expected primary-expression before '.' token

define DEBUG_SINRIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )

From: Gabriele Rizzi gabriele.rizzi@smartsol.it Date: Sunday, 10 January 2021 at 19:48 To: sinricpro/esp8266-esp32-sdk reply@reply.github.com, sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

This is really weird… here is my config in platformio.ini (I am using a Mac)

upload_speed = 921600

monitor_speed = 115200

upload_port = /dev/cu.SLAB_USBtoUART

monitor_port = /dev/cu.SLAB_USBtoUART

The option monitor_port was not there before. I added it and nothing changed.

I had already removed the “define…” block in the original sketch.

Serial output does work. Here the end of the initialization:

finished restoring EEPROM

[Wifi]: Connecting via Autoconnect Started, IP:192.168.1.76

Scanning BLE...

hopefully scanning in the background...

Connected to SinricPro

Temperaturesensor turned on (via SinricPro)

Temperature: 0.0 Celsius.Humidity: 0.0%

I also tried with another serial monitor app (coolterm), just to avoid any possible problems with Platformio, and I get the same results.

From: Boris Jäger notifications@github.com Reply to: sinricpro/esp8266-esp32-sdk reply@reply.github.com Date: Sunday, 10 January 2021 at 19:38 To: sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Gabriele Rizzi gabriele.rizzi@smartsol.it, Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

Serial Monitor is configured in platformio.ini too, monitor_speed = xxxxxx monitor_port = COMyy Baudrate must match the same settings as used in sketch. When using platformio, you have to remove the debug defines in sketch sketch:

define ENABLE_DEBUG

ifdef ENABLE_DEBUG

define DEBUG_ESP_PORT Serial

define NODEBUG_WEBSOCKETS

define NDEBUG

endif

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

sgrizzi commented 3 years ago

Hi Boris,

Solved.

I have no clue as to why this happens, but if I copy your platformio.ini file from github, just editing the bare minimum, then debugging works fine.

My platformio.ini, which is including the same items, does not work!

Thanks for your support and patience.

Gabriele

From: Gabriele Rizzi gabriele.rizzi@smartsol.it Date: Sunday, 10 January 2021 at 20:13 To: sinricpro/esp8266-esp32-sdk reply@reply.github.com, sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

I found the problem – but now I have another one!!

Checking SinricProDebug.h I realized that DEBUG_ESP_PORT was not seen as active.

At the bottom of the .ini file I had used another build_flags option to generate a linker map and probably this entry was “erasing” the first one with the debug flags.

Now this problem is fixed but the code does not compile. ?!?

I get a series of these errors:

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h: In member function 'void websocketListener::setExtraHeaders()':

.pio/libdeps/ESP32/SinricPro/src/SinricProDebug.h:13:41: error: expected primary-expression before '.' token

define DEBUG_SINRIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )

                                     ^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h:92:3: note: in expansion of macro 'DEBUG_SINRIC'

DEBUG_SINRIC("[SinricPro:Websocket]: headers: \r\n%s\r\n", headers.c_str());

^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h: In member function 'void websocketListener::begin(String, String, String, SinricProQueue_t*)':

.pio/libdeps/ESP32/SinricPro/src/SinricProDebug.h:13:41: error: expected primary-expression before '.' token

define DEBUG_SINRIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )

                                     ^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h:113:3: note: in expansion of macro 'DEBUG_SINRIC'

DEBUG_SINRIC("[SinricPro:Websocket]: Connecting to WebSocket Server (%s)\r\n", server.c_str());

^

.pio/libdeps/ESP32/SinricPro/src/SinricProWebsocket.h: In member function 'void websocketListener::webSocketEvent(WStype_t, uint8_t*, size_t)':

.pio/libdeps/ESP32/SinricPro/src/SinricProDebug.h:13:41: error: expected primary-expression before '.' token

define DEBUG_SINRIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )

From: Gabriele Rizzi gabriele.rizzi@smartsol.it Date: Sunday, 10 January 2021 at 19:48 To: sinricpro/esp8266-esp32-sdk reply@reply.github.com, sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

This is really weird… here is my config in platformio.ini (I am using a Mac)

upload_speed = 921600

monitor_speed = 115200

upload_port = /dev/cu.SLAB_USBtoUART

monitor_port = /dev/cu.SLAB_USBtoUART

The option monitor_port was not there before. I added it and nothing changed.

I had already removed the “define…” block in the original sketch.

Serial output does work. Here the end of the initialization:

finished restoring EEPROM

[Wifi]: Connecting via Autoconnect Started, IP:192.168.1.76

Scanning BLE...

hopefully scanning in the background...

Connected to SinricPro

Temperaturesensor turned on (via SinricPro)

Temperature: 0.0 Celsius.Humidity: 0.0%

I also tried with another serial monitor app (coolterm), just to avoid any possible problems with Platformio, and I get the same results.

From: Boris Jäger notifications@github.com Reply to: sinricpro/esp8266-esp32-sdk reply@reply.github.com Date: Sunday, 10 January 2021 at 19:38 To: sinricpro/esp8266-esp32-sdk esp8266-esp32-sdk@noreply.github.com Cc: Gabriele Rizzi gabriele.rizzi@smartsol.it, Author author@noreply.github.com Subject: Re: [sinricpro/esp8266-esp32-sdk] problems when porting code from Arduino to Platformio (#124)

Serial Monitor is configured in platformio.ini too, monitor_speed = xxxxxx monitor_port = COMyy Baudrate must match the same settings as used in sketch. When using platformio, you have to remove the debug defines in sketch sketch:

define ENABLE_DEBUG

ifdef ENABLE_DEBUG

define DEBUG_ESP_PORT Serial

define NODEBUG_WEBSOCKETS

define NDEBUG

endif

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.