Code Monkey home page Code Monkey logo

Comments (19)

yuwenyangfeng avatar yuwenyangfeng commented on May 22, 2024 1

Dear Markus,
I wanna use /webSocket.sendTXT();/ API like
char a='x'; webSocket.sendTXT("s%",a);
just like print() use string. but I got string is %s.
how can send string and inster number or variable.
may you can give me some suggestion.

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024 1

on ESP you can do:

#include <StreamString.h>


StreamString data;
char a='x';
data.printf("%c",a);
webSocket.sendTXT(data);

on AVR this will not work.

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

a delay of around ~12ms is what I get on my network.
for the test I send a message from the ESP to the server (node.js) and then echo it back.
https://github.com/Links2004/arduinoWebSockets/blob/master/tests/webSocketServer/index.js

may try to send every loop is overkill for the ESP network stack which leads to an delay,
you can try to send every 15ms.

void loop() {
    static unsigned long l = 0;
    unsigned long t = millis();
    if((t - l) > 15) {
        webSocket.sendTXT("1");
        l = t;
    }
    webSocket.loop();
}

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

Thanks for the reply. Using your Node script I was able to improve the latency from ~400 to 200. It looks like the difference is that your code sends a reply message. Mine was not sending anything back. I am not sure why that improves performance, but it does. I tried your code with and without the throttling, and it doesn't to effect the speed at all.

Still I am still getting results that are significantly slower than yours. Do you have the arduino code posted somewhere? Maybe I am doing something else wrong on that front.

Thanks for this library. I imagine it will be very helpful for alot of people.

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

for testing i use the example.
wit this line active.
https://github.com/Links2004/arduinoWebSockets/blob/master/examples/WebSocketClient/WebSocketClient.ino#L42
the server sends a "welcome" message this message is send then in ping pong style.
you can add a

Serial.println(millis());

the half of the difference between too prints is the time for one message.
(the message go client --> server --> client)

server:
https://github.com/Links2004/arduinoWebSockets/blob/master/tests/webSocketServer/index.js
if you like you can measure at nodejs level too. result shut be the same.

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

I get the same results as before. Still taking around 200ms between messages. The chip is sitting about 2 feet from the router, and other devices can communicate significantly faster. I can can receive data significantly faster on the chip when I run it as the socket server.

Any ideas why there is such a large difference between my results and yours? I am using Adafruit's Huzzah board. Which one are you using?

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

i use bare ESP12 with minimal resistor setup.

you can test:

extern "C" {
#include <user_interface.h>
}


void setup() {
..........
 wifi_set_sleep_type(NONE_SLEEP_T);
}

may it helps, on my VNC project it increases the possible data rate.
(my ws tests are without it)

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

Sadly, that made no appreciable difference in response time. I have tried it on two different chips. I'll try it on another network and see if there is any difference

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

I did the test again with NONE_SLEEP and git version of the ESP core.
results are amazing:

[WSc][11584] get text(20): Connection accepted.
[WSc][11585] get text(20): Connection accepted.
[WSc][11588] get text(20): Connection accepted.
[WSc][11590] get text(20): Connection accepted.
[WSc][11592] get text(20): Connection accepted.
[WSc][11594] get text(20): Connection accepted.
[WSc][11596] get text(20): Connection accepted.
[WSc][11598] get text(20): Connection accepted.
[WSc][11600] get text(20): Connection accepted.
[WSc][11602] get text(20): Connection accepted.

non sleep brings me down to <=1ms for one direction.

    Serial.printf("[WSc][%d] get text(%u): %s\n", millis(), lenght, payload);

may its better for you network with this change:
ff33056

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

I just updated to the latest version. Wow. Talk about a difference. Went from 200 ms in between messages down to 1-3 ms.

You kick ass. Thanks for all your work on this.

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

It doesn't really matter, but if I just send data from the esp to the server and don't have the server respond with anything the message time goes from 1ms up to 200ms. Do you know what that is about?

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

i thinks this are strange network effects, but the question is where they coming from.

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

Prior to your last update, it was taking 400 ms to send messages (with no response), and now its 200, so it seems like whatever you changed was in the ball park.

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

the new code only sends one TCP package, before it where two.
but why one TCP package needs 200ms, is strange.

from arduinowebsockets.

greengiant83 avatar greengiant83 commented on May 22, 2024

Does your new code apply to the websocketserver class as well? I am trying to get two esp to communicate now. I have the server replying to each message, but it seems to get bogged down now.

from arduinowebsockets.

Links2004 avatar Links2004 commented on May 22, 2024

yes it for the server too, all functions in the WebSockets.cpp are shared.
I tested it with the LEDcontrol example, what is the exact problem, server dont answer? or is it slow?

from arduinowebsockets.

yuwenyangfeng avatar yuwenyangfeng commented on May 22, 2024

My think is the same as you:

unsigned int i = 0;     //declare one int

void setup() {
  Serial.begin(9600);
}

void loop() {
  String Str;           //declare one string
  char buffer[50];      //declare array
  sprintf(buffer, "the current value is %d", i++);
  Serial.println(buffer);
  Str = buffer;
  Serial.println(Str);
  delay(1000);
}

from arduinowebsockets.

zykovkirill avatar zykovkirill commented on May 22, 2024

Hello. Im need help. How to send json data on the server. im can send this data format:
webSocket.sendTXT("{"type":"usermsg","name":"d","message":"nu","color":"null"}");
but when i send this data
webSocket.sendTXT("{"type":"usermsg","name":"%c %s",'d',"","message":"nu","color":"null"}"); server dont read this data

from arduinowebsockets.

Slayer4477 avatar Slayer4477 commented on May 22, 2024

" => \" like this ..

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.