khoih-prog / WebSockets_Generic

WebSocket / Socket.IO Server and Client for Arduino based on RFC6455. Now supporting Adafruit nRF52, Portenta_H7, STM32F/L/H/G/WB/MP1, Teensy, SAM DUE, SAMD21, SAMD51, Arduino SAMD21 (Nano 33 IoT), MKR1000 / MKR1010WiFi, RP2040-based boards using WiFi101, WiFiNINA, WiFi, Ethernet, WT32_ETH01, Teensy 4.1 NativeEthernet/QNEthernet or Portenta_H7 WiFi/Ethernet, etc. so that those boards can be voice-controlled by Alexa. Now supporting websocket only mode for Socket.IO. Ethernet_Generic library is used as default for W5x00
GNU General Public License v3.0
90 stars 22 forks source link

Socket.io client on Teensy Native Ethernet not working on Websockets_Generic #12

Closed mechatroniks-git closed 3 years ago

mechatroniks-git commented 3 years ago

Describe the bug Getting compiler warnings, not seeing any packets from Teensy using this code, only modified the IP server address(192.168.1.187) and Port (3000)

Steps to Reproduce Steps to reproduce the behavior. Including the MRE sketches

Expected behavior Expected to see TCP packets from teensy on Wireshark

Actual behavior Can ping teensy, and see the pings on wireshark

Debug and AT-command log (if applicable) Arduino compiler

Teensy_WebSocketClientSocketIO_NativeEthernet:84: warning: #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error 
   #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
    ^
In file included from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic.h:56:0,
                 from C:\Users\me\GitHub\Arduino\Teensy_WebSocketClientSocketIO_NativeEthernet\Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic.h:231:4: warning: #warning Use Teensy in WebSockets_Generic [-Wcpp]
   #warning Use Teensy in WebSockets_Generic
    ^
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic.h:516:4: warning: #warning Using Teensy 4.1 NativeEthernet Library [-Wcpp]
   #warning Using Teensy 4.1 NativeEthernet Library
    ^
In file included from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic.h:718:0,
                 from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic.h:56,
                 from C:\Users\me\GitHub\Arduino\Teensy_WebSocketClientSocketIO_NativeEthernet\Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic-Impl.h:74:6: warning: #warning No CORE_HAS_LIBB64 [-Wcpp]
     #warning No CORE_HAS_LIBB64
      ^
In file included from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic.h:236:0,
                 from C:\Users\me\GitHub\Arduino\Teensy_WebSocketClientSocketIO_NativeEthernet\Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h:303:4: warning: #warning WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC [-Wcpp]
   #warning WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC
    ^
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h:420:6: warning: #warning Not HAS_SSL [-Wcpp]
     #warning Not HAS_SSL
      ^
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h: In member function 'virtual void WebSocketsClient::clientDisconnect(WSclient_t*)':
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h:729:20: warning: deleting object of polymorphic class type 'EthernetClient' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
     delete client->tcp;
                    ^
Opening Teensy Loader...
Memory Usage on Teensy 4.1:
  FLASH: code:235564, data:75072, headers:7276   free for files:7808552
   RAM1: variables:40100, code:95512, padding:2792   free for local variables:385884
   RAM2: variables:12416  free for malloc/new:511872

Teensy serial output:

Start Teensy_WebSocketClientSocketIO_NativeEthernet on TEENSY 4.1 with Custom Ethernet using Teensy 4.1 NativeEthernet Library
WebSockets_Generic v2.7.0
[WS] Board :TEENSY 4.1, setCsPin:10
[WS] Default SPI pinout:
[WS] MOSI:11
[WS] MISO:12
[WS] SCK:13
[WS] SS:10
[WS] =========================
WebSockets Client @ IP address: 192.168.1.117
Connecting to WebSockets Server @ IP address: 192.168.1.187, port: 3000
[WS] WebSockets_Generic v2.7.0
[WS] [wsIOc] found EIO=4 disable EIO ping on client
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":45237}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":77261}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":109285}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":141309}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":173333}]

Ping:

ping 192.168.1.117

Pinging 192.168.1.117 with 32 bytes of data:
Reply from 192.168.1.117: bytes=32 time=1ms TTL=64
Reply from 192.168.1.117: bytes=32 time=1ms TTL=64
Reply from 192.168.1.117: bytes=32 time=1ms TTL=64
Reply from 192.168.1.117: bytes=32 time=1ms TTL=64

Ping statistics for 192.168.1.117:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 1ms, Average = 1ms

Wireshark image

Screenshots If applicable, add screenshots to help explain your problem.

Information Please ensure to specify the following:

Arduino IDE version:1.8.15 TeensyDuino: 1.54 Beta9 Contextual information: looking to confirm packets are being sent Anything that might be relevant in your opinion, such as: Windows 10, firewall disabled MINGW32_NT-6.2 MPC 1.0.8(0.46/3/2) 2002-12-09 07:58 i686 unknown Unifi network, Teensy hardwired Ethernet, PC is wifi

khoih-prog commented 3 years ago

Hi @mechatroniks-git

Thanks for your detailed report. I'm able to reproduce the issue and has a fix, which is a bug in the NativeEthernet library.

This is the debug terminal with the bug fix

Start Teensy_WebSocketClientSocketIO_NativeEthernet on TEENSY 4.1 with Custom Ethernet using Teensy 4.1 NativeEthernet Library
WebSockets_Generic v2.7.0
[WS] Board :TEENSY 4.1, setCsPin:10
[WS] Default SPI pinout:
[WS] MOSI:11
[WS] MISO:12
[WS] SCK:13
[WS] SS:10
[WS] =========================
WebSockets Client @ IP address: 192.168.2.103
Connecting to WebSockets Server @ IP address: 192.168.2.30, port: 8080
[WS] WebSockets_Generic v2.7.0
[WS] [wsIOc] found EIO=4 disable EIO ping on client
[WS] [WS-Client][connectedCb] Connected to Host:192.168.2.30, Port:8080
[WS] [WS-Client] [sendHeader] Sending header...
[WS] sendHeader: client->cKey = 1lTomU5X6SGDGrlASxqOlg==
[WS] [WS-Client] [sendHeader] Handshake:GET /socket.io/?EIO=4&transport=polling HTTP/1.1
Host: 192.168.2.30:8080
Connection: keep-alive
Authorization: 1234567890
User-Agent: arduino-WebSocket-Client

[WS] [WS-Client] [sendHeader] Sending header... Done (us):18
Teensy4 Stream.cpp: HTTP/1.1 200 OK

[WS] [WS-Client][handleHeader] RX:HTTP/1.1 200 OK
Teensy4 Stream.cpp: Content-Type: text/plain; charset=UTF-8

[WS] [WS-Client][handleHeader] RX:Content-Type: text/plain; charset=UTF-8
Teensy4 Stream.cpp: Content-Length: 97

[WS] [WS-Client][handleHeader] RX:Content-Length: 97
Teensy4 Stream.cpp: Date: Tue, 22 Jun 2021 04:21:26 GMT

[WS] [WS-Client][handleHeader] RX:Date: Tue, 22 Jun 2021 04:21:26 GMT
Teensy4 Stream.cpp: Connection: keep-alive

[WS] [WS-Client][handleHeader] RX:Connection: keep-alive
Teensy4 Stream.cpp: 

[WS] [WS-Client][handleHeader] Header read fin.
[WS] [WS-Client][handleHeader] Client settings:
[WS] [WS-Client][handleHeader] - cURL:/socket.io/?EIO=4
[WS] [WS-Client][handleHeader] - cKey:1lTomU5X6SGDGrlASxqOlg==
[WS] [WS-Client][handleHeader] Server header:
[WS] [WS-Client][handleHeader] - cCode:200
[WS] [WS-Client][handleHeader] - cIsUpgrade:0
[WS] [WS-Client][handleHeader] - cIsWebsocket:1
[WS] [WS-Client][handleHeader] - cAccept:
[WS] [WS-Client][handleHeader] - cProtocol:arduino
[WS] [WS-Client][handleHeader] - cExtensions:
[WS] [WS-Client][handleHeader] - cVersion:0
[WS] [WS-Client][handleHeader] - cSessionId:
[WS] [WS-Client][handleHeader] Still missing cSessionId try Socket.IO
[WS] [WS-Client][handleHeader] socket.io json: 0{"sid":"mJ7XjZxZ9y7mglEMAAAE","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":20000}
[WS] [WS-Client][handleHeader] - cSessionId: mJ7XjZxZ9y7mglEMAAAE
[WS] [WS-Client][handleHeader] Header read fin.
[WS] [WS-Client][handleHeader] Client settings:
[WS] [WS-Client][handleHeader] - cURL:/socket.io/?EIO=4
[WS] [WS-Client][handleHeader] - cKey:1lTomU5X6SGDGrlASxqOlg==
[WS] [WS-Client][handleHeader] Server header:
[WS] [WS-Client][handleHeader] - cCode:200
[WS] [WS-Client][handleHeader] - cIsUpgrade:0
[WS] [WS-Client][handleHeader] - cIsWebsocket:1
[WS] [WS-Client][handleHeader] - cAccept:
[WS] [WS-Client][handleHeader] - cProtocol:arduino
[WS] [WS-Client][handleHeader] - cExtensions:
[WS] [WS-Client][handleHeader] - cVersion:0
[WS] [WS-Client][handleHeader] - cSessionId:mJ7XjZxZ9y7mglEMAAAE
[WS] [WS-Client][handleHeader] found cSessionId
[WS] [WS-Client] [sendHeader] Sending header...
[WS] sendHeader: client->cKey = J6xa1VolBawqnU5fa9lzJA==
[WS] [WS-Client] [sendHeader] Handshake:GET /socket.io/?EIO=4&transport=websocket&sid=mJ7XjZxZ9y7mglEMAAAE HTTP/1.1
Host: 192.168.2.30:8080
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: J6xa1VolBawqnU5fa9lzJA==
Sec-WebSocket-Protocol: arduino
Authorization: 1234567890
User-Agent: arduino-WebSocket-Client

[WS] [WS-Client] [sendHeader] Sending header... Done (us):24
Teensy4 Stream.cpp: HTTP/1.1 101 Switching Protocols

[WS] [WS-Client][handleHeader] RX:HTTP/1.1 101 Switching Protocols
Teensy4 Stream.cpp: Upgrade: websocket

[WS] [WS-Client][handleHeader] RX:Upgrade: websocket
Teensy4 Stream.cpp: Connection: Upgrade

[WS] [WS-Client][handleHeader] RX:Connection: Upgrade
Teensy4 Stream.cpp: Sec-WebSocket-Accept: sO/BRUZNURqRtg5PRdwhYqh3AqY=

[WS] [WS-Client][handleHeader] RX:Sec-WebSocket-Accept: sO/BRUZNURqRtg5PRdwhYqh3AqY=
Teensy4 Stream.cpp: Sec-WebSocket-Protocol: arduino

[WS] [WS-Client][handleHeader] RX:Sec-WebSocket-Protocol: arduino
Teensy4 Stream.cpp: 

[WS] [WS-Client][handleHeader] Header read fin.
[WS] [WS-Client][handleHeader] Client settings:
[WS] [WS-Client][handleHeader] - cURL:/socket.io/?EIO=4
[WS] [WS-Client][handleHeader] - cKey:J6xa1VolBawqnU5fa9lzJA==
[WS] [WS-Client][handleHeader] Server header:
[WS] [WS-Client][handleHeader] - cCode:101
[WS] [WS-Client][handleHeader] - cIsUpgrade:1
[WS] [WS-Client][handleHeader] - cIsWebsocket:1
[WS] [WS-Client][handleHeader] - cAccept:sO/BRUZNURqRtg5PRdwhYqh3AqY=
[WS] [WS-Client][handleHeader] - cProtocol:arduino
[WS] [WS-Client][handleHeader] - cExtensions:
[WS] [WS-Client][handleHeader] - cVersion:0
[WS] [WS-Client][handleHeader] - cSessionId:mJ7XjZxZ9y7mglEMAAAE
[WS] [WS-Client][handleHeader] Websocket connection init done.
[WS] [wsIOc] Connected to url:/socket.io/?EIO=4
[IOc] Connected to url: /socket.io/?EIO=4
[WS] [wsIOc] get pong
[WS] [wsIOc] connected: len = 30
[WS] [wsIOc] data: {"sid":"O-W7fLFpMB4lvdAFAAAF"}

and the server response

Server launched on port 8080
Connected
PFWRz8S-WJiSVgMDAAAB
JWT token test:  { host: '192.168.2.30:8080',
  connection: 'keep-alive',
  authorization: '1234567890',
  'user-agent': 'arduino-WebSocket-Client' }
Message from Client :  { now: 30001 }
Connected
9KPN0j5G-7nA8e4TAAAD
JWT token test:  { host: '192.168.2.30:8080',
  connection: 'keep-alive',
  authorization: '1234567890',
  'user-agent': 'arduino-WebSocket-Client' }
Disconnected
Message from Client :  { now: 30001 }
Connected
O-W7fLFpMB4lvdAFAAAF
JWT token test:  { host: '192.168.2.30:8080',
  connection: 'keep-alive',
  authorization: '1234567890',
  'user-agent': 'arduino-WebSocket-Client' }
Message from Client :  { now: 30001 }
Disconnected
Message from Client :  { now: 60002 }
Message from Client :  { now: 90003 }
Message from Client :  { now: 120004 }
Message from Client :  { now: 150005 }

I'll post the fix or create a PR for the NativeEthernet later

But now, you can modify the NativeDns.cpp#L50-L79 as follows:

int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult, uint16_t timeout)
{
  // See if it's a numeric IP address
  if (inet_aton(aHostname, aResult)) 
  {
    // It is, our work here is done
    return 1;
  }

  resolveDone = 0;
  struct fnet_dns_params dns_params = 
  {
    .dns_server_addr = 
    {
    .sa_family = AF_INET,
    .sa_port = FNET_CFG_DNS_PORT,
    .sa_scope_id = fnet_netif_get_scope_id(fnet_netif_get_default()),
    .sa_data = {iDNSServer[0], iDNSServer[1], iDNSServer[2], iDNSServer[3]}
    },

    .host_name = aHostname,
    .addr_family = AF_INET,
    .callback = fnet_dns_callback,
    .cookie = this
  };

  fnet_dns_desc_t fnet_dns_desc = fnet_dns_init(&dns_params);

  if(fnet_dns_desc == FNET_NULL)
  {
    return 0;
  }

  while(resolveDone == 0)
  {
  }

  if(resolveDone == -1) 
    return 0;
  else if(resolveDone == 1) 
  {
  aResult = resolvedIP;
  return 1;
  }

  return 0 ;
}
khoih-prog commented 3 years ago

The PR has been created for NativeEthernet library as Fix the DNS bug #21

mechatroniks-git commented 3 years ago

Hey @khoih-prog, I've updated the NativeEthernet inside my Arduino folder (C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\NativeEthernet\src). I'm getting the same issue.

Compile warnings (are these expected?):

Teensy_WebSocketClientSocketIO_NativeEthernet:84: warning: #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error 
   #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
    ^
In file included from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic.h:56:0,
                 from C:\Users\me\GitHub\Arduino\Teensy_WebSocketClientSocketIO_NativeEthernet\Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic.h:231:4: warning: #warning Use Teensy in WebSockets_Generic [-Wcpp]
   #warning Use Teensy in WebSockets_Generic
    ^
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic.h:516:4: warning: #warning Using Teensy 4.1 NativeEthernet Library [-Wcpp]
   #warning Using Teensy 4.1 NativeEthernet Library
    ^
In file included from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic.h:718:0,
                 from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic.h:56,
                 from C:\Users\me\GitHub\Arduino\Teensy_WebSocketClientSocketIO_NativeEthernet\Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSockets_Generic-Impl.h:74:6: warning: #warning No CORE_HAS_LIBB64 [-Wcpp]
     #warning No CORE_HAS_LIBB64
      ^
In file included from C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic.h:236:0,
                 from C:\Users\me\GitHub\Arduino\Teensy_WebSocketClientSocketIO_NativeEthernet\Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h:303:4: warning: #warning WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC [-Wcpp]
   #warning WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC
    ^
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h:420:6: warning: #warning Not HAS_SSL [-Wcpp]
     #warning Not HAS_SSL
      ^
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h: In member function 'virtual void WebSocketsClient::clientDisconnect(WSclient_t*)':
C:\Users\me\GitHub\Arduino\libraries\WebSockets_Generic\src/WebSocketsClient_Generic-Impl.h:729:20: warning: deleting object of polymorphic class type 'EthernetClient' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
     delete client->tcp;
                    ^
Memory Usage on Teensy 4.1:
  FLASH: code:235756, data:75072, headers:8108   free for files:7807528
   RAM1: variables:40100, code:95704, padding:2600   free for local variables:385884
   RAM2: variables:12416  free for malloc/new:511872

Serial output

Start Teensy_WebSocketClientSocketIO_NativeEthernet on TEENSY 4.1 with Custom Ethernet using Teensy 4.1 NativeEthernet Library
WebSockets_Generic v2.7.0
[WS] Board :TEENSY 4.1, setCsPin:10
[WS] Default SPI pinout:
[WS] MOSI:11
[WS] MISO:12
[WS] SCK:13
[WS] SS:10
[WS] ========================|
WebSockets Client @ IP address: 192.168.1.119
Connecting to WebSockets Server @ IP address: 192.168.1.199, port: 8080
[WS] WebSockets_Generic v2.7.0
[WS] [wsIOc] found EIO=4 disable EIO ping on client
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":49307}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":89309}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":129311}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!

I setup a SocketIO server on 192.168.1.199 port 8080, firewall off. Used the 2nd server example from here. Nothing coming out of the Teensy on wireshark, I do see the ping responses as before.

khoih-prog commented 3 years ago

Hi,

Those warnings are intentional and correct.

I have no idea about what you're doing wrong or which steps /patches (Teensy core / NativeEthernet library / patches) you're missing as I have no problem at all as you can see the previously posted terminal output.

Teensy, especially with still not-yet-matured NativeEthernet, really creates many unsolved and hard-to-solve problems. I'm currently having no time and enough interest to investigate.

Be sure to check that the following are installed / patched correctly. I'm afraid I can't help you any further with my crystal ball.

  1. Packages' Patches for Teensy boards
  2. Use this Stream.cpp to replace ./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.cpp

Stream.h

/*
  Stream.h - base class for character-based streams.
  Copyright (c) 2010 David A. Mellis.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef Stream_h
#define Stream_h

#include <inttypes.h>
#include "Print.h"

class Stream : public Print
{
  public:
    constexpr Stream() : _timeout(1000), read_error(0) {}
    virtual int available() = 0;
    virtual int read() = 0;
    virtual int peek() = 0;

    void setTimeout(unsigned long timeout);
    bool find(const char *target);

    bool find(const uint8_t *target) 
    {
      return find ((const char *)target);
    }

    bool find(const String &target) 
    {
      return find(target.c_str());
    }

    bool find(const char *target, size_t length);

    bool find(const uint8_t *target, size_t length) 
    {
      return find ((const char *)target, length);
    }

    bool find(const String &target, size_t length) 
    {
      return find(target.c_str(), length);
    }

    bool findUntil(const char *target, const char *terminator);

    bool findUntil(const uint8_t *target, const char *terminator) 
    {
      return findUntil((const char *)target, terminator);
    }

    bool findUntil(const String &target, const char *terminator) 
    {
      return findUntil(target.c_str(), terminator);
    }

    bool findUntil(const char *target, const String &terminator) 
    {
      return findUntil(target, terminator.c_str());
    }

    bool findUntil(const String &target, const String &terminator) 
    {
      return findUntil(target.c_str(), terminator.c_str());
    }

    bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);

    bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) 
    {
      return findUntil((const char *)target, targetLen, terminate, termLen);
    }

    bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
    bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
    bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);

    long parseInt();
    long parseInt(char skipChar);

    float parseFloat();
    float parseFloat(char skipChar);

    size_t readBytes(char *buffer, size_t length);

    size_t readBytes(uint8_t *buffer, size_t length) 
    {
      return readBytes((char *)buffer, length);
    }

    size_t readBytesUntil(char terminator, char *buffer, size_t length);

    size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) 
    {
      return readBytesUntil(terminator, (char *)buffer, length);
    }

    ////////////////////////////////////////////////////////////
    String readString(size_t max = 512);
    String readStringUntil(char terminator, size_t max = 512);

    // KH, to not use String
    char* readCharsUntil(char terminator, size_t max = 512);
    ////////////////////////////////////////////////////////////

    int getReadError() 
    {
      return read_error;
    }

    void clearReadError() 
    {
      setReadError(0);
    }

  protected:
    void setReadError(int err = 1) 
    {
      read_error = err;
    }

    unsigned long _timeout;

    // KH
    int timedRead();
    //////

  private:
    char read_error;

    //int timedRead();

    int timedPeek();
    int peekNextDigit();
};

#endif

Stream.cpp

/*
 Stream.cpp - adds parsing methods to Stream class
 Copyright (c) 2008 David A. Mellis.  All right reserved.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 Created July 2011
 parsing functions based on TextFinder library by Michael Margolis
 */

#include <Arduino.h>

#define PARSE_TIMEOUT 1000  // default number of milli-seconds to wait
#define NO_SKIP_CHAR  1  // a magic char not found in a valid ASCII numeric field

// private method to read stream with timeout
int Stream::timedRead()
{
  int c;
  unsigned long startMillis = millis();

  do
  {
    c = read();

    if (c >= 0)
      return c;

    yield();
  } while (millis() - startMillis < _timeout);

  Serial.print(("timedRead timeout = "));
  Serial.println(_timeout);

  return -1;     // -1 indicates timeout
}

// private method to peek stream with timeout
int Stream::timedPeek()
{
  int c;
  unsigned long startMillis = millis();

  do
  {
    c = peek();

    if (c >= 0)
      return c;

    yield();
  } while (millis() - startMillis < _timeout);

  return -1;     // -1 indicates timeout
}

// returns peek of the next digit in the stream or -1 if timeout
// discards non-numeric characters
int Stream::peekNextDigit()
{
  int c;

  while (1)
  {
    c = timedPeek();

    if (c < 0)
      return c;  // timeout

    if (c == '-')
      return c;

    if (c >= '0' && c <= '9')
      return c;

    read();  // discard non-numeric
  }
}

// Public Methods
//////////////////////////////////////////////////////////////

void Stream::setTimeout(unsigned long timeout)  // sets the maximum number of milliseconds to wait
{
  _timeout = timeout;
}

// find returns true if the target string is found
bool  Stream::find(const char *target)
{
  return findUntil(target, NULL);
}

// reads data from the stream until the target string of given length is found
// returns true if target string is found, false if timed out
bool Stream::find(const char *target, size_t length)
{
  return findUntil(target, length, NULL, 0);
}

// as find but search ends if the terminator string is found
bool  Stream::findUntil(const char *target, const char *terminator)
{
  if (target == nullptr)
    return true;

  size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);

  return findUntil(target, strlen(target), terminator, tlen);
}

// reads data from the stream until the target string of the given length is found
// search terminated if the terminator string is found
// returns true if target string is found, false if terminated or timed out
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
{
  size_t index = 0;  // maximum target string length is 64k bytes!
  size_t termIndex = 0;
  int c;

  if ( target == nullptr)
    return true;

  if ( *target == 0)
    return true;  // return true if target is a null string

  if (terminator == nullptr)
    termLen = 0;

  while ( (c = timedRead()) > 0)
  {
    if ( c == target[index])
    {
      //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
      if (++index >= targetLen)
      {
        // return true if all chars in the target match
        return true;
      }
    }
    else
    {
      index = 0;  // reset index if any char does not match
    }

    if (termLen > 0 && c == terminator[termIndex])
    {
      if (++termIndex >= termLen)
        return false;       // return false if terminate string found before target string
    }
    else
      termIndex = 0;
  }

  return false;
}

// returns the first valid (long) integer value from the current position.
// initial characters that are not digits (or the minus sign) are skipped
// function is terminated by the first character that is not a digit.
long Stream::parseInt()
{
  return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
}

// as above but a given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
long Stream::parseInt(char skipChar)
{
  boolean isNegative = false;
  long value = 0;
  int c;

  c = peekNextDigit();

  // ignore non numeric leading characters
  if (c < 0)
    return 0; // zero returned if timeout

  do
  {
    if (c == skipChar)
      ; // ignore this charactor
    else if (c == '-')
      isNegative = true;
    else if (c >= '0' && c <= '9')       // is c a digit?
      value = value * 10 + c - '0';

    read();  // consume the character we got with peek
    c = timedPeek();
  }
  while ( (c >= '0' && c <= '9') || c == skipChar );

  if (isNegative)
    value = -value;

  return value;
}

// as parseInt but returns a floating point value
float Stream::parseFloat()
{
  return parseFloat(NO_SKIP_CHAR);
}

// as above but the given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
float Stream::parseFloat(char skipChar)
{
  boolean isNegative = false;
  boolean isFraction = false;
  long value = 0;
  int c;
  float fraction = 1.0;

  c = peekNextDigit();

  // ignore non numeric leading characters
  if (c < 0)
    return 0; // zero returned if timeout

  do
  {
    if (c == skipChar)
      ; // ignore
    else if (c == '-')
      isNegative = true;
    else if (c == '.')
      isFraction = true;
    else if (c >= '0' && c <= '9')
    {
      // is c a digit?
      value = value * 10 + c - '0';

      if (isFraction)
        fraction *= 0.1f;
    }

    read();  // consume the character we got with peek
    c = timedPeek();
  }
  while ( (c >= '0' && c <= '9')  || c == '.' || c == skipChar );

  if (isNegative)
    value = -value;

  if (isFraction)
    return value * fraction;
  else
    return value;
}

// read characters from stream into buffer
// terminates if length characters have been read, or timeout (see setTimeout)
// returns the number of characters placed in the buffer
// the buffer is NOT null terminated.
//
size_t Stream::readBytes(char *buffer, size_t length)
{
  if (buffer == nullptr)
    return 0;

  size_t count = 0;

  while (count < length)
  {
    int c = timedRead();

    if (c < 0)
    {
      setReadError();
      break;
    }

    *buffer++ = (char)c;
    count++;
  }

  return count;
}

// as readBytes with terminator character
// terminates if length characters have been read, timeout, or if the terminator character  detected
// returns the number of characters placed in the buffer (0 means no valid data found)

size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
{
  if (buffer == nullptr)
    return 0;

  if (length < 1)
    return 0;

  length--;
  size_t index = 0;

  while (index < length)
  {
    int c = timedRead();

    if (c == terminator)
      break;

    if (c < 0)
    {
      setReadError();
      break;
    }

    *buffer++ = (char)c;
    index++;
  }

  *buffer = 0;
  return index; // return number of characters, not including null terminator
}

#if 1
// From nRF52

String Stream::readString(size_t max)
{
  String ret;
  int c = timedRead();

  while (c >= 0)
  {
    ret += (char)c;
    c = timedRead();
  }

  return ret;
}

char readStringBuffer[2048];

char* Stream::readCharsUntil(char terminator, size_t max)
{
  uint16_t offset = 0;

  int c = timedRead();

  readStringBuffer[offset++] = c;

  while (c >= 0 && c != terminator)
  {
    c = timedRead();

    readStringBuffer[offset++] = c;
  }

  readStringBuffer[offset] = 0;

  return readStringBuffer;
}

String Stream::readStringUntil(char terminator, size_t max)
{
  String ret;
  uint16_t offset = 0;

  int c = timedRead();

  readStringBuffer[offset++] = c;

  while (c >= 0 && c != terminator)
  {
    c = timedRead();

    readStringBuffer[offset++] = c;
  }

  readStringBuffer[offset] = 0;

  ret = String(readStringBuffer);

  Serial.print(F("Teensy4 Stream.cpp: "));
  Serial.println(ret);

  return String(readStringBuffer);
}

#else

String Stream::readString(size_t max)
{
  String str;
  size_t length = 0;

  while (length < max)
  {
    int c = timedRead();

    if (c < 0)
    {
      setReadError();
      break;  // timeout
    }

    if (c == 0)
      break;

    str += (char)c;
    length++;
  }

  return str;
}

String Stream::readStringUntil(char terminator, size_t max)
{
  String str;
  size_t length = 0;

  while (length < max)
  {
    int c = timedRead();

    if (c < 0)
    {
      setReadError();
      break;  // timeout
    }

    if (c == 0 || c == terminator)
      break;

    str += (char)c;
    length++;
  }

  // MR fix
  if(str.length()==0) str="\0";

  return str;
}
#endif
khoih-prog commented 3 years ago

I'm using this SIO server, included with the library Nodejs_SocketIO_TestServer

khoih-prog commented 3 years ago

Just test with Teensy core v1.54beta10 and Arduino v1.8.15 and it's still working well

Compiler Output

/home/kh/Arduino/khoih-prog_working/WebSockets_Generic_GitHub/examples/Teensy/NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet.ino:84:4: warning: #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error [-Wcpp]
   #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
    ^
In file included from /home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic.h:56:0,
                 from /home/kh/Arduino/khoih-prog_working/WebSockets_Generic_GitHub/examples/Teensy/NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSockets_Generic.h:231:4: warning: #warning Use Teensy in WebSockets_Generic [-Wcpp]
   #warning Use Teensy in WebSockets_Generic
    ^
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSockets_Generic.h:516:4: warning: #warning Using Teensy 4.1 NativeEthernet Library [-Wcpp]
   #warning Using Teensy 4.1 NativeEthernet Library
    ^
In file included from /home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSockets_Generic.h:718:0,
                 from /home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic.h:56,
                 from /home/kh/Arduino/khoih-prog_working/WebSockets_Generic_GitHub/examples/Teensy/NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSockets_Generic-Impl.h:74:6: warning: #warning No CORE_HAS_LIBB64 [-Wcpp]
     #warning No CORE_HAS_LIBB64
      ^
In file included from /home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic.h:236:0,
                 from /home/kh/Arduino/khoih-prog_working/WebSockets_Generic_GitHub/examples/Teensy/NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet/Teensy_WebSocketClientSocketIO_NativeEthernet.ino:126:
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic-Impl.h:309:4: warning: #warning WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC [-Wcpp]
   #warning WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC
    ^
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic-Impl.h:426:6: warning: #warning Not HAS_SSL [-Wcpp]
     #warning Not HAS_SSL
      ^
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic-Impl.h: In member function 'virtual void WebSocketsClient::clientDisconnect(WSclient_t*)':
/home/kh/Arduino/libraries/WebSockets_Generic-2.7.0/src/WebSocketsClient_Generic-Impl.h:735:20: warning: deleting object of polymorphic class type 'EthernetClient' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
     delete client->tcp;
                    ^
teensy_size: Memory Usage on Teensy 4.1:
teensy_size:   FLASH: code:235700, data:75072, headers:9192   free for files:7806500
teensy_size:    RAM1: variables:40100, code:95640, padding:2664   free for local variables:385884
teensy_size:    RAM2: variables:12416  free for malloc/new:511872
Sketch uses 174776 bytes (2%) of program storage space. Maximum is 8126464 bytes.
Global variables use 135732 bytes (25%) of dynamic memory, leaving 388556 bytes for local variables. Maximum is 524288 bytes.

NativeEthernet SIO Client

Start Teensy_WebSocketClientSocketIO_NativeEthernet on TEENSY 4.1 with Custom Ethernet using Teensy 4.1 NativeEthernet Library
WebSockets_Generic v2.7.0
[WS] Board :TEENSY 4.1, setCsPin:10
[WS] Default SPI pinout:
[WS] MOSI:11
[WS] MISO:12
[WS] SCK:13
[WS] SS:10
[WS] =========================
WebSockets Client @ IP address: 192.168.2.116
Connecting to WebSockets Server @ IP address: 192.168.2.30, port: 8080
[WS] WebSockets_Generic v2.7.0
[WS] [wsIOc] found EIO=4 disable EIO ping on client
[WS] [WS-Client][connectedCb] Connected to Host:192.168.2.30, Port:8080
[WS] [WS-Client] [sendHeader] Sending header...
[WS] sendHeader: client->cKey = JHxGz+EFdSxa6Mb9AFEzAg==
[WS] [WS-Client] [sendHeader] Handshake:GET /socket.io/?EIO=4&transport=polling HTTP/1.1
Host: 192.168.2.30:8080
Connection: keep-alive
Authorization: 1234567890
User-Agent: arduino-WebSocket-Client

[WS] [WS-Client] [sendHeader] Sending header... Done (us):19
[WS] [WS-Client][handleHeader] RX:HTTP/1.1 200 OK
[WS] [WS-Client][handleHeader] RX:Content-Type: text/plain; charset=UTF-8
[WS] [WS-Client][handleHeader] RX:Content-Length: 97
[WS] [WS-Client][handleHeader] RX:Date: Tue, 29 Jun 2021 22:01:47 GMT
[WS] [WS-Client][handleHeader] RX:Connection: keep-alive
[WS] [WS-Client][handleHeader] Header read fin.
[WS] [WS-Client][handleHeader] Client settings:
[WS] [WS-Client][handleHeader] - cURL:/socket.io/?EIO=4
[WS] [WS-Client][handleHeader] - cKey:JHxGz+EFdSxa6Mb9AFEzAg==
[WS] [WS-Client][handleHeader] Server header:
[WS] [WS-Client][handleHeader] - cCode:200
[WS] [WS-Client][handleHeader] - cIsUpgrade:0
[WS] [WS-Client][handleHeader] - cIsWebsocket:1
[WS] [WS-Client][handleHeader] - cAccept:
[WS] [WS-Client][handleHeader] - cProtocol:arduino
[WS] [WS-Client][handleHeader] - cExtensions:
[WS] [WS-Client][handleHeader] - cVersion:0
[WS] [WS-Client][handleHeader] - cSessionId:
[WS] [WS-Client][handleHeader] Still missing cSessionId try Socket.IO
[WS] [WS-Client][handleHeader] socket.io json: 0{"sid":"u6mgnv5wm5LrN0leAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":20000}
[WS] [WS-Client][handleHeader] - cSessionId: u6mgnv5wm5LrN0leAAAA
[WS] [WS-Client][handleHeader] Header read fin.
[WS] [WS-Client][handleHeader] Client settings:
[WS] [WS-Client][handleHeader] - cURL:/socket.io/?EIO=4
[WS] [WS-Client][handleHeader] - cKey:JHxGz+EFdSxa6Mb9AFEzAg==
[WS] [WS-Client][handleHeader] Server header:
[WS] [WS-Client][handleHeader] - cCode:200
[WS] [WS-Client][handleHeader] - cIsUpgrade:0
[WS] [WS-Client][handleHeader] - cIsWebsocket:1
[WS] [WS-Client][handleHeader] - cAccept:
[WS] [WS-Client][handleHeader] - cProtocol:arduino
[WS] [WS-Client][handleHeader] - cExtensions:
[WS] [WS-Client][handleHeader] - cVersion:0
[WS] [WS-Client][handleHeader] - cSessionId:u6mgnv5wm5LrN0leAAAA
[WS] [WS-Client][handleHeader] found cSessionId
[WS] [WS-Client] [sendHeader] Sending header...
[WS] sendHeader: client->cKey = D2lVAT+6DJTL652keZxVIw==
[WS] [WS-Client] [sendHeader] Handshake:GET /socket.io/?EIO=4&transport=websocket&sid=u6mgnv5wm5LrN0leAAAA HTTP/1.1
Host: 192.168.2.30:8080
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: D2lVAT+6DJTL652keZxVIw==
Sec-WebSocket-Protocol: arduino
Authorization: 1234567890
User-Agent: arduino-WebSocket-Client

[WS] [WS-Client] [sendHeader] Sending header... Done (us):26
[WS] [WS-Client][handleHeader] RX:HTTP/1.1 101 Switching Protocols
[WS] [WS-Client][handleHeader] RX:Upgrade: websocket
[WS] [WS-Client][handleHeader] RX:Connection: Upgrade
[WS] [WS-Client][handleHeader] RX:Sec-WebSocket-Accept: T24rdxNb6xZZ51NYE8YDXiB/mYE=
[WS] [WS-Client][handleHeader] RX:Sec-WebSocket-Protocol: arduino
[WS] [WS-Client][handleHeader] Header read fin.
[WS] [WS-Client][handleHeader] Client settings:
[WS] [WS-Client][handleHeader] - cURL:/socket.io/?EIO=4
[WS] [WS-Client][handleHeader] - cKey:D2lVAT+6DJTL652keZxVIw==
[WS] [WS-Client][handleHeader] Server header:
[WS] [WS-Client][handleHeader] - cCode:101
[WS] [WS-Client][handleHeader] - cIsUpgrade:1
[WS] [WS-Client][handleHeader] - cIsWebsocket:1
[WS] [WS-Client][handleHeader] - cAccept:T24rdxNb6xZZ51NYE8YDXiB/mYE=
[WS] [WS-Client][handleHeader] - cProtocol:arduino
[WS] [WS-Client][handleHeader] - cExtensions:
[WS] [WS-Client][handleHeader] - cVersion:0
[WS] [WS-Client][handleHeader] - cSessionId:u6mgnv5wm5LrN0leAAAA
[WS] [WS-Client][handleHeader] Websocket connection init done.
[WS] [wsIOc] Connected to url:/socket.io/?EIO=4
[IOc] Connected to url: /socket.io/?EIO=4
[WS] [wsIOc] get pong
[WS] [wsIOc] connected: len = 30
[WS] [wsIOc] data: {"sid":"P7Isy2B2k8G0uLHTAAAB"}

Server

Server launched on port 8080
Connected
P7Isy2B2k8G0uLHTAAAB
JWT token test:  { host: '192.168.2.30:8080',
  connection: 'keep-alive',
  authorization: '1234567890',
  'user-agent': 'arduino-WebSocket-Client' }
Message from Client :  { now: 30001 }
Message from Client :  { now: 60002 }
Message from Client :  { now: 90003 }
khoih-prog commented 3 years ago

You also can print more debugging messages by using in the sketch

#define _WEBSOCKETS_LOGLEVEL_     3
mechatroniks-git commented 3 years ago

@khoih-prog None of that worked.

I'm looking at my router logs now, I see the DHCP:

Jun 29 22:32:54 ubnt daemon.info dnsmasq-dhcp[2883]: DHCPDISCOVER(br0) de:ad:be:ef:fe:01
Jun 29 22:32:54 ubnt daemon.info dnsmasq-dhcp[2883]: DHCPOFFER(br0) 192.168.1.73 de:ad:be:ef:fe:01
Jun 29 22:32:54 ubnt daemon.info dnsmasq-dhcp[2883]: DHCPREQUEST(br0) 192.168.1.73 de:ad:be:ef:fe:01
Jun 29 22:32:54 ubnt daemon.info dnsmasq-dhcp[2883]: DHCPACK(br0) 192.168.1.73 de:ad:be:ef:fe:01

Nothing else, nothing in the firewall logs either. Any chance you can send me your .hex file? Set the server IP to 192.168.1.199

khoih-prog commented 3 years ago

Teensy_WebSocketClientSocketIO_NativeEthernet.ino.hex.zip

Can't connect as wrong Server address (192.168.1.199) for me

Start Teensy_WebSocketClientSocketIO_NativeEthernet on TEENSY 4.1 with Custom Ethernet using Teensy 4.1 NativeEthernet Library
WebSockets_Generic v2.7.0
[WS] Board :TEENSY 4.1, setCsPin:10
[WS] Default SPI pinout:
[WS] MOSI:11
[WS] MISO:12
[WS] SCK:13
[WS] SS:10
[WS] =========================
WebSockets Client @ IP address: 192.168.2.116
Connecting to WebSockets Server @ IP address: 192.168.1.199, port: 8080
[WS] WebSockets_Generic v2.7.0
[WS] [wsIOc] found EIO=4 disable EIO ping on client
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":40002}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
["event_name",{"now":80004}]
[IOc] Disconnected
[WS] [wsIOc] Disconnected!
khoih-prog commented 3 years ago

Are you sure your SIO server is working OK? Can you test it using a simple SIO client to be sure not wasting your time.

mechatroniks-git commented 3 years ago

Thanks for the hex file, same thing. I will try setting up SIO server on a raspberry pi next.

khoih-prog commented 3 years ago

I'm just running that Nodejs_SocketIO_TestServer on my Ubuntu PC/Laptop, same code will work on RPi (with Nodejs)

mechatroniks-git commented 3 years ago

Ok, @khoih-prog I setup the PI with that TestServer (192.168.1.9) and my python client (192.168.1.199) can connect, I see packets on wireshark.

image

Still nothing from the Teensy 4.1, I tried 2nd set of hardware that works fine with NativeEthernet sending UDP packets all day long.

I'm using the Teensy 4.1 with onboard Ethernet PHY chip, which is NOT connected via SPI, it has a RMII interface to the IMX chip. The PHY connects to Ethernet with one of these. Can you confirm your setup is the same?

Thanks.

khoih-prog commented 3 years ago

Same Ethernet MagJack kit.

I suggest you have to recheck everything individually (network, server, Teensy, NativeEthernet, etc.) to be sure everything is OK before moving forward. I'm thinking there is something wrong with your NativeEthernet (MagJack kit, wiring, solder, Teensy, etc.). Only you can figure this out, sorry.

TeensyWS

mechatroniks-git commented 3 years ago

@khoih-prog Thanks, you've been very helpful. I will keep at it, setup a dumb network, I'm thinking this Unifi UDM system is blocking packets.

khoih-prog commented 3 years ago

Hi @mechatroniks-git

FYI, you can also test and use this new release, using the new and much better QNEthernet Library for Teensy 4.1 built-in Ethernet


Major Releases v2.9.0

  1. Add support to QNEthernet Library for Teensy 4.1 built-in Ethernet
  2. Update examples with new features

Teensy_WebSocketClientSocketIO_QNEthernet on TEENSY 4.1 using QNEthernet

The following are debug terminal output when running example Teensy_WebSocketClientSocketIO_QNEthernet on TEENSY 4.1 using QNEthernet library

Client

Starting Teensy_WebSocketClient_QNEthernet on TEENSY 4.1 using QNEthernet
WebSockets_Generic v2.9.0
=========== USE_QN_ETHERNET ===========
Initialize Ethernet using static IP => Connected! IP address:192.168.2.222
Connecting to WebSockets Server @ IP address: 192.168.2.30, port: 8080
[IOc] Connected to url: /socket.io/?EIO=4
["event_name",{"now":30001}]
[IOc] Get event: ["Send Message io.emit Broadcasted : ",{"now":30001}]
[IOc] Get event: ["Send Message : ",{"now":30001}]
["event_name",{"now":60002}]
[IOc] Get event: ["Send Message io.emit Broadcasted : ",{"now":60002}]
[IOc] Get event: ["Send Message : ",{"now":60002}]
["event_name",{"now":90003}]
[IOc] Get event: ["Send Message io.emit Broadcasted : ",{"now":90003}]
[IOc] Get event: ["Send Message : ",{"now":90003}]

Server

Using the Socket.IO Server in Nodejs_SocketIO_TestServer

kh@kh-Inspiron-3593:~/Downloads/Nodejs/New_SIO$ ./SIO_server.sh 
Server launched on port 8080
Connected
bK733pVgbd3DCsy5AAAB
JWT token test:  { host: '192.168.2.30:8080',
  connection: 'keep-alive',
  authorization: '1234567890',
  'user-agent': 'arduino-WebSocket-Client' }
Message from Client :  { now: 30001 }
Message from Client :  { now: 60002 }
Message from Client :  { now: 90003 }