Git Product home page Git Product logo

Comments (4)

khoih-prog avatar khoih-prog commented on May 28, 2024

The example doesn't actually control the RGB LED, just a simple demo for WebSocket server.

To actually control the LEDs, you have to adapt the code from

https://github.com/Links2004/arduinoWebSockets/blob/323592f622e0ec8f9ce1f995c5777d9bbaaae1ec/examples/esp8266/WebSocketServerAllFunctionsDemo/WebSocketServerAllFunctionsDemo.ino#L28-L59

to receive command ( in msg.data() ) and contriol the LEDs yourself

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) 
{
  switch(type) 
  {
    case WStype_DISCONNECTED:
    
      Serial.printf("[%u] Disconnected!\n", num);
      
      break;
    
    case WStype_CONNECTED: 
      {
        IPAddress ip = webSocket.remoteIP(num);
        Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);

        // send message to client
        webSocket.sendTXT(num, "Connected");
      }
  
      break;
  
  case WStype_TEXT:
    Serial.printf("[%u] get Text: %s\n", num, payload);

    if(payload[0] == '#') 
    {
      // we get RGB data


      // decode rgb data
      uint32_t rgb = (uint32_t) strtol((const char *) &payload[1], NULL, 16);

      analogWrite(LED_RED, ((rgb >> 16) & 0xFF));
      analogWrite(LED_GREEN, ((rgb >> 8) & 0xFF));
      analogWrite(LED_BLUE, ((rgb >> 0) & 0xFF));
    }

    break;
  }
}

As I have no intention to do this, please use it as is or ignore the example

It maybe better to delete the example in the near future to avoid confusion.

Good Luck,

from websockets2_generic.

jnanneng2 avatar jnanneng2 commented on May 28, 2024

@khoih-prog

Do you have any working example of duplex socket communication using this library and a NANO RP2040 CONNECT? Everything I've tried does not work. The examples also seem to not work. The examples you linked to do not use this library, of which there are great differences in the implementation. I cannot find API documentation on this library (does that exist somewhere)?

Thus, kind of stuck; looking for some guidance as to how to get a duplex socket up and running with this library; with the server socket being hosted on the RP2040.

from websockets2_generic.

khoih-prog avatar khoih-prog commented on May 28, 2024

Try to switch to cheaper and faster RP2040W, using AsyncWebServer_RP2040W with arduino-pico core

from websockets2_generic.

MirkoGelsomini avatar MirkoGelsomini commented on May 28, 2024

@khoih-prog

Do you have any working example of duplex socket communication using this library and a NANO RP2040 CONNECT? Everything I've tried does not work. The examples also seem to not work. The examples you linked to do not use this library, of which there are great differences in the implementation. I cannot find API documentation on this library (does that exist somewhere)?

Thus, kind of stuck; looking for some guidance as to how to get a duplex socket up and running with this library; with the server socket being hosted on the RP2040.

I agree with @jnanneng2 , the code you are referring to seems to come from a different repo using a different library.
Can you share a full working example?

from websockets2_generic.

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.