RTOS problem with nopoll websockets

harryzz
Posts: 2
Joined: Sun Dec 06, 2015 7:08 pm

RTOS problem with nopoll websockets

Postby harryzz » Sat Dec 19, 2015 6:29 pm

Hello
someone tested nopoll lib. I can't establish connection with nopoll_conn_new() - every time i get error.
For example
conn = nopoll_conn_new(ctx, "echo.websocket.org", "80", "echo.websocket.org:80", "ws://echo.websocket.org:80/", NULL, "null");

this work without problem with nopoll lib under windows. but on ESP with latest RTOS not. And the example included also not work.


br
harry

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: RTOS problem with nopoll websockets

Postby ESP_Faye » Mon Dec 21, 2015 11:25 am

Hi,

Could it work with Espressif Cloud ?

faintu
Posts: 1
Joined: Thu Dec 31, 2015 4:24 pm

Re: RTOS problem with nopoll websockets

Postby faintu » Thu Dec 31, 2015 4:37 pm

The included websocket demo causes system crash -- of course it will cause crash, as it declares 512 bytes stack space, and then it immediately declares a 1024 byte local array in function test_04a. Are all the examples coming along with the RTOS sdk ever built and run????

also, the libnopoll will not work, because it won't generate the handshake key correctly. Why do I know this, simply build and run the following code:

extern char * nopoll_conn_produce_accept_key(noPollCtx * ctx, const char * websocket_key);
char* key = nopoll_conn_produce_accept_key(ctx, "3WazH0uwf9nfcy5VNmasrw==");
printf("KEY:%s\n", key);
nopoll_free(key);

The expected result response key should be "yKyGAgJvgbG9GY8gjdicbpl3HWs=", but it actually returns "udQnQPAff9nfcy5VNmasrw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11". Why is that? Because the libnopoll.a is compiled with wrong SHA1 result buffer size, which is defined as "ESP_EVP_MAX_MD_SIZE 6". It should be at least 20.

Since I don't have access to the code,I don't know if there is any other errors, but please, when you release an "SDK" with examples, build and run them!

this is totally a waste of time!

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: RTOS problem with nopoll websockets

Postby ESP_Faye » Mon Jan 04, 2016 1:53 pm

Hi,

Sorry for the inconvenience.

Please have a try with this new demo as the attachment.
Attachments
websocket_demo.zip
(425.51 KiB) Downloaded 723 times

dsbaha
Posts: 5
Joined: Fri Jan 22, 2016 3:06 pm

Re: RTOS problem with nopoll websockets

Postby dsbaha » Fri Jan 22, 2016 3:23 pm

I, too, have wasted countless amount of hours trying to get this to work to only get a "Sec-Websocket-Accept" mismatch error due to the invalid SHA1 calculation of the key. When will a patched version of libnopoll.a be released? I don't see anything special/different in the "websocket_demo.zip" file either.

dsbaha
Posts: 5
Joined: Fri Jan 22, 2016 3:06 pm

Re: RTOS problem with nopoll websockets

Postby dsbaha » Sat Jan 23, 2016 2:25 pm

Hi, instead of waiting for a patched libnopoll, I just made my own patch.

execute xtensa-lx106-elf-objcopy -W nopoll_conn_produce_accept_key libnopoll.a libnopoll2.a

Edit makefile to link libnopoll2.a (instead of the default one).

Put the following in your source code (or just a new .c file);

Code: Select all

include <nopoll/nopoll.h>
#include "ssl_compat-1.0.h"
#include "esp_common.h"

char ICACHE_FLASH_ATTR * nopoll_conn_produce_accept_key(noPollCtx * ctx, const char * websocket_key)
{
  if(websocket_key == NULL) return;

  const char * static_guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
  char * accept_key = NULL;
  int accept_key_size, key_length;

  key_length = strlen(websocket_key);

  unsigned char buffer[SHA1_SIZE];
  SHA1_CTX mdctx;
  unsigned int md_len = SHA1_SIZE;

  accept_key_size = key_length + 36 + 1;
  accept_key      = nopoll_new(char, accept_key_size);

  memcpy(accept_key, websocket_key, key_length);
  memcpy(accept_key + key_length, static_guid, 36);

  SHA1_Init(&mdctx);
  SHA1_Update(&mdctx, accept_key, strlen(accept_key));
  SHA1_Final(buffer, &mdctx);

  nopoll_base64_encode((const char *)buffer, md_len, (char *)accept_key, &accept_key_size);

  return accept_key;
}

bool ICACHE_FLASH_ATTR check_websocket_auth_response(bool print)
{
  bool result = FALSE;
  char * expected_result = "HSmrc0sMlYUkAGmm5OPpG2HaGWk="; //Wikipedia Sample Response
  char * websocket_key_test = nopoll_conn_produce_accept_key(NULL, "x3JJHMbDL1EzLkh9GBhXDw=="); //Wikipedia Sample   
  if(memcmp(expected_result, websocket_key_test, 28) == 0) result = TRUE;
  if(print) printf("Websocket Auth Response %s\nExpected: %s\nReturned: %s\n", result ? "Passed" : "Failed", expected_result, websocket_key_test);
  nopoll_free(websocket_key_test);
  return result;
}


works great!!

JasonWan
Posts: 4
Joined: Sun Nov 15, 2015 4:43 pm

ESP8266 RTOS SDK v1.4.0 websocke连不上

Postby JasonWan » Sun Nov 06, 2016 10:53 am

ESP8266 RTOS SDK v1.4.0连不上云端,是怎么回事?
单独测试连接ws://iot.espressif.cn:9000也连不上,难道espressif的云端现在不支持websocket了?

JasonWan
Posts: 4
Joined: Sun Nov 15, 2015 4:43 pm

Re: RTOS problem with nopoll websockets

Postby JasonWan » Sun Nov 06, 2016 10:56 am

编译了android-websocket_v1.0.0,安装到手机上,也连接不到云端。
试了wss://iot.espressif.cn:9443改为ws://iot.espressif.cn:9000,都连不上。
espressif的云端不支持websocket了?

Who is online

Users browsing this forum: No registered users and 59 guests