-
-
Hi there, I am playing around with my DHT11 temperature sensor and my websocket server, I am using the Wemos d1 mini.
Here is my code:
var dht = require("DHT11").connect(D4); var WebSocket = require("ws"); var wifi = require("Wifi"); var WIFI_NAME = "MY WIFI NAME"; var WIFI_OPTIONS = { password : "MY WIFI PASSWORD" }; wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) { if (err) { console.log("Connection error: "+err); return; } console.log("Connected!"); var host = "MY IP"; var ws = new WebSocket(host, { path: '/', port: 80, // default is 80 protocol : "echo-protocol", // websocket protocol name (default is none) protocolVersion: 13, // websocket protocol version, default is 13 origin: 'Espruino', keepAlive: 600, (default is none) } ); ws.on('open', function() { console.log("Connected to server"); setInterval(function(){ dht.read(function (a) { ws.send('{"temp":"'+a.temp.toString()+'","rh":"'+a.rh.toString()+'"}'); }); },10000); }); });
Note: I have obviously hidden my wifi ssid, password and my IP in the code, just in case :)
If I upload this to the Wemos it will work as it should, my websocket server is receiving the messages and will display the temperature and the humidity every 10 second the message is sent.
But then once i save() this code onto the Wemos and reboot it, it starts showing this message every 10 second:
Uncaught Error: This socket is closed. at line 2 col 26 b,c+(this.masking?128:0)));126==c&&(this.socket.write(h(a.le... ^ in function "send" called from line 1 col 69 ...rh":"'+b.rh.toString()+'"}'); ^ in function "c" called from line 2 col 173 ...or:0<e,raw:b,temp:-1,rh:-1}) ^ in function called from system
What causes this problem? Seems like it has to do with the wifi module?
I have tried restarting the server and also the Wemos but the problem persists.Thanks
-
-
-
-
-
Hello
I have been playing around with my 8x8 LED matrix and for some reason when I use Espruino my 4th column (from the left) does not work, I know it is not a hardware issue because if I use the matrix with Arduino it works just fine.
SPI1.setup({mosi:D14, sck:D13}); var disp = require("MAX7219").connect(SPI1,D15); disp.intensity(0); var arr = [255,255,255,255,255,255,255,255]; disp.raw(arr);
Here is the code I use to test the display, also I'm not sure if the MAX7219 module is the best to use?
My board is the Wemos d1 mini
Thanks
-
-
Hello
Is it somehow possible to call a function you have saved on the ESP8266??For example:
I would like to save the stepper module on the ESP8266 so I am able to do stuff like:var motorLeft = new StepperMotor({ pins:[D0,D2,D4,D5], pattern:[0b0010,0b0001,0b0100,0b1000] });
without having to get the module off the web and upload it everytime.
The problem with this is that if I connect to the ESP8266 over wifi, my computer is no longer connected to the web and can therefore no longer get the module.And also, would it be possible to save something like this:
function forward(steps) { motorRight.moveTo(motorRight.getPosition()+steps, 1); motorLeft.moveTo(motorLeft.getPosition()-steps, 1); }
to the ESP8266, so that I can just send something like this: forward(1000);
Thanks :)
Thank you so much for the very thorough explanation and the great tips. People such as you are those who make communities great :)