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)".
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi.
I tried that code, but i just recieve unreadyable data at the server.
The result in the web-ide is like that:
That should be always the same message...
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:
In Browserconsole (Chrome) i entered "ws.send(hallo welt)".
Thanks.