Git Product home page Git Product logo

Comments (16)

cpp-tutor avatar cpp-tutor commented on August 18, 2024 1

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.

from arduinowebsockets.

cpp-tutor avatar cpp-tutor commented on August 18, 2024 1

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.

from arduinowebsockets.

cpp-tutor avatar cpp-tutor commented on August 18, 2024 1

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

from arduinowebsockets.

AfdulRohmat avatar AfdulRohmat commented on August 18, 2024 1

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

from arduinowebsockets.

markieboy223 avatar markieboy223 commented on August 18, 2024

Please help as quickly as possible i really need this to work fast :-)

from arduinowebsockets.

pawellen avatar pawellen commented on August 18, 2024

Any update on this?

from arduinowebsockets.

AfdulRohmat avatar AfdulRohmat commented on August 18, 2024

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

error: expected ')' before '*' token WebsocketsServer(network2_generic::TcpServer* server = new WSDefaultTcpServer); error: 'TcpServer' in namespace 'websockets2_generic::network2_generic' does not name a type network2_generic::TcpServer* _server;

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 ?

from arduinowebsockets.

AfdulRohmat avatar AfdulRohmat commented on August 18, 2024

image

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?

from arduinowebsockets.

AfdulRohmat avatar AfdulRohmat commented on August 18, 2024

image
image

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

from arduinowebsockets.

cpp-tutor avatar cpp-tutor commented on August 18, 2024

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 connect() should take the form ws://192.x.x.x according to the docs. Maybe you could try adding this to the websockets_server_host variable?

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

from arduinowebsockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.