gilmaimon / ArduinoWebsockets

A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
GNU General Public License v3.0
466 stars 96 forks source link

network::TcpServer* _server #162

Open dmtzs opened 3 months ago

dmtzs commented 3 months ago

Describe the bug receive this error:

In file included from c:\Users\diego\OneDrive\Documentos\Arduino\libraries\ArduinoWebsockets\src/ArduinoWebsockets.h:6:0,
                 from D:\github projects\Arduino\websocket\websocket.ino:2:
c:\Users\diego\OneDrive\Documentos\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/server.hpp:10:40: error: expected ')' before '*' token
     WebsocketsServer(network::TcpServer* server = new WSDefaultTcpServer);
                                        ^
c:\Users\diego\OneDrive\Documentos\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/server.hpp:26:14: error: 'TcpServer' in namespace 'websockets::network' does not name a type
     network::TcpServer* _server;
              ^~~~~~~~~

exit status 1

Compilation error: exit status 1

To Reproduce Only verifying the code used This should include:

Expected behavior Subscribed to the topic 1

Code

#include "WiFiS3.h"
#include <ArduinoWebsockets.h>
#include "arduino_secrets.h"  // Just a file to store secrets

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int status = WL_IDLE_STATUS;

const char* websockets_server_host = "0.0.0.0:8000/ws/<token>";

using namespace websockets;
WebsocketsClient client;

void onMessageCallback(WebsocketsMessage message) {
    Serial.print("Got Message: ");
    Serial.println(message.data());
}

void onEventsCallback(WebsocketsEvent event, String 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) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }

  printWifiStatus();

  client.connect(websockets_server_host);

  client.send("{\"topic\": \"topic1\", \"content\": \"Subscribing to topic1\"}");

  client.onMessage(handleMessage);
}

void loop() {
  client.poll();
}

void handleMessage(WebsocketsMessage message) {
  Serial.print("Received message: ");
  Serial.println(message.data());
}

void printWifiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Additional context Add any other context about the problem here.

dmtzs commented 3 months ago

Please help @gilmaimon , I'm following all the steps if I'm not wrong

dmtzs commented 1 month ago

any updates? @gilmaimon