skaarj1989 / mWebSockets

WebSockets for microcontrollers
https://skaarj1989.github.io/mWebSockets/autobahn-testsuite/servers/
MIT License
108 stars 23 forks source link

TinyGSM #64

Closed trickyau closed 1 year ago

trickyau commented 1 year ago

Any idea if it's possible to use TinyGSM library with this library?

skaarj1989 commented 1 year ago

I managed to compile with TinyGSM, but I cannot test it.

How to make it work?

Finally you can use it this way:

TinyGsm modem(SerialAT);
WebSocketClient client(TinyGsmClient{modem});
trickyau commented 1 year ago

Sorry if this is a stupid question, but where exactly should overloaded constructor be placed?

If I place it it before or after default lines I get an compile error expecting 0 arguments, 1 provided.

WebSocketClient() = default; ~WebSocketClient() = default;

skaarj1989 commented 1 year ago

I would add it between the default constructor and the destructor. https://github.com/skaarj1989/mWebSockets/blob/eeeb71f06048b4a0807113df5fc302d044be5368/src/WebSocketClient.h#L19

trickyau commented 1 year ago

I'm probably doing something wrong on my end, but I have place overload between L18 and L19 I still run into same issue.

WebSocketClient.h:19:3: note: candidate: 'net::WebSocketClient::WebSocketClient()' WebSocketClient.h:19:3: note: candidate expects 0 arguments, 1 provided

I'm also seeing this which I assume is probably related to the above.

error: no matching function for call to 'net::WebSocketClient::WebSocketClient(TinyGsmClient)' WebSocketClient client(TinyGsmClient{modem});

skaarj1989 commented 1 year ago

Try the GSM branch.

trickyau commented 1 year ago

Slight improvement with that branch but still running into following. WiFI compiles fine, GSM does not.

c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.cpp: In member function 'void net::WebSocket::_send(uint8_t, bool, bool, const char*, uint16_t)':
c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.cpp:271:36: error: invalid conversion from 'char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]
     bytesWritten += m_client.write(maskingKey, 4);
                                    ^~~~~~~~~~
In file included from c:\Users\tricky\Documents\Arduino\libraries\TinyGSM\src/TinyGsmClientSIM7600.h:25,
                 from c:\Users\tricky\Documents\Arduino\libraries\TinyGSM\src/TinyGsmClient.h:55,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\platform.h:72,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\utility.h:3,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.h:5,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.cpp:1:
c:\Users\tricky\Documents\Arduino\libraries\TinyGSM\src/TinyGsmTCP.tpp:110:33: note:   initializing argument 1 of 'size_t TinyGsmTCP<modemType, muxCount>::GsmClient::write(const uint8_t*, size_t) [with modemType = TinyGsmSim7600; unsigned char muxCount = 10; size_t = unsigned int; uint8_t = unsigned char]'
     size_t write(const uint8_t* buf, size_t size) override {
                  ~~~~~~~~~~~~~~~^~~
c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.cpp:282:24: error: invalid conversion from 'const char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]
         m_client.write(reinterpret_cast<const char *>(data), length);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from c:\Users\tricky\Documents\Arduino\libraries\TinyGSM\src/TinyGsmClientSIM7600.h:25,
                 from c:\Users\tricky\Documents\Arduino\libraries\TinyGSM\src/TinyGsmClient.h:55,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\platform.h:72,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\utility.h:3,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.h:5,
                 from c:\Users\tricky\Documents\Arduino\libraries\mWebSockets\src\WebSocket.cpp:1:
c:\Users\tricky\Documents\Arduino\libraries\TinyGSM\src/TinyGsmTCP.tpp:110:33: note:   initializing argument 1 of 'size_t TinyGsmTCP<modemType, muxCount>::GsmClient::write(const uint8_t*, size_t) [with modemType = TinyGsmSim7600; unsigned char muxCount = 10; size_t = unsigned int; uint8_t = unsigned char]'
     size_t write(const uint8_t* buf, size_t size) override {
                  ~~~~~~~~~~~~~~~^~~
skaarj1989 commented 1 year ago

Can you give more information about your environment? IDE, compiler, c++ version, etc.?

trickyau commented 1 year ago

I'm using plan old Arduino IDE version 2.1.1. Not sure if I makes any difference but TinyGSM is 0.11.7.

skaarj1989 commented 1 year ago

In my environment these errors are just warnings. Just apply reinterpret_cast<const uint8_t *>(...);

trickyau commented 1 year ago

That did allow me to compile and run my code, I did however have to change handshake request to be sent as one, rather than multiple lines.

My only remaining issue, after handshake there is 0 bytes written to the connection which server assumes client has disconnected and drops the connection..

skaarj1989 commented 1 year ago

AFAIK, After the handshake, a server cannot "assume" a client connection status (the only thing it can do is send a ping frame). Are you sure that the server accepted the client handshake? What kind of server do you have?

trickyau commented 1 year ago

The server is something I wrote in php years ago and runs a bunch of my personal projects fine..

Unfortunately.. detecting timed out streams in php is a pain, if I get feof or 0 bytes from fread I assume client is timed out and close the connection which has worked fine over the years until now.

skaarj1989 commented 1 year ago

Could you please check this one?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.