Avatar for user65754

user65754

Member since Jun 2016 • Last active Jun 2016
  • 0 conversations
  • 4 comments

Most recent activity

  • in JavaScript
    Avatar for user65754

    I try to stream video data to the server to control 100 ws2812 leds.
    I tried to work with 1byte for each pixel, so the current limitations do not disturb.

    But i get no stable connection. Always if i send between 25 and 60 messages i get:

    WebSocket is already in CLOSING or CLOSED state.
    

    Would be really good so solve this problem first ;) If i couldn't get a reliable connection, i can't use that websocket implementation...

    Please have a look at it. Thanks.

  • in JavaScript
    Avatar for user65754

    Great to hear from you. Thank you for your response!

    Now it seems to work 95% :)

    Some of my tests:

    [WS] "hallo welt"
    [WS] "hallo welt 123"
    [WS] "123"
    [WS] "hallo welt 123"
    [WS] "[object Object]"
    [WS] "test"
    [WS] "{\"room\":\"room\",\"msg\":\"message\"}­"
    1: [WS] "\x14"
    2: [WS] "PUM\x1F\x1D\x00\x02O^M\x02\x1E\x15MUO\x­1F\n\x1C\x1E\x13\b\nO\x0Fe\x8Ah\"\xC9\x8­F\x13\x00\xBB\xE0\aO\xEB\xB5JP\xA6\xE0\x­05\x00\xE5\xAD\x05Q\xAE\xADR\x00\xA4\xEA­\x1BQ\xA8\xE8\r\x00\xB4\x94%Nw\x83y5U\xF­1\x16!\x1A\xA1Cl\x05\xEC\x16#U\xAF[#\x04­\xE4[tU\xEE\x1C=\x04\xE2\x1E+U\xFE;0=\x1­8=\xDAF:O\xB5Ru\x1F\xE0\x1FjR\xB5"
    [WS] "{\"room\":\"room\",\"msg\":\"message\"}­"
    [WS] "{\"room\":\"room\",\"msg\":\"message\"}­"
    [WS] "{\"room\":\"room\",\"msg\":\"message\"}­"
    

    The named lines (1,2) should be also the same message as before. My conclusion is, that i still get that "unreadable" data, if i wait a little bit.

    Start the WebSocket and send a Message -> OK
    Send more messages -> OK
    Wait a minute and send one message -> Unreadable Data
    send more messages -> Sometimes OK, timesomes unreadable
    send more messages -> everything OK

    So always if i wait a little bit it seems that the next data package can't processed successfully.

    If i wait for 5-10 Minutes and try to send a message from Chrome:

    WebSocket is already in CLOSING or CLOSED state.
    

    I would be really happy if you could check that again :)
    I will also try the capacitor for the ESP8266.

    Thank you!

    Edit: I looked at the ws.js file. Why you don't allow to send data bigger then 125 character? How can i send more than 125? I need to send more than 300 characters.

  • in JavaScript
    Avatar for user65754

    Next post...

  • in JavaScript
    Avatar for user65754

    Hi.

    I tried that code, but i just recieve unreadyable data at the server.

    ws.on('message',function(msg) { print("[WS] "+JSON.stringify(msg)); });
    

    The result in the web-ide is like that:

    [WS] "\xC7\xD3\x00\x00\xC7\xD3\x00\x00\xC7\xD­3"
    [WS] ""
    [WS] "\x1A\t\x00\x00\x1A\t\x00\x00\x1A\t"
    [WS] ""
    [WS] ""
    [WS] "/<\x00\x00/<\x00\x00/<"
    [WS] "bl\x1C\x00bl\x1C\x00bl"
    [WS] "R\x9E\xEF\x00R\x9E\xEF\x00R\x9E"
    [WS] "<C\x00\x00<C\x00\x00<C"
    [WS] "\xE9\xBC\x00\x00\xE9\xBC\x00\x00\xE9\xB­C"
    

    That should be always the same message...

    ws.send("hallo welt");
    

    What is wrong with the code? I run it with the pico VERSION 1v85 in combination with the esp8266.
    I hope someone can help me with that.

    In addition the connection interrupt all the time. Is there an easy solution for a stable connection? I want to send a lot of data from client to the server.

    FullCode:

    Serial2.setup(9600, {    rx: A3,    tx: A2}); 
    var wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
        if (err) throw err;
        wifi.reset(function(err) {
            if (err) throw err;
            console.log("Connecting to WiFi");
            wifi.connect("SSID", "12345", function(err) {
                if (err) throw err;
    
                var server = require('ws').createServer(onPageRequest­);
                server.listen(8000);
                server.on("websocket", function(ws) {
                    ws.on('message',function(msg) {
                      print("[WS] "+JSON.stringify(msg));
                    });
                    ws.on('open', function() {
                      ws.send("Connected to server!");
                    });
                    ws.send("Hello from Espruino!");
                });
            });
        });
    });
    var page = '<html><head><meta charset="utf-8"><title>WebSocket Client Test...</title></head><body><script>var ws;setTimeout(function(){';
    page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "text");';
    page += 'ws.onmessage = function (event) { console.log("MSG: "+event.data); };';
    page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);';
    page += '},1000);</script></body></html>';
    page += '</script></body></html>';
    function onPageRequest(req, res) {
        res.writeHead(200, {        'Content-Type': 'text/html'    });
        res.end(page);
    }
    

    In Browserconsole (Chrome) i entered "ws.send(hallo welt)".

    Thanks.

Actions