-
-
I used wiznet 5500 for tcp connection, but sometime I didn't know why it stopped. And then I tried to reset system, but the socket not avaiable still exiested. I had to power off the board then the wiznet work fined agnin.
How to reset WIZnet 5500 while socket is not available?
No free sockets found
This is my code, and run on the board STM32F4DISCOVERY
let WIZnet = require("WIZnet"); let st = require("Storage"); let WebServer = require('WebServer'); let ip = "192.168.1.238"; let gateway = "192.168.1.1"; let eth = null; E.on('init', function () { SPI2.setup({mosi: B15, miso: B14, sck: B13}); eth = WIZnet.connect(SPI2, B12); setTimeout(function () { eth.setIP({ip: ip, gateway: gateway, subnet: "255.255.255.0",dns:"8.8.8.8"}); console.log("ip", eth.getIP()); startServer(); }, 1500); }); function startServer() { var webs = new WebServer({ port: 8080, file_system: '/var/www/', memory: { 'index.html': { 'type': 'text/html', 'content': '<html><head><script src="index.js"></script></head><body>' + '<p>Hello from in memory HTML!</p>' + '<br><button onclick="hello()"> Run client side JavaScript</button>' + '<br><br><button onclick="window.open(\'index.njs\', \'_top\')"> Run server side JavaScript</button>' + '<br><br><button onclick="window.open(\'index.txt\', \'_top\')"> Go to a simple text</button>' + '<br><p align="right"> <small>Espruino WebServer</small> </p>' + '</body></html>' }, 'index.txt': { 'content': 'Hello from in memory text!' }, 'index.js': { 'type': 'application/javascript', 'content': "function hello(){ alert('Hello from in memory client side javascript'); }", }, 'index.njs': { 'content': index_njs }, 'favicon.ico': { 'type': 'image/x-icon', 'content': "\0\0\x01\0\x01\0\x10\x10\x10\0\x01\0\x04\x00\xf0\0\0\0\x16\0\0\x00\x89PNG\x0d\x0a\x1a\x0a\0\0\0\x0dIHDR\0\0\0\x10\0\0\0\x10\x08\x06\0\0\0\x1f\xf3\xffa\0\0\x00\xb7IDAT8\x8d\xa5S\xc1\x0d\x03!\x0csN\xb7\x91w\xcaP\xde)3\xd1G\x09\x0a\x85\xab\xa8\xea\x0f\x02\x82c\x1b0\x92x\x82\xbb\xb7:\x8f\x08D\x84\xd5\xb5\x1b\x00H\xb6>N\x04uN\x12\x92\x10\x11S\xcd]\x0b\xbf\xa9\xe9\x8a\x00\xa0I\x1a*\x06A\x97\xb7\x90\xd4\x8e$A\x12\xee\xde\xb2vR\x90$\xc8q\xf6\x03\xbc\x15Ldw]\x88zpc\xab*\x8c\x08H\xb2A\x90\x1e\x97\xce\x1bd3\x00\xb8v\x9b\xa7p\xf7\xb6\x10\x9cb\xc9\xe0Wd\x06\x17\x80v\xe2\xfb\x09\x17\x00H\xfa\x8b\xc0\xba\x9c\xe3CU\xf1\xc8@\xd2\x08fW\xf8i3?U\x12\x18z\x16\xf5A\x9ddc_\xee\xbd~e{*z\x01|\xcdnfT\x03\x0an\0\0\0\x00IEND\xaeB`\x82" } } }); webs.on('start', function (WebServer) { console.log('WebServer listening on port ' + WebServer.port); }); webs.on('request', function (request, response, parsedUrl, WebServer) { console.log('WebServer requested', parsedUrl); }); webs.on('error', function (error, WebServer) { console.log('WebServer error', error); }); webs.createServer(); } function index_njs(req, res, uri, webs) { return { type: 'text/html', content: '<html>' + '<p>Hello from in memory server side javascript!</p>' + '<p><b>Espruino Memory Usage: </b><br>' + JSON.stringify(process.memory()) + '</p>' + '<p><b>Espruino Flash Usage: </b><br>' + JSON.stringify(require('Flash').getFree()) + '</p>' + '</html>' }; } // setInterval(function () { // eth.getIP(); // startServer(); // }, 5000);
-
When I first time visited the device like this, http://192.168.1.111
Ok,no matter how I pressed the F5 button for refreshing, the connection was ok.
But when I write a new website like: http://www.google.com and then press the back history for visiting the http://192.168.1.111 again, it failed, the browser rejected for visiting, maybe the device did. -
The page I load is very simple and little cotent, I just press the F5 for refreshing the website, but somehow the server reject for connecting.
And I invoked WIZnet.getStatus(), it was still working.
{ state: "online", id: "W5500", phylink: "up", phypowmode: "normal", by: 0, mode: 1, speed: 100, duplex: 0 }
But when I visit website by http://ip , the browser reject like this: ERR_CONNECTION_REFUSED
-
function pageRequest(req, res) { res.writeHead(200); res.end("Hello World"); } require("http").createServer(pageRequest).listen(8080); // port 8080
The code like this, when the borad work, it's ok for visiting the pages which the server supply at the very first time. But when I jump for the other websites and visit back via return history of browser, the server stop. I can't visit the server website again. I have to invoke load() for restart then I access the server again.
How to Keep web server working for long time?
-
-
-
I use a module WIZnet W5500 for network.
My code:let WIZnet = require("WIZnet"); var http = require("http"); SPI2.setup({mosi: B15, miso: B14, sck: B13}); let eth = WIZnet.connect(SPI2, B12); setTimeout(function() { eth.setIP(); console.log("ip", eth.getIP()); },1000);
If I unplug the net cable, this code stopped in 'ERROR: No free sockets found', but I don't know how to catch this error.
On the other hand, how do I continuedly listen the eth while I plug the net cable for initializing the network?
-
I read a statement about stm32F4, it said that this kind of chip can be individually configured by software in several modes, include input floating. However, the Espruion system did not have input floating, and initially I coded Pin.getInfo(), it shown that its' mode was analog.
Even though I reset(true) the system, its' default mode is still analog. I have no idea how to use input floating mode as default, or I have no idea where its'mode was changed from input floating to analog. -
-
-
-
when I use Esprima(offline) to minify the code, It's not okay when use AT.js. But If I don't use Esprima, all goes well.
Uncaught Error: Cannot read property 'substr' of undefined
at line 1 col 222
...;if(e)for(var c in e)for(;b.substr(0,c.length)==c;)if(a=b,b=...I think the position of the error right here:
if (line[0]=="\n") {line=line.substr(1);} if (handlers) { for (var h in handlers) { while (line.substr(0,h.length)==h) { // console.log("execute handler", h) var pre = line; line = handlers[h](line); if (pre==line) {return;} // handler needs more data //if (dbg) console.log("HANDLER] "+JSON.stringify(pre)+"=>"+JSON.stringify(line)+" ("+h+")"); } } }
How can I avoid this error?
Otherwise, when I tried to uncheck the Esprima: Mangle(Shorten variable name), the result of this error still use the short variable name, I wonder if WEB IDE didn't work?
=======================================
I tried to write a simple code in WEB-IDE,Serial2.setup(19200, {rx: A3, tx: A2}); let at = require('AT').connect(Serial2); //console.log at.cmd("AT+CIPOPEN?\r\n",1000,function(r){console.log(r)});
and use Esprima to minify the code, like these. It's the same with the original AT.js.
Serial2.on("data", function (d) {if(console.log('res',JSON.stringify(d)),d[0]==='extends typeof'&&(d=d.replace('extends typeof','')),dataCount){if(line&&(d=line+d,line=''),d.length<=dataCount){dataCount-=d.length,dataCallback(d),dataCount==0&&(dataCallback=undefined);return;}dataCallback(d.substr(0,dataCount)),d=d.substr(dataCount),dataCount=0,dataCallback=undefined;}if(line+=d,line[0]=='\n'&&(line=line.substr(1)),handlers)for(var h in handlers)while(line.substr(0,h.length)==h){var pre=line;if(line=handlersh,pre==line)return;}var i=line.indexOf('\r');while(i>=0){var l=line.substr(0,i);var handled=!1;if(l.length>0)for(var h in lineHandlers){let namee='ddddd';l.substr(0,h.length)==h&&(lineHandlersh,handled=!0),handled||lineCallback&&l&&lineCallback(l);}if(line=line.substr(i+1),handled&&dataCount)return cb('');if(line[0]=='\n'&&(line=line.substr(1)),line.length&&handlers)for(var h in handlers)line.substr(0,h.length)==h&&(line=handlersh);line||(line=''),i=line.indexOf('\r');}});
However, when I pick up the same position code from my project by dump(), the AT.js part is different with the previous one.
function Cnet(ua) { iam = this; uart = ua; at = require("AT").connect(ua); setTimeout(function () { init1(); }, 3000); }
Serial2.on("data", function (a) {
if(d){b&&(a=b+a,b="");if(a.length<=d){d-=a.length;l(a);0==d&&(l=void 0);return}l(a.substr(0,d));a=a.substr(d);d=0;l=void 0}b+=a;m&&console.log("] "+JSON.stringify(a));"\n"==b[0]&&(b=b.substr(1));if(e)for(var c in e)for(;b.substr(0,c.length)==c;)if(a=b,b=ec,a==b)return;for(a=b.indexOf("\r");0<=a;){var f=b.substr(0,a),p=!1;if(0<f.length){for(c in h)f.substr(0,c.length)==c&&(hc,p=!0);p||g&&
g(f)}b=b.substr(a+1);if(p&&d)return q("");"\n"==b[0]&&(b=b.substr(1));if(b.length&&e)for(c in e)b.substr(0,c.length)==c&&(b=ec);a=b.indexOf("\r")}
}); -
I want to use Storage to cache datas.
After the some times, I always get the fix length data which I write very early.
I want to know that do Storage can overwirte the old datas when I user write("",""). Otherwise, why I always read the very first datas? And the data length is always 38.console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiii_1", JSON.stringify(cac))
let cac = st.read("http"); console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiii_0", JSON.stringify(line)) console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiii_1", JSON.stringify(cac)) if (cac) { line = line.substr(line.indexOf(tar_flag) + tar_flag.length); console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiii_2", JSON.stringify(line)) } cac += line; console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiii_3", JSON.stringify(cac)) st.write("http", cac);
st.getFree()
=248900 -
I ran code in STM32F4DISCOVERY board.
I use Event on for listening the 4G Sim。If the Http Response is a little datas, it work well. But If the Response is relatively much more data, this error will happen.
In the code, the variable line will receive data as much as the http return.
How do I avoid this error?
The main code like this:
uart.on("data", function cb(d) { line += d; if (line.startsWith("\r\n")) { line = line.substr(2); } if (line[0] === "\n") { line = line.substr(1); } if (line[0] === "\r") { line = line.substr(1); } if (line[0] === "\u00FF") { line = line.replace("\u00FF", ""); } if (line.length > 0) { for (let h in lineHandlers) if (line.indexOf(h) > -1) { line = lineHandlers[h](line.substr(line.indexOf(h))); } } if (handlers) { for (let h in handlers) { while (line.substr(0, h.length) === h) { let resp = handlers[h](line); if (resp) { line = resp; } else { line = ""; } return; } } }
-
This is the request message
GET /hello.txt HTTP/1.1
User-Agent: Espruino 2v04.401
Connection: close
Host: http://www.pur3.co.ukAnd this is the response message
RECV FROM:93.93.135.13:80
+IPD259
HTTP/1.1 200 OK
Date: Wed, 25 Mar 2020 02:30:54 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Fri, 15 Nov 2013 15:42:26 GMT
ETag: "d-4eb390b887c80"
Accept-Ranges: bytes
Content-Length: 13
Connection: close
Content-Type: text/plain
Hello World!
+IPCLOSE: 0,1I tried to put debuggers in two places. In this place, I can't reach the debugger 2.
debugger; // 1 http.get("http://www.pur3.co.uk/hello.txt", function(res) { debugger; //2 let str = ''; res.on('data', chunk => { console.log("chunk",chunk); str += chunk; }); res.on('end', () => { console.log("Get some test request contents: ---> ", str); }); });
And the second place here:
recv: function (sckt, maxLen) { if (sockData[sckt]) { console.log("ddddddddddddddd",sockData[sckt]) var r; console.log("recv", sockData[sckt].length); if (sockData[sckt].length > maxLen) { r = sockData[sckt].substr(0, maxLen); sockData[sckt] = sockData[sckt].substr(maxLen); console.log("recv", sockData[sckt]); } else { r = sockData[sckt]; sockData[sckt] = ""; console.log("recv | socks[sckt]", socks[sckt]); if (socks[sckt] == "DataClose") { dbg("Got DataClose - forcing close"); socks[sckt] = "closing"; } } console.log("[recv data]", r); debugger; // 3 return r; } if (socks[sckt] == "closing" || !socks[sckt]) return -1; // close it return ""; },
I can reach debugger 3. And then where the code goes puzzle me so much! What's the relation between Http.get() and recv()?
debug>step
return r; ^
debug>step
Value returned is ="Hello World!" -
The code
console.log("back from network?",res)
didn't print anything.tp.get("http://www.pur3.co.uk/hello.txt", function (res) { console.log("back from network?",res) let str = ''; res.on('data', chunk => { console.log("chunk",chunk); str += chunk; }); res.on('end', () => { console.log("result: ---> ", str); }); });
In the Mehtod recv(), I did got datas and retruned them. But where these datas go I really don't know, and how do they go back to http.get response body?
console.log("[recv data]", r)
return r;
-
Now I use a SIM7600CE for 4G connection. The modules didn't adapt for this kind of sim card.
So I have to write my own module for it.Now I can get response datas in this Method:
recv: function (sckt, maxLen) { if (sockData[sckt]) { var r; console.log("recv", sockData[sckt].length); if (sockData[sckt].length > maxLen) { r = sockData[sckt].substr(0, maxLen); sockData[sckt] = sockData[sckt].substr(maxLen); console.log("recv", sockData[sckt]); } else { r = sockData[sckt]; sockData[sckt] = ""; console.log("recv | socks[sckt]", socks[sckt]); if (socks[sckt] == "DataClose") { dbg("Got DataClose - forcing close"); socks[sckt] = "closing"; } } console.log("[recv data]", r) return r; } if (socks[sckt] == "closing" || !socks[sckt]) return -1; // close it return ""; },
I think this part is the place where return datas to http.get().
But I can't recieve any datas in this place.
Do you have any introductions about how the datas flow in the network?http.get("http://www.pur3.co.uk/hello.txt", function (res) { let str = ''; res.on('data', chunk => { console.log("chunk",chunk); str += chunk; }); res.on('end', () => { console.log("result: ---> ", str); }); });
-
Sometimes I want the update codes by METHOD load(), and use HTTP to download new codes and eval("new codes"). But it always crashed. Especially when I use serval setInterval() in code.
When I invoke load() in code, it still have the past codes in the RAM. Is it possible to refresh codes by codes? How can I clean RAM datas, or the garbage?
ERROR: Ctrl-C while processing interval - removing it.
Execution Interrupted during event processing.
New interpreter error: CALLBACK,MEMORY
ERROR: Ctrl-C while processing interval - removing it.
ERROR: Ctrl-C while processing interval - removing it.
Execution Interrupted during event processing.
ERROR: Ctrl-C while processing interval - removing it.
Execution Interrupted during event processing.
MQTT disconnected... reconnecting.
ERROR: No free sockets found -
-
I ran codes in STM32F4DISCOVERY board.
I used MQTT module, when I didn't access board by IDE, just open the power, MQTT failed, datas couldn't send to server, but the board do get ip and access into network fine. Then I accessed into IDE, showed log like this. When I always accessed IDE, it's okay all the time.
New interpreter error: FIFO_FULL
What's this means? How to avoid this error without IDE?
My codes
E.on('init', function () { setTimeout(() => { eth = WIZnet.connect(SPI2, B12); eth.setIP(); console.log(eth.getIP()); },2000); setTimeout(() => { mqtt = mqttLib.connect({ host: serip, username: "admin", password: "admin", client_id: "33333333333" }); mqtt.on('connected', function () { console.log("connect to mqtt success"); rhb(); }); }, 8 * 1000); }); function rhb() { console.log("enter a heartbeat runner......"); let hber = setInterval(() => { if (mqtt) { mqtt.publish(hbTopic, JSON.stringify({ sn: "22222222222" })); } }, 1000); } save();
-
I run a example in STM32F4DISCOVERY board.
I copied the example code like this:let WIZnet = require("WIZnet"); E.on('init', function () { SPI2.setup({ mosi:B15, miso:B14, sck:B13 }); let eth = WIZnet.connect(SPI2, B10); eth.setIP(); }); save();
But is's not okay.
Prompt not detected - upload failed. Trying to recover...Execution Interrupted during event processing.
I do have the library WIZnet in board.
I want to konw how connect to Internet stably by Ethernet cable?===================================
Then I changed the code like this:let WIZnet = require("WIZnet"); setTimeout(()=>{ SPI2.setup({ mosi:B15, miso:B14, sck:B13 }); let eth = WIZnet.connect(SPI2, B10); eth.setIP(); },2000) E.on('init', function () { }); save();
that's okay. But the new question is, If i closed the power of the board and then reopened it, It couldn't access to network, I couldn't ping the static ip of the board.
It seems that I have to run code after I access the board by IDE!
I wonder when and where I access to network is better.
-
-
The board ran for months, but someday the codes in flash disappeared, and the board died.
How and Where I can figure out the key problem?