skaarj1989 / mWebSockets

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

Support for Arduino Due #40

Closed fkromer closed 3 years ago

fkromer commented 3 years ago

The Arduino Due uses an Atmel SAM3X8E processor. Would be great to have support for this MCU class as well.

fkromer commented 3 years ago

I'm available for beta testing btw ;-)

skaarj1989 commented 3 years ago

Have you tried to upload a client/server? I don't have any Due at the moment, so I can't test it. (but it compiles without errors, so it might work).

fkromer commented 3 years ago

Yes, I tried to upload the simple-server.ino via Programming (USB) Port.

In file included from C:\Users\Florian\Documents\Arduino\libraries\mWebSockets\src\base64\Base64.cpp:2:0:
C:\Users\Florian\Documents\Arduino\libraries\mWebSockets\src\base64\../platform.h:30:4: error: #error "Unsupported platform"
 #  error "Unsupported platform"
    ^
C:\Users\Florian\Documents\Arduino\libraries\mWebSockets\src\base64\Base64.cpp:8:24: fatal error: pgmspace.h: No such file or directory
 #  include <pgmspace.h>
                        ^
compilation terminated.
exit status 1
Error compiling for board Arduino Due (Programming Port).
skaarj1989 commented 3 years ago

Ok, it's my bad, I checked Duemilanove, almost the same ;) In order to get it working, you need to go into platform.h and add another define #define PLATFORM_ARCHITECTURE_SAM 6 then do the following modification:

// ...
#elif defined(ARDUINO_ARCH_SAM)
#  define PLATFORM_ARCH PLATFORM_ARCHITECTURE_SAM
# else
// ...
#endif

Next head into base64/Base64.cpp and do a little update:

#if (PLATFORM_ARCH == PLATFORM_ARCHITECTURE_AVR) ||                            \
  (PLATFORM_ARCH == PLATFORM_ARCHITECTURE_SAMD21) || (PLATFORM_ARCH == PLATFORM_ARCHITECTURE_SAM)
// ...

Now it should compile.

fkromer commented 3 years ago

@skaarj1989 No worries. In the simple-server.ino example I'm still getting some error.

WARNING: library mWebSockets claims to run on avr, esp8266, esp32, samd, stm32 architecture(s) and may be incompatible with your current board which runs on sam architecture(s).
C:\Users\Florian\AppData\Local\Temp\arduino_modified_sketch_755881\simple-server.ino: In lambda function:
simple-server:59:30: error: 'class net::WebSocket' has no member named 'getProtocol'
     const auto protocol = ws.getProtocol();
                              ^
simple-server:78:6: error: invalid user-defined conversion from 'setup()::__lambda0::__lambda1' to 'void (* const&)(net::WebSocket&, const net::WebSocket::DataType&, const char*, uint16_t) {aka void (* const&)(net::WebSocket&, const net::WebSocket::DataType&, const char*, short unsigned int)}' [-fpermissive]
     });
      ^
C:\Users\Florian\AppData\Local\Temp\arduino_modified_sketch_755881\simple-server.ino:66:56: note: candidate is: setup()::__lambda0::__lambda1::operator void (*)(net::WebSocket&, net::WebSocket::DataType, const char*, uint16_t)() const <near match>
                    const char *message, uint16_t length) {
                                                        ^
C:\Users\Florian\AppData\Local\Temp\arduino_modified_sketch_755881\simple-server.ino:66:56: note:   no known conversion for implicit 'this' parameter from 'void (*)(net::WebSocket&, net::WebSocket::DataType, const char*, uint16_t) {aka void (*)(net::WebSocket&, net::WebSocket::DataType, const char*, short unsigned int)}' to 'const onMessageCallback {aka void (* const)(net::WebSocket&, const net::WebSocket::DataType&, const char*, short unsigned int)}'
simple-server:78:6: error: invalid conversion from 'void (*)(net::WebSocket&, net::WebSocket::DataType, const char*, uint16_t) {aka void (*)(net::WebSocket&, net::WebSocket::DataType, const char*, short unsigned int)}' to 'void (*)(net::WebSocket&, const net::WebSocket::DataType&, const char*, uint16_t) {aka void (*)(net::WebSocket&, const net::WebSocket::DataType&, const char*, short unsigned int)}' [-fpermissive]
     });
      ^
simple-server:81:67: error: invalid user-defined conversion from 'setup()::__lambda0::__lambda2' to 'void (* const&)(net::WebSocket&, const net::WebSocket::CloseCode&, const char*, uint16_t) {aka void (* const&)(net::WebSocket&, const net::WebSocket::CloseCode&, const char*, short unsigned int)}' [-fpermissive]
                  uint16_t) { _SERIAL.println(F("Disconnected")); });
                                                                   ^
C:\Users\Florian\AppData\Local\Temp\arduino_modified_sketch_755881\simple-server.ino:81:26: note: candidate is: setup()::__lambda0::__lambda2::operator void (*)(net::WebSocket&, net::WebSocket::CloseCode, const char*, uint16_t)() const <near match>
                  uint16_t) { _SERIAL.println(F("Disconnected")); });
                          ^
C:\Users\Florian\AppData\Local\Temp\arduino_modified_sketch_755881\simple-server.ino:81:26: note:   no known conversion for implicit 'this' parameter from 'void (*)(net::WebSocket&, net::WebSocket::CloseCode, const char*, uint16_t) {aka void (*)(net::WebSocket&, net::WebSocket::CloseCode, const char*, short unsigned int)}' to 'const onCloseCallback {aka void (* const)(net::WebSocket&, const net::WebSocket::CloseCode&, const char*, short unsigned int)}'
simple-server:81:67: error: invalid conversion from 'void (*)(net::WebSocket&, net::WebSocket::CloseCode, const char*, uint16_t) {aka void (*)(net::WebSocket&, net::WebSocket::CloseCode, const char*, short unsigned int)}' to 'void (*)(net::WebSocket&, const net::WebSocket::CloseCode&, const char*, uint16_t) {aka void (*)(net::WebSocket&, const net::WebSocket::CloseCode&, const char*, short unsigned int)}' [-fpermissive]
                  uint16_t) { _SERIAL.println(F("Disconnected")); });
                                                                   ^
exit status 1
'class net::WebSocket' has no member named 'getProtocol'
skaarj1989 commented 3 years ago

Try master branch.

fkromer commented 3 years ago

WARNING: library mWebSockets-master claims to run on avr, esp8266, esp32, samd, stm32 architecture(s) and may be incompatible with your current board which runs on sam architecture(s).
Sketch uses 50396 bytes (9%) of program storage space. Maximum is 524288 bytes.
Atmel SMART device 0x285e0a60 found
Erase flash
done in 0.037 seconds

Write 52708 bytes to flash (206 pages)
[==============================] 100% (206/206 pages)
done in 10.669 seconds

Verify 52708 bytes of flash
[==============================] 100% (206/206 pages)
Verify successful
done in 10.364 seconds
Set boot flash true
CPU reset.
skaarj1989 commented 3 years ago

That warning is negligible. It comes from the library.json/.properties pair. Does it run correctly?

fkromer commented 3 years ago

Sorry, had something different to do. simple-server.ino works just fine 🚀 Thanks

stale[bot] commented 3 years 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.