-
I tried this on a ESP8266 where it is working with a ip address. In the docs it states the parameter should be 'hostname', but when I try with a hostname I get an error:
w.ping('google.com', (details) => { console.log(details) }); Uncaught Error: Not a valid IP address.
When I try this on a ESP32 I get:
w=require('Wifi') =function () { [native code] } >w.ping('212.51.158.12', (details) => { console.log(details) }); Uncaught Error: Function "ping" not found!
Both ESP's are running espruino 2v00
The ping method may work for me when it would be available on both platforms however it's somewhat tricky, because you can not decide how many pings are issued.
Where could I find the source code of the 'net' Library?
-
I am trying to make my things resistive to all sort of annoyances that can occour. Currently I am working on network disruptions, when the wireless router is still responsive but cannot connect to the internet. While I use websocket connections I saw that the websocket module wants to create a socket connection using net.connect(), but unfortunately I could not find any possibility to detect this condition in the documentation. I get just a message at the console:
ERROR: Connect failed (err 113) Uncaught InternalError: Unable to create socket
I don't know whether this is specific on the ESP32.
-
-
I tried to use a watch on a esp32 where I got the following error:
setWatch(function(st) { console.log(st.time) }, D4, {repeat: false, edge: 'falling', debounce: 10}); WARNING: Unable to set watch. You may already have a watch on a pin with the same number (eg. A0 and B0), or this pin cannot be used with watch
I also tried other pins which should work without luck. I am using esruino 2v00 on a esp32s chip. On espruino 2v01 i get the same message.
-
I want to call a method of the calling class within a module. This worked fine in Version 2v00 of espruino. After updating to 2v01 I get an error with the same code.
This is the calling program:
class a { constructor() { this.mB = null; } init() { this.mB = new (require('http://192.168.88.117:8081/b.js'))(this); this.mB.perform(); } say(text) { console.log(text); } } var x = new a(); x.init();
And this is the module:
class b { constructor(a) { this.a = a; } perform() { console.log('class b called'); this.a.say("I'm in b"); } } exports = b;
The output shows as follows:
Error: Line 8: Unexpected reserved word in http://192.168.88.117:8081/b.js > ____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v00 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate Flash map 4MB:512/512, manuf 0xef chip 0x4016 >class b called I'm in b Disconnected > Found ESP8266_4MB, 2v01 > Connected to COM4 Error: Line 8: Unexpected reserved word in http://192.168.88.117:8081/b.js > ____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v01 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate Flash map 4MB:512/512, manuf 0xef chip 0x4016 >class b called Uncaught Error: Cannot read property 'say' of undefined at line 2 col 11 this.a.say("I'm in b"); ^ in function "perform" called from line 10 col 21 this.mB.perform(); ^ in function "init" called from line 19 col 8 x.init(); ^ >
It seems that the parameter for the constructor is not passed anymore in 2v01
-
-
This is my module saver program. It works now and can be used to save modules stored on a webserver onto esp8266 flash memory. Start the program and then key in on the left side:
s.save('MyModule');class StModule { constructor () { this.st = require('Storage'); this.wifi = require('Wifi'); this.http = require('http'); this.server = null; } init (ssid, pw, server) { this.wifi.connect(ssid, {password: pw}, (err) => { if (err) { console.log('Connection error, cannot connect to ', ssid); } else { console.log('Connected to ', ssid); this.server = server; } }); } save(name) { var url = 'http://'+this.server+'/'+name+'.js'; this.st.erase(name); this.http.get(url, (res) => { var offset = 0; var sz = res.headers['Content-Length']; res.on('data', (data) => { this.st.write(name, data, offset, sz); offset += data.length; }); res.on('close', () => { console.log('Module '+name+' saved, size: '+this.st.read(name).length); console.log(this.st.list()); }); }); } show(name) { print(this.st.read(name)); } } exports = StModule; var s = new StModule(); s.init('MyWlan', 'mypassword', '192.168.88.117:8081'); // SSID Password webserver's url
I had to find out the size of the module. It was stored in the header of the received code.
then it needs to specify the total module size for each chunk to be written to the flash:this.st.write(name, data, offset, sz);
Altough some times i get an error which might be from a buffer overrun in the http.get module.
-
-
-
I am trying out the Sorage module. The example in the documentation works fine on my board. However a small change in the code brought me to a problem:
I would start with an empty file of the required size and then populate the file with content:var f = require("Storage"); f.write("a", "", 0, 20); console.log("File-Size: ", f.read("a").length); f.write("a","Hello",0); f.write("a"," ",5); f.write("a","World!!!",6); print(f.read("a"));
This results in an error:
File-Size: 14 Uncaught Error: Too much data for file size at line 1 col 18 f.write("a"," ",5); ^ Uncaught Error: Too much data for file size at line 1 col 25 f.write("a","World!!!",6); ^ Hello
And another question: How to determine the size of a file without reading it? The file might be bigger than the available memory and the "list()" method just lists the file name.
-
Thanks for this tip! This brought me to the Idea to store the modules to the flash using Storage. This would allow to load the modules later also offline.
My application has multiple modules. This approch would allow me to work on a smaller module without the need to load all the time all modules.However I came over a problem with the storage module, i'll put this in another thread.
-
I have my own nodejs webserver and want to load my modules from this server. When I enter the following code on the right side of the Web IDE everything works hwever I get error messages like "Unexpected reserved word in http://192.168.88.117:8081/Wireless.js":
Transmit = require("http://192.168.88.117:8081/transmitClass.js"); Wireless = require("http://192.168.88.117:8081/Wireless.js"); Switch = require("http://192.168.88.117:8081/switchClass.js"); oWl = new Wireless('myAp', '192.168.88.117', new Switch()); oWl.init();
when I enter the command on the left side, the file is not found:
Transmit = require("http://192.168.88.117:8081/transmitClass.js") Uncaught Error: Module http://192.168.88.117:8081/transmitClass.js not found at line 1 col 65 ....117:8081/transmitClass.js")
The same happens, when I require such a module within the module:
doTransmit() { console.log('Call Transmit'); var url = 'http://'+this.wServer+':8081/transmitClass.js'; Transmit = require(url); this.oTr = new Transmit(this.wServer, this.mThing); this.oTr.init(); }
I do not understand this behaviour. Could somebody explain this to me?
Thanks for all,
Thomas -
-
-
I am using the websocket client on a WEMOS board where i could establish a connection to my nodejs server. However the documentation on espruino is very basic. I could not find a reference and i am missing calls to close a connection and events to react on closing the connection from the server or a disconnect due to a network failure.
Is there some reference for these calls or is it still under development?
-
@allObjects ah ya! i have overseen this in your suggestion! Brilliant! The way around beak is perfect. Thank you.
@Gordon I have tried using the function Array.filter() replacing the inner loop. This works although I must pass a parameter to this function and so the Web Ide warns me "don't use a function within a loop".
By the way Array.find() is not implemented yet which would have been my favorite choice. -
Thanks for your tips, you are right there are some other issues. I came not across this yet because I got this compilation error which was irritating me. The mentioned error message does not go away, even with the corrected code. Of course I can remove the the breaks, but the code is not efficient because it does not stop looping when the correct record is found.
-
I have a nested while construct to find a value found in a source array to be within a destination array. When found want to break out from both loops. But it throws an error on the break statement in the outer loop. Could this be an error or do I miss something?
I am using Espruino 1v99 on a ESP2866
Here is the code:
var oWifi = require('Wifi'); oWifi.scan(function(aAp) { aAp.sort(function(a, b) { var r = a.rssi === b.rssi ? 0 : (a.rssi < b.rssi ? 1 : -1); return r; }); console.log(aAp); var i=0, k=0, foundMy=false; while (i<aAp.length) { foundMy = false; while (k<aMyAp.length) { if (aAp[i].ssid === aMyAp[i].ssid) { foundMy = true; break; } k++; } if (foundMy) { break; <--- Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop } i++; } if (foundMy) { oWifi.connect(aMyAp[k].ssid, {password: aMyAp[k].pwd}, function(err) { if (err===null) { console.log('Connection success to:', aMyAp[k].ssid); } }); } else { console.log('no Ap found'); } });
I am running under 2v00