Comments (19)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
i thinks this are strange network effects, but the question is where they coming from.
from arduinowebsockets.
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.
the new code only sends one TCP package, before it where two.
but why one TCP package needs 200ms, is strange.
from arduinowebsockets.
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.
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.
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.
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.
" => \" like this ..
from arduinowebsockets.
Related Issues (20)
- Using sim800l module with websockets
- Client Certificate Authentication on ESP32?
- WebSocketsServer causes memory leak - WiFiServer is not destroyed
- to long message
- How many clients connected? HOT 1
- esp8266 unable to connect websocket server wss://xyz.com
- problem in mocpp_initialize() function. HOT 1
- Possible hint at how to close connections. HOT 1
- WebSocketsClient.cpp begin() error HOT 1
- I can not connect Heroku Server
- Use a buffer pool HOT 4
- WebSocket with AT commands (GSM model: Quectel EC25)
- Async with Socket.IO disconnects and reconnects repeatedly HOT 1
- Conflict when using with pn532. HOT 2
- WebSocketsClient - Return in Void-Function and also toString not found? HOT 3
- Connecting as a client to another ESP8266 hosting Async websocket server is failing on long messages. HOT 1
- Serial Monitor Garbage datas
- Can we describe the behavior of disconnect/autoreconnect and according action HOT 2
- Disconnection detection issue HOT 11
- The error code is not compiled: 'class WiFiServer' does not have a member named 'accept' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinowebsockets.