-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting a error from the TCPServer using the Arduino GIGA R1 WIFI on the ESP-32Client code. #145
Comments
Please help as quickly as possible i really need this to work fast :-) |
Any update on this? |
A little late with this, but I have had some success adapting the Portenta H7 code from the WebSockets2_Generic library to use with GIGA R1 WiFi. Since no other websocket support for this board is apparently available, and this library itself is archived read-only by the author, I have created a fork: https://github.com/cpp-tutor/WebSockets2_Generic Basic usage (header-only functionality so dependencies not needed): #define WEBSOCKETS_USE_GIGA_R1_WIFI 1
#include <WiFi.h>
#include <WebSockets2_Generic.h> Any comments, queries or problems, please raise an issue there. |
hello sir @cpp-tutor I have a project related to websockets on Arduino Giga R1 WiFi and I am trying to use solution you provided. But I still get the same error as in the main issue
here is my code. I took the reference from Portenta H7 code from the WebSockets2_Generic (as you mentioned) : #define WEBSOCKETS_USE_GIGA_R1_WIFI 1
// #include <WiFi.h>
#include <WebSockets2_Generic.h>
using namespace websockets2_generic;
const char* ssid = "my_wifi";
const char* password = "my_password";
const char* websockets_server_host = "192.xxx.x.x"; // since i use in localhost
const uint16_t websockets_server_port = 3000;
WebsocketsClient client;
int status = WL_IDLE_STATUS;
void onEventsCallback(WebsocketsEvent event, String data) {
(void)data;
if (event == WebsocketsEvent::ConnectionOpened) {
Serial.println("Connnection Opened");
} else if (event == WebsocketsEvent::ConnectionClosed) {
Serial.println("Connnection Closed");
} else if (event == WebsocketsEvent::GotPing) {
Serial.println("Got a Ping!");
} else if (event == WebsocketsEvent::GotPong) {
Serial.println("Got a Pong!");
}
}
void setup() {
Serial.begin(9600);
while (!Serial && millis() < 5000)
;
Serial.print("\nStarting Portenta_H7-Client using WiFi on ");
Serial.println(BOARD_NAME);
Serial.println(WEBSOCKETS2_GENERIC_VERSION);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}
Serial.print(F("Connecting to SSID: "));
Serial.println(ssid);
status = WiFi.begin(ssid, password);
delay(1000);
// attempt to connect to WiFi network
while (status != WL_CONNECTED) {
delay(500);
// Connect to WPA/WPA2 network
status = WiFi.status();
}
if (WiFi.status() == WL_CONNECTED) {
Serial.print("Connected to Wifi, IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Connecting to WebSockets Server @");
Serial.println(websockets_server_host);
} else {
Serial.println("\nNo WiFi");
return;
}
// run callback when messages are received
client.onMessage([&](WebsocketsMessage message) {
Serial.print("Got Message: ");
Serial.println(message.data());
});
// run callback when events are occuring
client.onEvent(onEventsCallback);
sendMessage();
}
void sendMessage() {
// try to connect to Websockets server
bool connected = client.connect(websockets_server_host, websockets_server_port, "/");
if (connected) {
Serial.println("Connected!");
String WS_msg = String("Hello to Server from ") + BOARD_NAME;
client.send(WS_msg);
} else {
Serial.println("Not Connected!");
}
}
void loop() {
// let the websockets client check for incoming messages
if (client.available()) {
client.poll();
}
} Maybe there's something I'm missing or there's something wrong with my approach ? |
Hi @AfdulRohmat I have successfully compiled your code above on my machine, so could I ask if you are definitely using my fork of Websockets2_Generic instead of the upstream (and Arduino repo) version? If you are still having difficulties please contact me. |
Hello Mr. @cpp-tutor . Apologize for my late response I used the official library on Arduino as shown in the image above. Could the problem be caused by this ? since I think the library is from the original version which does not support Arduino Giga R1 Do I have to manually install the library you forked to Arduino? |
Hi @AfdulRohmat In reply, yes you will need to perform a manual install. This involves going to https://github.com/cpp-tutor/WebSockets2_Generic and choosing "Code <> --> Download ZIP". Then in Arduino IDE 2.x choose "Sketch --> Include Library --> Add .ZIP Library" and navigate to the saved zip file (you may want to uninstall the existing WebSockets2_Generic library first). You should then see version "1.14.0" in the list of installed libraries (your screenshot above shows "1.13.2"). I believe following this process will fully solve your issue. Regards, Richard |
Hi Mr @cpp-tutor I see, thank you very much for the instruction, i will try those instruction very soon and also update the result, hopefully it can works |
Hi mr @cpp-tutor I've tried updating the library and it successfully compiled! But I got a new problem where I can't connect to localhost from my server. I have entered my IPv4 address in the websockets_server_host variable but it still doesn't work Previously I had tried running my websocket project in postman and it works smoothly Note: WiFi connection is successfully connected |
Hi @AfdulRohmat Thank you for your feedback, I'm glad that you got your code compiling. I must confess that I didn't either flash or run your code, but one thing I did notice is that the method You might like to take a look at my two other Arduino projects in order to see working code using this library, in particular "pforth" which hosts a web-based terminal. The original author has made the upstream repo read-only so raising issues either there or on my fork is not possible, and this isn't really the best place to go into more detail, so if you are still having problems please email me directly or raise an issue on "pforth". Regards, Richard |
Hi, sorry for the late response aswell. I managed to get a client working with the arduinohttpclient library for the giga. Unfortunately i’m running into some difficulties there aswell such as it needing a immideate response message to perform a handshake. I will try your solution tomorrow, does it still work? |
Hi @cpp-tutor i am trying to connect to a signalR websocketServer of mine, that protocol is a bit different because it expects a message to perform a handshake. Do you perhaps know a way to fix this? |
Hi @markieboy223,I'm afraid I don't have any ideas about how to solve your specific problem. My fork simply adapts the Portenta H7 code to GIGA, which works for my own purposes.You could try asking the upstream author who may be able to assist further.https://github.com/khoih-prog/WebSockets_Generic
|
Hi, no worries i fixed it. Did some deep diving into the websocketclient.hpp and it works now. Protocol for signalR is different so it required some adjustment. Also i noticed it’s wss and not ws so that needed to be declared in the client.connect() |
@cpp-tutor Are you able to pass the websocketclient into a .h and .cpp file with you sketch somehow? Main.ino
SocketHandler.h:
SocketHandler.cpp: #include "SocketHandler.h"
Gives this error: C:\Users\markv\AppData\Local\Temp\arduino\sketches\C38A2398EBE09833B4D8B55F206493C8\sketch\sketch_aug1a.ino.cpp.o: In function exit status 1 Compilation error: exit status 1 |
Hi @markieboy223,
Apologies for the late reply. The only answer I have is to declare and define SocketHandler entirely within the sketch, in case you haven't done this already. This would then avoid the multiple inclusion problem?
Regards
On 6 Aug 2024 12:52, Mark van der Burg ***@***.***> wrote:
@cpp-tutor Are you able to pass the websocketclient into a .h and .cpp file with you sketch somehow?
|
Pretty late to this, but i managed to move the sockethandler to the main.ino. That fixed it. |
@cpp-tutor Right now im working on a solution with Ethernet, does this libary support that? And do you perhaps have any examples? So using: |
Describe the bug
error: expected ')' before '' token
WebsocketsServer(network::TcpServer server = new WSDefaultTcpServer);
error: 'TcpServer' in namespace 'websockets::network' does not name a type
network::TcpServer* _server;
To Reproduce
Steps to reproduce the behavior.
This should include:
Expected behavior
To connect to the given websocketserver and receive my helloworld message from the websocketserver.
Code
Im using the File->Examples->ArduinoWebsockets->Esp-32Client code.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: