• I've been trying to make a Espruino webserver that would work with an ESP8266, and be able to serve static files and dynamically generated data.

    I've run into a problem though....

    It serves the first request just fine.

    Subsequent requests make the ESP's activity LED blink, but nothing is printed to the espruino console, and the browser hangs at "waiting for 192.168.2.102..."

    It's as if the callback stops getting called after the first request. Are things getting fouled up, leaving the ESP waiting for a response that the Espruino doesn't know it needs to give?

    In any event, after getting into this state, the ESP8266 needs to be reset. If we can't keep it from doing this, we need to take the CC3k approach and wire in reset, and use it liberally.

    Serial4.setup(9600, { rx: C11, tx : C10 });
    
    
    var http = require("http");
    var wifi = require("ESP8266WiFi").connect(Serial4, function(err) {
      if (err) throw err;
      wifi.reset(function(err) {
        if (err) throw err;
        console.log("Connecting to WiFi");
        wifi.connect(wifi.config.ssid,wifi.confi­g.pass, function(err) {
          if (err) throw err;
          console.log("Connected");
          wifi.getIP(function(err,ip){wifi.config.­ip=ip;});
          setTimeout(wifi.userinit.bind(wifi),1500­0);
        });
      });
    });
    wifi.config={ssid:"TwilightZone", pass:"(snip)", port:80};
    wifi.fpfx="html"; //file prefix for serving files off SD card;
    
    wifi.userinit= function() { //set up the server. 
    	console.log("setting up server on "+this.config.ip+":"+this.config.port);
    	this.server=require('http').createServer­(this.onRequest.bind(this)).listen(this.­config.port);
    };
    wifi.onRequest=function (req, res) {
    	var par=url.parse(req.url,true);
    	var q=par.query; 
    	var nam=par.pathname; 
    	var l=nam.indexOf("/");
    	nam=nam.slice(l);
    	var rd=this.procreq(nam,q);
    	res.writeHead(rd.code,rd.head?rd.head:{'­Content-Type': 'text/plain'});
    	if (!rd.file) {
    		res.write(rd.body);
            res.end();
    	} else {
    		rd.file.pipe(res);
            res.end();
    	}
    };
    
    wifi.procreq = function (path,query) {
    	var paths=path.split(".");
    	var rd={};
    	rd.code=404;
    	rd.body="";
    	// code goes here
        console.log(paths[1]);
    	switch (paths[1]) {
    		case "json": 
    			if (this.json.hasOwnProperty(paths[0].slice­(1)))
    			{
    				rd=this.json[paths[0].slice(1)](path,que­ry);
    			} else {
    				rd.body="json "+paths[0].slice(1)+" not found";
    			}
    			break;
    		case "cmd": 
    			rd=runCMD(path,query);
    			break;
    		
    		default: 
    			var f = E.openFile(wifi.fpfx+"/"+path, "r");
    			if (f==undefined) {
    				rd.body="File "+path+" not found";
    			} else {
    				rd.code=200;
    				rd.file=f;
    			}
    		
    	}
    	return rd;
    };
    wifi.json={};
    wifi.json.status= function (path,query) {
    	 return {code:200,body:'{gtg:true,dtf:false,miss­iles:["armed","armed","repair","mothball­ed"]}'};
    };
    

    at.debug() output below.

  •  _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v76 Copyright 2015 G.Williams
    >echo(0);
    =undefined
    >wifi.at.debug();
    ={
      "line": "\"aÓ§…ÿ@\x11\x19×aÇ!\x19ÿeQQ\\ÿ)Âû",
      "lineCallback": function (a) { ... },
      "handlers": {
        "+IPD": function (a) { ... }
       },
      "lineHandlers": {  },
      "waiting": [  ]
     }
    ] "\"aÓ§…ÿ@\x11\x19×aÇ!\x19ÿeQQ\\ÿ)Âû\r" <--- "\r"
    ] "\n[Ven" <--- "\n[Ven"
    ] "[Vendor" <--- "dor"
    ] "[Vendor:ww" <--- ":ww"
    ] "[Vendor:http://www.a" <--- "w.a"
    ] "[Vendor:http://www.ai-t" <--- "i-t"
    ] "[Vendor:http://www.ai-thin" <--- "hin"
    ] "[Vendor:http://www.ai-thinker" <--- "ker"
    ] "[Vendor:http://www.ai-thinker.co" <--- ".co"
    ] "[Vendor:http://www.ai-thinker.com V" <--- "m V"
    ] "[Vendor:http://www.ai-thinker.com Versi" <--- "ersi"
    ] "[Vendor:http://www.ai-thinker.com Version:" <--- "on:"
    ] "[Vendor:http://www.ai-thinker.com Version:0.9" <--- "0.9"
    ] "[Vendor:http://www.ai-thinker.com Version:0.9.2.4" <--- ".2.4"
    ] "[Vendor:http://www.ai-thinker.com Version:0.9.2.4]\r\n" <--- "]\r\n"
    ] "\r\nread" <--- "\r\nread"
    ] "ready\r\n" <--- "y\r\n"
    ["ATE0\r\n"
    ] "ATE0" <--- "ATE0"
    ] "ATE0\r\r\n" <--- "\r\r\n"
    ] "\r\nOK\r\n" <--- "\r\nOK\r\n"
    ["AT+CIPMUX=1\r\n"
    ] "\r" <--- "\r"
    ] "\nOK" <--- "\nOK"
    ] "OK\r\n" <--- "\r\n"
    Connecting to WiFi
    ["AT+CWMODE=1\r\n"
    ] "n" <--- "n"
    ] "no " <--- "o "
    ] "no cha" <--- "cha"
    ] "no change" <--- "nge"
    ] "no change\r\n" <--- "\r\n"
    ["AT+CWJAP=\"TwilightZone\",\"(snip)\"\r­\n"
    ] "\r" <--- "\r"
    ] "\nOK" <--- "\nOK"
    ] "OK\r\n" <--- "\r\n"
    Connected
    ["AT+CIFSR\r\n"
    ] "1" <--- "1"
    ] "192" <--- "92"
    ] "192.16" <--- ".16"
    ] "192.168.2" <--- "8.2"
    ] "192.168.2.10" <--- ".10"
    ] "192.168.2.102\r\n" <--- "2\r\n"
    ] "\r\nOK\r" <--- "\r\nOK\r"
    ] "\n" <--- "\n"
    setting up server on 192.168.2.102:80
    ["AT+CIPSERVER=1,80\r\n"
    ] "\r\nO" <--- "\r\nO"
    ] "OK\r\n" <--- "K\r\n"
    ] "Lin" <--- "Lin"
    ] "Link\r\n" <--- "k\r\n"
    ] "Link" <--- "Link"
    ] "Link\r\n\r" <--- "\r\n\r"
    ] "\n+IPD," <--- "\n+IPD,"
    ] "+IPD,0,2" <--- "0,2"
    ] "+IPD,0,298:GE" <--- "98:GE"
    ] "+IPD,0,296:T /st" <--- "T /st"
    ] "+IPD,0,291:atus." <--- "atus."
    ] "+IPD,0,286:json H" <--- "json H"
    ] "+IPD,0,280:TTP/1" <--- "TTP/1"
    ] "+IPD,0,275:.1\r\nHo" <--- ".1\r\nHo"
    ] "+IPD,0,269:st: 1" <--- "st: 1"
    ] "+IPD,0,264:92.16" <--- "92.16"
    ] "+IPD,0,259:8.2.10" <--- "8.2.10"
    ] "+IPD,0,253:2\r\nUs" <--- "2\r\nUs"
    ] "+IPD,0,248:er-Ag" <--- "er-Ag"
    ] "+IPD,0,243:ent: M" <--- "ent: M"
    ] "+IPD,0,237:ozill" <--- "ozill"
    ] "+IPD,0,232:a/5.0 " <--- "a/5.0 "
    ] "+IPD,0,226:(Wind" <--- "(Wind"
    ] "+IPD,0,221:ows N" <--- "ows N"
    ] "+IPD,0,216:T 6.3;" <--- "T 6.3;"
    ] "+IPD,0,210: WOW6" <--- " WOW6"
    ] "+IPD,0,205:4; rv" <--- "4; rv"
    ] "+IPD,0,200::36.0)" <--- ":36.0)"
    ] "+IPD,0,194: Geck" <--- " Geck"
    ] "+IPD,0,189:o/201" <--- "o/201"
    ] "+IPD,0,184:00101 " <--- "00101 "
    ] "+IPD,0,178:Firef" <--- "Firef"
    ] "+IPD,0,173:ox/36." <--- "ox/36."
    ] "+IPD,0,167:0\r\nAc" <--- "0\r\nAc"
    ] "+IPD,0,162:cept:" <--- "cept:"
    ] "+IPD,0,157: text/" <--- " text/"
    ] "+IPD,0,151:html," <--- "html,"
    ] "+IPD,0,146:appli" <--- "appli"
    ] "+IPD,0,141:cation" <--- "cation"
    ] "+IPD,0,135:/xhtm" <--- "/xhtm"
    ] "+IPD,0,130:l+xml," <--- "l+xml,"
    ] "+IPD,0,124:appli" <--- "appli"
    ] "+IPD,0,119:catio" <--- "catio"
    ] "+IPD,0,114:n/xml;" <--- "n/xml;"
    ] "+IPD,0,108:q=0.9" <--- "q=0.9"
    ] "+IPD,0,103:,*/*;" <--- ",*/*;"
    ] "+IPD,0,98:q=0.8\r" <--- "q=0.8\r"
    ] "+IPD,0,92:\nAcce" <--- "\nAcce"
    ] "+IPD,0,87:pt-La" <--- "pt-La"
    ] "+IPD,0,82:nguage" <--- "nguage"
    ] "+IPD,0,76:: en-" <--- ": en-"
    ] "+IPD,0,71:US,en;" <--- "US,en;"
    ] "+IPD,0,65:q=0.5" <--- "q=0.5"
    ] "+IPD,0,60:\r\nAcc" <--- "\r\nAcc"
    ] "+IPD,0,55:ept-En" <--- "ept-En"
    ] "+IPD,0,49:codin" <--- "codin"
    ] "+IPD,0,44:g: gz" <--- "g: gz"
    ] "+IPD,0,39:ip, de" <--- "ip, de"
    ] "+IPD,0,33:flate" <--- "flate"
    ] "+IPD,0,28:\r\nCon" <--- "\r\nCon"
    ] "+IPD,0,23:nectio" <--- "nectio"
    ] "+IPD,0,17:n: ke" <--- "n: ke"
    ] "+IPD,0,12:ep-al" <--- "ep-al"
    ] "+IPD,0,7:ive\r\n\r" <--- "ive\r\n\r"
    ] "+IPD,0,1:\n\r\nOK" <--- "\n\r\nOK"
    ] "OK\r\n" <--- "\r\n"
    Socket accept 0 "GET /status.json HTTP/1.1\r\nHost: 192.168.2.102\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0\r\nAccept: text/html,application/xhtml+xml,applicat­ion/xml;q=0.9,*/*;q=0.8\r\nAccept-Langua­ge: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n" undefined
    json
    ["AT+CIPSEND=0,64\r\nHTTP/1.0 200 OK\r\nServer: Espruino 1v76\r\nContent-Type: text/plain"
    ] ">" <--- ">"
    ] "> " <--- " "
    ] "> \r\n" <--- "\r\n"
    ] "SEND " <--- "SEND "
    ] "SEND OK\r" <--- "OK\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=0,64\r\n\r\n\r\n{gtg:true,d­tf:false,missiles:[\"armed\",\"armed\",\­"repair\",\"moth"
    ] "> " <--- "> "
    ] "> \r\nSEN" <--- "\r\nSEN"
    ] "SEND OK\r\n" <--- "D OK\r\n"
    ["AT+CIPSEND=0,9\r\nballed\"]}"
    ] "> " <--- "> "
    ] "> \r\n" <--- "\r\n"
    ] "SEND " <--- "SEND "
    ] "SEND OK\r" <--- "OK\r"
    ["AT+CIPCLOSE=0\r\n"
    ] "\n" <--- "\n"
    ] "\r\nO" <--- "\r\nO"
    ] "OK\r\n" <--- "K\r\n"
    ] "Unl" <--- "Unl"
    ] "Unlink" <--- "ink"
    ] "Unlink\r\n" <--- "\r\n"
    ] "Lin" <--- "Lin"
    ] "Link\r" <--- "k\r"
    ] "\n\r\n+I" <--- "\n\r\n+I"
    ] "+IPD,0" <--- "PD,0"
    ] "+IPD,0,299" <--- ",299"
    ] "+IPD,0,299:GET " <--- ":GET "
    ] "+IPD,0,295:/stat" <--- "/stat"
    ] "+IPD,0,290:us2.j" <--- "us2.j"
    ] "+IPD,0,285:son HT" <--- "son HT"
    ] "+IPD,0,279:TP/1." <--- "TP/1."
    ] "+IPD,0,274:1\r\nHos" <--- "1\r\nHos"
    ] "+IPD,0,268:t: 19" <--- "t: 19"
    ] "+IPD,0,263:2.168" <--- "2.168"
    ] "+IPD,0,258:.2.102" <--- ".2.102"
    ] "+IPD,0,252:\r\nUse" <--- "\r\nUse"
    ] "+IPD,0,247:r-Agen" <--- "r-Agen"
    ] "+IPD,0,241:t: Mo" <--- "t: Mo"
    ] "+IPD,0,236:zilla" <--- "zilla"
    ] "+IPD,0,231:/5.0 (" <--- "/5.0 ("
    ] "+IPD,0,225:Windo" <--- "Windo"
    ] "+IPD,0,220:ws NT " <--- "ws NT "
    ] "+IPD,0,214:6.3; " <--- "6.3; "
    ] "+IPD,0,209:WOW64" <--- "WOW64"
    ] "+IPD,0,204:; rv:3" <--- "; rv:3"
    ] "+IPD,0,198:6.0) " <--- "6.0) "
    ] "+IPD,0,193:Gecko/" <--- "Gecko/"
    ] "+IPD,0,187:20100" <--- "20100"
    ] "+IPD,0,182:101 F" <--- "101 F"
    ] "+IPD,0,177:irefox" <--- "irefox"
    ] "+IPD,0,171:/36.0" <--- "/36.0"
    ] "+IPD,0,166:\r\nAcce" <--- "\r\nAcce"
    ] "+IPD,0,160:pt: t" <--- "pt: t"
    ] "+IPD,0,155:ext/h" <--- "ext/h"
    ] "+IPD,0,150:tml,ap" <--- "tml,ap"
    ] "+IPD,0,144:plica" <--- "plica"
    ] "+IPD,0,139:tion/x" <--- "tion/x"
    ] "+IPD,0,133:html+" <--- "html+"
    ] "+IPD,0,128:xml,a" <--- "xml,a"
    ] "+IPD,0,123:pplica" <--- "pplica"
    ] "+IPD,0,117:tion/" <--- "tion/"
    ] "+IPD,0,112:xml;q=" <--- "xml;q="
    ] "+IPD,0,106:0.9,*" <--- "0.9,*"
    ] "+IPD,0,101:/*;q=" <--- "/*;q="
    ] "+IPD,0,96:0.8\r\nA" <--- "0.8\r\nA"
    ] "+IPD,0,90:ccept" <--- "ccept"
    ] "+IPD,0,85:-Lang" <--- "-Lang"
    ] "+IPD,0,80:uage: " <--- "uage: "
    ] "+IPD,0,74:en-US" <--- "en-US"
    ] "+IPD,0,69:,en;q=" <--- ",en;q="
    ] "+IPD,0,63:0.5\r\n" <--- "0.5\r\n"
    ] "+IPD,0,58:Accep" <--- "Accep"
    ] "+IPD,0,53:t-Enco" <--- "t-Enco"
    ] "+IPD,0,47:ding:" <--- "ding:"
    ] "+IPD,0,42: gzip" <--- " gzip"
    ] "+IPD,0,37:, defl" <--- ", defl"
    ] "+IPD,0,31:ate\r\n" <--- "ate\r\n"
    ] "+IPD,0,26:Conne" <--- "Conne"
    ] "+IPD,0,21:ction:" <--- "ction:"
    ] "+IPD,0,15: keep" <--- " keep"
    ] "+IPD,0,10:-alive" <--- "-alive"
    ] "+IPD,0,4:\r\n\r\n\r" <--- "\r\n\r\n\r"
    ] "\nOK\r\n" <--- "\nOK\r\n"
    
  • You can see there that the first request goes fine, but the second one just seems to go nowhere after being received....

    Order doesn't matter either - same requests in opposite order, but failing same way for unknown reasons.

    
    setting up server on 192.168.2.102:80
    ["AT+CIPSERVER=1,80\r\n"
    ] "\r\nO" <--- "\r\nO"
    ] "OK\r\n" <--- "K\r\n"
    ] "Li" <--- "Li"
    ] "Link" <--- "nk"
    ] "Link\r\n\r" <--- "\r\n\r"
    ] "\n+IPD,0" <--- "\n+IPD,0"
    ] "+IPD,0,29" <--- ",29"
    ] "+IPD,0,299:GE" <--- "9:GE"
    ] "+IPD,0,297:T /st" <--- "T /st"
    ] "+IPD,0,292:atus2." <--- "atus2."
    ] "+IPD,0,286:json " <--- "json "
    ] "+IPD,0,281:HTTP/" <--- "HTTP/"
    ] "+IPD,0,276:1.1\r\nH" <--- "1.1\r\nH"
    ] "+IPD,0,270:ost: " <--- "ost: "
    ] "+IPD,0,265:192.1" <--- "192.1"
    ] "+IPD,0,260:68.2.1" <--- "68.2.1"
    ] "+IPD,0,254:02\r\nU" <--- "02\r\nU"
    ] "+IPD,0,249:ser-Ag" <--- "ser-Ag"
    ] "+IPD,0,243:ent: " <--- "ent: "
    ] "+IPD,0,238:Mozil" <--- "Mozil"
    ] "+IPD,0,233:la/5.0" <--- "la/5.0"
    ] "+IPD,0,227: (Win" <--- " (Win"
    ] "+IPD,0,222:dows " <--- "dows "
    ] "+IPD,0,217:NT 6.3" <--- "NT 6.3"
    ] "+IPD,0,211:; WOW" <--- "; WOW"
    ] "+IPD,0,206:64; rv" <--- "64; rv"
    ] "+IPD,0,200::36.0" <--- ":36.0"
    ] "+IPD,0,195:) Gec" <--- ") Gec"
    ] "+IPD,0,190:ko/201" <--- "ko/201"
    ] "+IPD,0,184:00101" <--- "00101"
    ] "+IPD,0,179: Fire" <--- " Fire"
    ] "+IPD,0,174:fox/36" <--- "fox/36"
    ] "+IPD,0,168:.0\r\nA" <--- ".0\r\nA"
    ] "+IPD,0,163:ccept:" <--- "ccept:"
    ] "+IPD,0,157: text" <--- " text"
    ] "+IPD,0,152:/html" <--- "/html"
    ] "+IPD,0,147:,appli" <--- ",appli"
    ] "+IPD,0,141:catio" <--- "catio"
    ] "+IPD,0,136:n/xht" <--- "n/xht"
    ] "+IPD,0,131:ml+xml" <--- "ml+xml"
    ] "+IPD,0,125:,appl" <--- ",appl"
    ] "+IPD,0,120:icatio" <--- "icatio"
    ] "+IPD,0,114:n/xml" <--- "n/xml"
    ] "+IPD,0,109:;q=0." <--- ";q=0."
    ] "+IPD,0,104:9,*/*;" <--- "9,*/*;"
    ] "+IPD,0,98:q=0.8" <--- "q=0.8"
    ] "+IPD,0,93:\r\nAcc" <--- "\r\nAcc"
    ] "+IPD,0,88:ept-La" <--- "ept-La"
    ] "+IPD,0,82:nguag" <--- "nguag"
    ] "+IPD,0,77:e: en" <--- "e: en"
    ] "+IPD,0,72:-US,en" <--- "-US,en"
    ] "+IPD,0,66:;q=0." <--- ";q=0."
    ] "+IPD,0,61:5\r\nAc" <--- "5\r\nAc"
    ] "+IPD,0,56:cept-E" <--- "cept-E"
    ] "+IPD,0,50:ncodi" <--- "ncodi"
    ] "+IPD,0,45:ng: g" <--- "ng: g"
    ] "+IPD,0,40:zip, d" <--- "zip, d"
    ] "+IPD,0,34:eflat" <--- "eflat"
    ] "+IPD,0,29:e\r\nCo" <--- "e\r\nCo"
    ] "+IPD,0,24:nnecti" <--- "nnecti"
    ] "+IPD,0,18:on: k" <--- "on: k"
    ] "+IPD,0,13:eep-al" <--- "eep-al"
    ] "+IPD,0,7:ive\r\n" <--- "ive\r\n"
    ] "+IPD,0,2:\r\n\r\nO" <--- "\r\n\r\nO"
    ] "OK\r\n" <--- "K\r\n"
    Socket accept 0 "GET /status2.json HTTP/1.1\r\nHost: 192.168.2.102\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0\r\nAccept: text/html,application/xhtml+xml,applicat­ion/xml;q=0.9,*/*;q=0.8\r\nAccept-Langua­ge: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n" undefined
    json
    ["AT+CIPSEND=0,64\r\nHTTP/1.0 404 OK\r\nServer: Espruino 1v76\r\nContent-Type: text/plain"
    ] ">" <--- ">"
    ] "> " <--- " "
    ] "> \r\nSEND" <--- "\r\nSEND"
    ] "SEND OK\r\n" <--- " OK\r\n"
    ["AT+CIPSEND=0,26\r\n\r\n\r\njson status2 not found"
    ] "> " <--- "> "
    ] "> \r\nS" <--- "\r\nS"
    ] "SEND OK" <--- "END OK"
    ] "SEND OK\r\n" <--- "\r\n"
    ["AT+CIPCLOSE=0\r\n"
    ] "\r\nO" <--- "\r\nO"
    ] "OK\r\nU" <--- "K\r\nU"
    ] "Unlink\r" <--- "nlink\r"
    ] "\n" <--- "\n"
    ] "L" <--- "L"
    ] "Link" <--- "ink"
    ] "Link\r\n" <--- "\r\n"
    ] "\r\n+IP" <--- "\r\n+IP"
    ] "+IPD,0," <--- "D,0,"
    ] "+IPD,0,298:G" <--- "298:G"
    ] "+IPD,0,297:ET /s" <--- "ET /s"
    ] "+IPD,0,292:tatus" <--- "tatus"
    ] "+IPD,0,287:.json " <--- ".json "
    ] "+IPD,0,281:HTTP/" <--- "HTTP/"
    ] "+IPD,0,276:1.1\r\n" <--- "1.1\r\n"
    ] "+IPD,0,271:Host: " <--- "Host: "
    ] "+IPD,0,265:192.1" <--- "192.1"
    ] "+IPD,0,260:68.2.1" <--- "68.2.1"
    ] "+IPD,0,254:02\r\nU" <--- "02\r\nU"
    ] "+IPD,0,249:ser-A" <--- "ser-A"
    ] "+IPD,0,244:gent: " <--- "gent: "
    ] "+IPD,0,238:Mozil" <--- "Mozil"
    ] "+IPD,0,233:la/5.0" <--- "la/5.0"
    ] "+IPD,0,227: (Win" <--- " (Win"
    ] "+IPD,0,222:dows " <--- "dows "
    ] "+IPD,0,217:NT 6.3" <--- "NT 6.3"
    ] "+IPD,0,211:; WOW" <--- "; WOW"
    ] "+IPD,0,206:64; rv" <--- "64; rv"
    ] "+IPD,0,200::36.0" <--- ":36.0"
    ] "+IPD,0,195:) Gec" <--- ") Gec"
    ] "+IPD,0,190:ko/201" <--- "ko/201"
    ] "+IPD,0,184:00101" <--- "00101"
    ] "+IPD,0,179: Fire" <--- " Fire"
    ] "+IPD,0,174:fox/36" <--- "fox/36"
    ] "+IPD,0,168:.0\r\nA" <--- ".0\r\nA"
    ] "+IPD,0,163:ccept:" <--- "ccept:"
    ] "+IPD,0,157: text" <--- " text"
    ] "+IPD,0,152:/html" <--- "/html"
    ] "+IPD,0,147:,appli" <--- ",appli"
    ] "+IPD,0,141:catio" <--- "catio"
    ] "+IPD,0,136:n/xhtm" <--- "n/xhtm"
    ] "+IPD,0,130:l+xml" <--- "l+xml"
    ] "+IPD,0,125:,appl" <--- ",appl"
    ] "+IPD,0,120:icatio" <--- "icatio"
    ] "+IPD,0,114:n/xml" <--- "n/xml"
    ] "+IPD,0,109:;q=0.9" <--- ";q=0.9"
    ] "+IPD,0,103:,*/*;" <--- ",*/*;"
    ] "+IPD,0,98:q=0.8" <--- "q=0.8"
    ] "+IPD,0,93:\r\nAcce" <--- "\r\nAcce"
    ] "+IPD,0,87:pt-La" <--- "pt-La"
    ] "+IPD,0,82:nguage" <--- "nguage"
    ] "+IPD,0,76:: en-" <--- ": en-"
    ] "+IPD,0,71:US,en" <--- "US,en"
    ] "+IPD,0,66:;q=0.5" <--- ";q=0.5"
    ] "+IPD,0,60:\r\nAcc" <--- "\r\nAcc"
    ] "+IPD,0,55:ept-E" <--- "ept-E"
    ] "+IPD,0,50:ncodin" <--- "ncodin"
    ] "+IPD,0,44:g: gz" <--- "g: gz"
    ] "+IPD,0,39:ip, de" <--- "ip, de"
    ] "+IPD,0,33:flate" <--- "flate"
    ] "+IPD,0,28:\r\nCon" <--- "\r\nCon"
    ] "+IPD,0,23:nectio" <--- "nectio"
    ] "+IPD,0,17:n: ke" <--- "n: ke"
    ] "+IPD,0,12:ep-al" <--- "ep-al"
    ] "+IPD,0,7:ive\r\n\r" <--- "ive\r\n\r"
    ] "+IPD,0,1:\n\r\nOK" <--- "\n\r\nOK"
    ] "OK\r\n" <--- "\r\n"
    > 
    
    
  • Thanks - I'll take a look.

    It's odd because I did actually get this when doing the server code :) not sure what's gone on. Iirc Espruino should respond to the Unlink that comes from the esp8266, so it should know that a new socket has opened.

  • I have a similiar problem using ESP8266 with nodemcu firmware.
    First request runs fine, 2nd creates an internal error.
    After resetting (power reset) and starting same application again, it runs without problems, at least next hours (never tested more than 2 hours).

  • Well that was embarrassing. Typo :)

    Should be fixed now. On the plus side, I've had a Pico doing the Weather Station thing running for a few days non-stop now and it's still working great (HTTP GET).

  • Thanks

    "Should be fixed now"

    Is that a change in the module, or a change in the firmware that fixes it? (Ie, to fix it, do I have to build and flash latest firmware, or just resend and count on website having updated modules?) Can you point me to the github commit?

  • It's just a module, so the next time you flash it should work - thankfully now it's all JS life is a lot easier.

    commit here - told you it was embarrassing :)

    It seems to work ok now, I think you might be able to confuse it be refreshing very quickly though?

    After a while the server does seem to just stop accepting connections. Not actually sure what's up with that as I reckon that one is on the ESP8266 side - it might even be a bad WiFi connection here.

    Worst case you can just do a software reset though.

  • This is better, but it's still so unreliable as to be useless. If the ESP8266 is going to be used with the Pico's that are going out, major improvements are necessary. A few calls went well... then a call that had worked before failed, and now the server is not answering http requests. Additionally I can't seem to revive the ESP without a hard power cycle. Sometimes I need to do it twice, because it doesn't respond to AT+RST,

    
    ["AT+CIPSEND=1,43\r\n\r\n\r\nInvalid json data requested: /test.json"
    ] "> " <--- "> "
    ] "> \r" <--- "\r"
    ] "\nSEND" <--- "\nSEND"
    ] "SEND OK" <--- " OK"
    ] "SEND OK\r\n" <--- "\r\n"
    ["AT+CIPCLOSE=1\r\n"
    ] "\r" <--- "\r"
    ] "\nOK" <--- "\nOK"
    ] "OK\r\n" <--- "\r\n"
    ] "Un" <--- "Un"
    ] "Unlin" <--- "lin"
    ] "Unlink\r\n" <--- "k\r\n"
    ] "Lin" <--- "Lin"
    ] "Link\r" <--- "k\r"
    ] "\nLink" <--- "\nLink"
    ] "Link\r\n" <--- "\r\n"
    ] "\r\n" <--- "\r\n"
    ] "+IPD" <--- "+IPD"
    ] "+IPD,0,3" <--- ",0,3"
    ] "+IPD,0,352:G" <--- "52:G"
    ] "+IPD,0,351:ET /st" <--- "ET /st"
    ] "+IPD,0,345:atus." <--- "atus."
    ] "+IPD,0,340:json H" <--- "json H"
    ] "+IPD,0,334:TTP/1" <--- "TTP/1"
    ] "+IPD,0,329:.1\r\nH" <--- ".1\r\nH"
    ] "+IPD,0,324:ost: 1" <--- "ost: 1"
    ] "+IPD,0,318:92.16" <--- "92.16"
    ] "+IPD,0,313:8.2.10" <--- "8.2.10"
    ] "+IPD,0,307:2\r\nCo" <--- "2\r\nCo"
    ] "+IPD,0,302:nnecti" <--- "nnecti"
    ] "+IPD,0,296:on: k" <--- "on: k"
    ] "+IPD,0,291:eep-a" <--- "eep-a"
    ] "+IPD,0,286:live\r\n" <--- "live\r\n"
    ] "+IPD,0,280:Accep" <--- "Accep"
    ] "+IPD,0,275:t: tex" <--- "t: tex"
    ] "+IPD,0,269:t/htm" <--- "t/htm"
    ] "+IPD,0,264:l,app" <--- "l,app"
    ] "+IPD,0,259:licati" <--- "licati"
    ] "+IPD,0,253:on/xh" <--- "on/xh"
    ] "+IPD,0,248:tml+xm" <--- "tml+xm"
    ] "+IPD,0,242:l,app" <--- "l,app"
    ] "+IPD,0,237:licati" <--- "licati"
    ] "+IPD,0,231:on/xm" <--- "on/xm"
    ] "+IPD,0,226:l;q=0." <--- "l;q=0."
    ] "+IPD,0,220:9,ima" <--- "9,ima"
    ] "+IPD,0,215:ge/we" <--- "ge/we"
    ] "+IPD,0,210:bp,*/*" <--- "bp,*/*"
    ] "+IPD,0,204:;q=0." <--- ";q=0."
    ] "+IPD,0,199:8\r\nUse" <--- "8\r\nUse"
    ] "+IPD,0,193:r-Age" <--- "r-Age"
    ] "+IPD,0,188:nt: Mo" <--- "nt: Mo"
    ] "+IPD,0,182:zilla" <--- "zilla"
    ] "+IPD,0,177:/5.0 " <--- "/5.0 "
    ] "+IPD,0,172:(Windo" <--- "(Windo"
    ] "+IPD,0,166:ws NT" <--- "ws NT"
    ] "+IPD,0,161: 6.3; " <--- " 6.3; "
    ] "+IPD,0,155:WOW64" <--- "WOW64"
    ] "+IPD,0,150:) Appl" <--- ") Appl"
    ] "+IPD,0,144:eWebK" <--- "eWebK"
    ] "+IPD,0,139:it/53" <--- "it/53"
    ] "+IPD,0,134:7.36 (" <--- "7.36 ("
    ] "+IPD,0,128:KHTML" <--- "KHTML"
    ] "+IPD,0,123:, like" <--- ", like"
    ] "+IPD,0,117: Geck" <--- " Geck"
    ] "+IPD,0,112:o) Chr" <--- "o) Chr"
    ] "+IPD,0,106:ome/4" <--- "ome/4"
    ] "+IPD,0,101:1.0.22" <--- "1.0.22"
    ] "+IPD,0,95:72.11" <--- "72.11"
    ] "+IPD,0,90:8 Saf" <--- "8 Saf"
    ] "+IPD,0,85:ari/53" <--- "ari/53"
    ] "+IPD,0,79:7.36\r" <--- "7.36\r"
    ] "+IPD,0,74:\nAcce" <--- "\nAcce"
    ] "+IPD,0,69:pt-Enc" <--- "pt-Enc"
    ] "+IPD,0,63:oding" <--- "oding"
    ] "+IPD,0,58:: gzip" <--- ": gzip"
    ] "+IPD,0,52:, def" <--- ", def"
    ] "+IPD,0,47:late, " <--- "late, "
    ] "+IPD,0,41:sdch\r" <--- "sdch\r"
    ] "+IPD,0,36:\nAcce" <--- "\nAcce"
    ] "+IPD,0,31:pt-Lan" <--- "pt-Lan"
    ] "+IPD,0,25:guage" <--- "guage"
    ] "+IPD,0,20:: en-U" <--- ": en-U"
    ] "+IPD,0,14:S,en;" <--- "S,en;"
    ] "+IPD,0,9:q=0.8" <--- "q=0.8"
    ] "+IPD,0,4:\r\n\r\n\r\n" <--- "\r\n\r\n\r\n"
    ] "OK\r\n\r\n" <--- "OK\r\n\r\n"
    ] "+IPD,1," <--- "+IPD,1,"
    ] "+IPD,1,352:" <--- "352:"
    ] "+IPD,1,352:GET /s" <--- "GET /s"
    ] "+IPD,1,346:tatus" <--- "tatus"
    ] "+IPD,1,341:.json" <--- ".json"
    ] "+IPD,1,336: HTTP/" <--- " HTTP/"
    ] "+IPD,1,330:1.1\r\n" <--- "1.1\r\n"
    ] "+IPD,1,325:Host: " <--- "Host: "
    ] "+IPD,1,319:192.1" <--- "192.1"
    ] "+IPD,1,314:68.2.1" <--- "68.2.1"
    ] "+IPD,1,308:02\r\nC" <--- "02\r\nC"
    ] "+IPD,1,303:onnec" <--- "onnec"
    ] "+IPD,1,298:tion: " <--- "tion: "
    ] "+IPD,1,292:keep-" <--- "keep-"
    ] "+IPD,1,287:alive\r" <--- "alive\r"
    ] "+IPD,1,281:\nAcce" <--- "\nAcce"
    ] "+IPD,1,276:pt: te" <--- "pt: te"
    ] "+IPD,1,270:xt/ht" <--- "xt/ht"
    ] "+IPD,1,265:ml,ap" <--- "ml,ap"
    ] "+IPD,1,260:plicat" <--- "plicat"
    ] "+IPD,1,254:ion/x" <--- "ion/x"
    ] "+IPD,1,249:html+x" <--- "html+x"
    ] "+IPD,1,243:ml,ap" <--- "ml,ap"
    ] "+IPD,1,238:plicat" <--- "plicat"
    ] "+IPD,1,232:ion/x" <--- "ion/x"
    ] "+IPD,1,227:ml;q=" <--- "ml;q="
    ] "+IPD,1,222:0.9,im" <--- "0.9,im"
    ] "+IPD,1,216:age/w" <--- "age/w"
    ] "+IPD,1,211:ebp,*/" <--- "ebp,*/"
    ] "+IPD,1,205:*;q=0" <--- "*;q=0"
    ] "+IPD,1,200:.8\r\nUs" <--- ".8\r\nUs"
    ] "+IPD,1,194:er-Ag" <--- "er-Ag"
    ] "+IPD,1,189:ent: M" <--- "ent: M"
    ] "+IPD,1,183:ozill" <--- "ozill"
    ] "+IPD,1,178:a/5.0" <--- "a/5.0"
    ] "+IPD,1,173: (Wind" <--- " (Wind"
    ] "+IPD,1,167:ows N" <--- "ows N"
    ] "+IPD,1,162:T 6.3;" <--- "T 6.3;"
    ] "+IPD,1,156: WOW6" <--- " WOW6"
    ] "+IPD,1,151:4) Ap" <--- "4) Ap"
    ] "+IPD,1,146:pleWeb" <--- "pleWeb"
    ] "+IPD,1,140:Kit/5" <--- "Kit/5"
    ] "+IPD,1,135:37.36 " <--- "37.36 "
    ] "+IPD,1,129:(KHTM" <--- "(KHTM"
    ] "+IPD,1,124:L, lik" <--- "L, lik"
    ] "+IPD,1,118:e Gec" <--- "e Gec"
    ] "+IPD,1,113:ko) Ch" <--- "ko) Ch"
    ] "+IPD,1,107:rome/" <--- "rome/"
    ] "+IPD,1,102:41.0." <--- "41.0."
    ] "+IPD,1,97:2272.1" <--- "2272.1"
    ] "+IPD,1,91:18 Sa" <--- "18 Sa"
    ] "+IPD,1,86:fari/5" <--- "fari/5"
    ] "+IPD,1,80:37.36" <--- "37.36"
    ] "+IPD,1,75:\r\nAcce" <--- "\r\nAcce"
    ] "+IPD,1,69:pt-En" <--- "pt-En"
    ] "+IPD,1,64:codin" <--- "codin"
    ] "+IPD,1,59:g: gzi" <--- "g: gzi"
    ] "+IPD,1,53:p, de" <--- "p, de"
    ] "+IPD,1,48:flate, sd" <--- "flate, sd"
    ] "+IPD,1,39:ch\r\nAc" <--- "ch\r\nAc"
    ] "+IPD,1,33:cept-" <--- "cept-"
    ] "+IPD,1,28:Langua" <--- "Langua"
    ] "+IPD,1,22:ge: e" <--- "ge: e"
    ] "+IPD,1,17:n-US," <--- "n-US,"
    ] "+IPD,1,12:en;q=0" <--- "en;q=0"
    ] "+IPD,1,6:.8\r\n\r" <--- ".8\r\n\r"
    ] "+IPD,1,1:\n\r\nOK" <--- "\n\r\nOK"
    ] "OK\r\n" <--- "\r\n"
    json
    ["AT+CIPSEND=0,64\r\nHTTP/1.0 200 OK\r\nServer: Espruino 1v76\r\nContent-Type: text/plain"
    ] ">" <--- ">"
    ["AT+CIPSEND=0,64\r\n\r\n\r\n{gtg:true,d­tf:false,missiles:[\"armed\",\"armed\",\­"repair\",\"moth"
    ] "> busy" <--- "busy"
    ] "> busy in" <--- " in"
    ] "> busy inet..." <--- "et..."
    ] "> busy inet...\r\n\r" <--- "\r\n\r"
    ] "\nERROR\r\n\r\n" <--- "\nERROR\r\n\r\n"
    ] "wrong sy" <--- "wrong sy"
    ] "wrong synta" <--- "nta"
    ] "wrong syntax\r\n\r" <--- "x\r\n\r"
    ] "\nERROR\r" <--- "\nERROR\r"
    ] "\n\r\nwr" <--- "\n\r\nwr"
    ] "wrong s" <--- "ong s"
    ] "wrong syn" <--- "yn"
    ] "wrong syntax" <--- "tax"
    ] "wrong syntax\r\n\r" <--- "\r\n\r"
    ] "\nERROR\r" <--- "\nERROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=0,9\r\nballed\"]}"
    ] "b" <--- "b"
    ] "bus" <--- "us"
    ] "busy i" <--- "y i"
    ] "busy inet" <--- "net"
    ] "busy inet..." <--- "..."
    ] "busy inet...\r\n\r" <--- "\r\n\r"
    ["AT+CIPCLOSE=0\r\n"
    ] "\nERROR\r\n" <--- "\nERROR\r\n"
    json
    ] "busy i" <--- "busy i"
    ] "busy inet" <--- "net"
    ] "busy inet..." <--- "..."
    ] "busy inet...\r\n\r" <--- "\r\n\r"
    ] "\nERROR" <--- "\nERROR"
    ] "ERROR\r\n" <--- "\r\n"
    ["AT+CIPSEND=1,64\r\nHTTP/1.0 200 OK\r\nServer: Espruino 1v76\r\nContent-Type: text/plain"
    ] "bu" <--- "bu"
    ] "busy " <--- "sy "
    ] "busy ine" <--- "ine"
    ] "busy inet...\r" <--- "t...\r"
    ] "\n\r\nERR" <--- "\n\r\nERR"
    ] "ERROR\r\n\r\n" <--- "OR\r\n\r\n"
    ] "wrong sy" <--- "wrong sy"
    ] "wrong synta" <--- "nta"
    ] "wrong syntax\r\n" <--- "x\r\n"
    ] "\r\nERR" <--- "\r\nERR"
    ] "ERROR\r\n\r" <--- "OR\r\n\r"
    ] "\nwrong " <--- "\nwrong "
    ] "wrong syn" <--- "syn"
    ] "wrong syntax" <--- "tax"
    ] "wrong syntax\r\n\r" <--- "\r\n\r"
    ] "\nERROR\r" <--- "\nERROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=1,64\r\n\r\n\r\n{gtg:true,d­tf:false,missiles:[\"armed\",\"armed\",\­"repair\",\"moth"
    ] "b" <--- "b"
    ] "busy" <--- "usy"
    ] "busy ine" <--- " ine"
    ] "busy inet..." <--- "t..."
    ] "busy inet...\r\n\r" <--- "\r\n\r"
    ] "\nERROR\r\n\r\n" <--- "\nERROR\r\n\r\n"
    ] "wrong sy" <--- "wrong sy"
    ] "wrong syntax" <--- "ntax"
    ] "wrong syntax\r\n" <--- "\r\n"
    ] "\r\nERRO" <--- "\r\nERRO"
    ] "ERROR\r\n\r\n" <--- "R\r\n\r\n"
    ] "wrong s" <--- "wrong s"
    ] "wrong synt" <--- "ynt"
    ] "wrong syntax\r" <--- "ax\r"
    ] "\n\r\nE" <--- "\n\r\nE"
    ] "ERROR\r" <--- "RROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=1,9\r\nballed\"]}"
    ] "bus" <--- "bus"
    ] "busy i" <--- "y i"
    ] "busy ine" <--- "ne"
    ] "busy inet.." <--- "t.."
    ] "busy inet...\r\n" <--- ".\r\n"
    ["AT+CIPCLOSE=1\r\n"
    ] "\r\nERROR\r" <--- "\r\nERROR\r"
    ] "\n" <--- "\n"
    ] "bu" <--- "bu"
    ] "busy " <--- "sy "
    ] "busy ine" <--- "ine"
    ] "busy inet.." <--- "t.."
    ] "busy inet...\r\n" <--- ".\r\n"
    ] "\r\nER" <--- "\r\nER"
    ] "ERROR\r\n" <--- "ROR\r\n"
    ] "L" <--- "L"
    ] "Lin" <--- "in"
    ] "Link\r\n" <--- "k\r\n"
    ] "Link\r" <--- "Link\r"
    ] "\n\r\n+" <--- "\n\r\n+"
    ] "+IPD," <--- "IPD,"
    ] "+IPD,2,352" <--- "2,352"
    ] "+IPD,2,352:GET" <--- ":GET"
    ] "+IPD,2,349: /sta" <--- " /sta"
    ] "+IPD,2,344:tus.js" <--- "tus.js"
    ] "+IPD,2,338:on HT" <--- "on HT"
    ] "+IPD,2,333:TP/1.1" <--- "TP/1.1"
    ] "+IPD,2,327:\r\nHos" <--- "\r\nHos"
    ] "+IPD,2,322:t: 192" <--- "t: 192"
    ] "+IPD,2,316:.168." <--- ".168."
    ] "+IPD,2,311:2.102" <--- "2.102"
    ] "+IPD,2,306:\r\nConn" <--- "\r\nConn"
    ] "+IPD,2,300:ectio" <--- "ectio"
    ] "+IPD,2,295:n: kee" <--- "n: kee"
    ] "+IPD,2,289:p-ali" <--- "p-ali"
    ] "+IPD,2,284:ve\r\nAc" <--- "ve\r\nAc"
    ] "+IPD,2,278:cept:" <--- "cept:"
    ] "+IPD,2,273: text" <--- " text"
    ] "+IPD,2,268:/html," <--- "/html,"
    ] "+IPD,2,262:appli" <--- "appli"
    ] "+IPD,2,257:cation" <--- "cation"
    ] "+IPD,2,251:/xhtm" <--- "/xhtm"
    ] "+IPD,2,246:l+xml," <--- "l+xml,"
    ] "+IPD,2,240:appli" <--- "appli"
    ] "+IPD,2,235:catio" <--- "catio"
    ] "+IPD,2,230:n/xml;" <--- "n/xml;"
    ] "+IPD,2,224:q=0.9" <--- "q=0.9"
    ] "+IPD,2,219:,image" <--- ",image"
    ] "+IPD,2,213:/webp" <--- "/webp"
    ] "+IPD,2,208:,*/*;q" <--- ",*/*;q"
    ] "+IPD,2,202:=0.8\r" <--- "=0.8\r"
    ] "+IPD,2,197:\nUser-" <--- "\nUser-"
    ] "+IPD,2,191:Agent" <--- "Agent"
    ] "+IPD,2,186:: Moz" <--- ": Moz"
    ] "+IPD,2,181:illa/5" <--- "illa/5"
    ] "+IPD,2,175:.0 (W" <--- ".0 (W"
    ] "+IPD,2,170:indows" <--- "indows"
    ] "+IPD,2,164: NT 6" <--- " NT 6"
    ] "+IPD,2,159:.3; WO" <--- ".3; WO"
    ] "+IPD,2,153:W64) " <--- "W64) "
    ] "+IPD,2,148:Apple" <--- "Apple"
    ] "+IPD,2,143:WebKit" <--- "WebKit"
    ] "+IPD,2,137:/537." <--- "/537."
    ] "+IPD,2,132:36 (KH" <--- "36 (KH"
    ] "+IPD,2,126:TML, " <--- "TML, "
    ] "+IPD,2,121:like G" <--- "like G"
    ] "+IPD,2,115:ecko)" <--- "ecko)"
    ] "+IPD,2,110: Chrom" <--- " Chrom"
    ] "+IPD,2,104:e/41." <--- "e/41."
    ] "+IPD,2,99:0.227" <--- "0.227"
    ] "+IPD,2,94:2.118 " <--- "2.118 "
    ] "+IPD,2,88:Safar" <--- "Safar"
    ] "+IPD,2,83:i/537." <--- "i/537."
    ] "+IPD,2,77:36\r\nA" <--- "36\r\nA"
    ] "+IPD,2,72:ccept-" <--- "ccept-"
    ] "+IPD,2,66:Encod" <--- "Encod"
    ] "+IPD,2,61:ing: " <--- "ing: "
    ] "+IPD,2,56:gzip, " <--- "gzip, "
    ] "+IPD,2,50:defla" <--- "defla"
    ] "+IPD,2,45:te, sd" <--- "te, sd"
    ] "+IPD,2,39:ch\r\nA" <--- "ch\r\nA"
    ] "+IPD,2,34:ccept" <--- "ccept"
    ] "+IPD,2,29:-Langu" <--- "-Langu"
    ] "+IPD,2,23:age: " <--- "age: "
    ] "+IPD,2,18:en-US," <--- "en-US,"
    ] "+IPD,2,12:en;q=" <--- "en;q="
    ] "+IPD,2,7:0.8\r\n" <--- "0.8\r\n"
    ] "+IPD,2,2:\r\n\r\nOK" <--- "\r\n\r\nOK"
    ] "OK\r\n" <--- "\r\n"
    json
    ["AT+CIPSEND=2,64\r\nHTTP/1.0 200 OK\r\nServer: Espruino 1v76\r\nContent-Type: text/plain"
    ] "b" <--- "b"
    ] "busy " <--- "usy "
    ] "busy ine" <--- "ine"
    ] "busy inet..." <--- "t..."
    ] "busy inet...\r\n\r\n" <--- "\r\n\r\n"
    ] "ERROR\r\n\r\nw" <--- "ERROR\r\n\r\nw"
    ] "wrong syn" <--- "rong syn"
    ] "wrong syntax" <--- "tax"
    ] "wrong syntax\r\n\r\n" <--- "\r\n\r\n"
    ] "ERROR\r\n" <--- "ERROR\r\n"
    ] "\r\nwro" <--- "\r\nwro"
    ] "wrong s" <--- "ng s"
    ] "wrong synt" <--- "ynt"
    ] "wrong syntax\r" <--- "ax\r"
    ] "\n\r\nER" <--- "\n\r\nER"
    ] "ERROR\r" <--- "ROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=2,64\r\n\r\n\r\n{gtg:true,d­tf:false,missiles:[\"armed\",\"armed\",\­"repair\",\"moth"
    ] "b" <--- "b"
    ] "busy" <--- "usy"
    ] "busy ine" <--- " ine"
    ] "busy inet..." <--- "t..."
    ] "busy inet...\r\n\r" <--- "\r\n\r"
    ] "\nERROR\r\n\r\n" <--- "\nERROR\r\n\r\n"
    ] "wrong sy" <--- "wrong sy"
    ] "wrong synta" <--- "nta"
    ] "wrong syntax\r\n\r" <--- "x\r\n\r"
    ] "\nERROR\r" <--- "\nERROR\r"
    ] "\n\r\nwr" <--- "\n\r\nwr"
    ] "wrong s" <--- "ong s"
    ] "wrong synt" <--- "ynt"
    ] "wrong syntax\r" <--- "ax\r"
    ] "\n\r\nE" <--- "\n\r\nE"
    ] "ERROR\r" <--- "RROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=2,9\r\nballed\"]}"
    ] "bus" <--- "bus"
    ] "busy " <--- "y "
    ] "busy ine" <--- "ine"
    ] "busy inet.." <--- "t.."
    ] "busy inet...\r\n" <--- ".\r\n"
    ["AT+CIPCLOSE=2\r\n"
    ] "\r\nERROR\r" <--- "\r\nERROR\r"
    ] "\n" <--- "\n"
    ] "bu" <--- "bu"
    ] "busy " <--- "sy "
    ] "busy ine" <--- "ine"
    ] "busy inet.." <--- "t.."
    ] "busy inet...\r\n" <--- ".\r\n"
    ] "\r\nER" <--- "\r\nER"
    ] "ERROR\r\n" <--- "ROR\r\n"
     
    

    code now is:

    
    Serial4.setup(9600, { rx: C11, tx : C10 });
    
    
    var http = require("http");
    var wifi = require("ESP8266WiFi").connect(Serial4, function(err) {
      
      if (err) throw err;
      wifi.reset(function(err) {
        if (err) throw err;
        console.log("Connecting to WiFi");
        wifi.connect(wifi.config.ssid,wifi.confi­g.pass, function(err) {
          if (err) throw err;
          console.log("Connected");
          wifi.getIP(function(err,ip){wifi.config.­ip=ip;});
          setTimeout(wifi.userinit.bind(wifi),1500­0);
        });
      });
    });
    wifi.config={ssid:"TwilightZone", pass:"snip", port:80};
    wifi.fpfx="html"; //file prefix for serving files off SD card;
    
    wifi.userinit= function() { //set up the server. 
    	console.log("setting up server on "+this.config.ip+":"+this.config.port);
    	this.server=require('http').createServer­(this.onRequest.bind(this)).listen(this.­config.port);
    };
    wifi.onRequest=function (req, res) {
    	var par=url.parse(req.url,true);
    	var q=par.query; 
    	var nam=par.pathname; 
    	var l=nam.indexOf("/");
    	nam=nam.slice(l);
    	var rd=this.procreq(nam,q);
    	res.writeHead(rd.code,rd.head?rd.head:{'­Content-Type': 'text/plain'});
    	if (!rd.file) {
    		res.write(rd.body);
            res.end();
    	} else {
    		rd.file.pipe(res);
            res.end();
    	}
    };
    
    wifi.procreq = function (path,query) {
    	var paths=path.split(".");
    	var rd={};
    	rd.code=404;
    	rd.body="";
    	// code goes here
        console.log(paths[1]);
    	if (paths[1] in this.handler) {
    		if (paths[0].slice(1) in this.handler[paths[1]]) {
    			rd=this.handler[paths[1]][paths[0].slice­(1)](path,query);
    		} else if ("_" in this.handler[paths[1]]){
    			rd=this.handler[paths[1]]["_"](path,quer­y);
    		} else { rd.body="Handler does not support this file.";}
    	}
    	else {
    		var f = E.openFile(wifi.fpfx+"/"+path, "r");
    		if (f==undefined) {
    			rd.body="File "+path+" not found";
    		} else {
    			rd.code=200;
    			rd.file=f;
    		}	
    	}
    	return rd;
    };
    wifi.handler={};
    wifi.handler.json={};
    wifi.handler.json.status= function (path,query) {
    	 return {code:200,body:'{gtg:true,dtf:false,miss­iles:["armed","armed","repair","mothball­ed"]}'};
    };
    wifi.handler.json._ = function (path,query) {
    	 return {code:404,body:"Invalid json data requested: "+path};
    };
    wifi.handler.run={};
    wifi.handler.run.code= function (path,query) {
    	 try {
    	 	return {code:200,body:+eval(query.code)}; //danger! This is about as insecure as it gets!
    	 } catch(err) {
    	 	return {code:500,body:"Error thrown: "+err};
    	 }
    };
    
    
  • In this state, requests for status.json look like this:

    ] "\r\n" <--- "\r\n"
    ] "+IPD" <--- "+IPD"
    ] "+IPD,2,3" <--- ",2,3"
    ] "+IPD,2,378:GE" <--- "78:GE"
    ] "+IPD,2,376:T /st" <--- "T /st"
    ] "+IPD,2,371:atus.j" <--- "atus.j"
    ] "+IPD,2,365:son H" <--- "son H"
    ] "+IPD,2,360:TTP/1" <--- "TTP/1"
    ] "+IPD,2,355:.1\r\nHo" <--- ".1\r\nHo"
    ] "+IPD,2,349:st: 1" <--- "st: 1"
    ] "+IPD,2,344:92.168" <--- "92.168"
    ] "+IPD,2,338:.2.10" <--- ".2.10"
    ] "+IPD,2,333:2\r\nCon" <--- "2\r\nCon"
    ] "+IPD,2,327:necti" <--- "necti"
    ] "+IPD,2,322:on: k" <--- "on: k"
    ] "+IPD,2,317:eep-al" <--- "eep-al"
    ] "+IPD,2,311:ive\r\n" <--- "ive\r\n"
    ] "+IPD,2,306:Cache-" <--- "Cache-"
    ] "+IPD,2,300:Contr" <--- "Contr"
    ] "+IPD,2,295:ol: ma" <--- "ol: ma"
    ] "+IPD,2,289:x-age" <--- "x-age"
    ] "+IPD,2,284:=0\r\nAc" <--- "=0\r\nAc"
    ] "+IPD,2,278:cept:" <--- "cept:"
    ] "+IPD,2,273: text" <--- " text"
    ] "+IPD,2,268:/html," <--- "/html,"
    ] "+IPD,2,262:appli" <--- "appli"
    ] "+IPD,2,257:cation" <--- "cation"
    ] "+IPD,2,251:/xhtm" <--- "/xhtm"
    ] "+IPD,2,246:l+xml," <--- "l+xml,"
    ] "+IPD,2,240:appli" <--- "appli"
    ] "+IPD,2,235:catio" <--- "catio"
    ] "+IPD,2,230:n/xml;" <--- "n/xml;"
    ] "+IPD,2,224:q=0.9" <--- "q=0.9"
    ] "+IPD,2,219:,image" <--- ",image"
    ] "+IPD,2,213:/webp" <--- "/webp"
    ] "+IPD,2,208:,*/*;q" <--- ",*/*;q"
    ] "+IPD,2,202:=0.8\r" <--- "=0.8\r"
    ] "+IPD,2,197:\nUser-" <--- "\nUser-"
    ] "+IPD,2,191:Agent" <--- "Agent"
    ] "+IPD,2,186:: Moz" <--- ": Moz"
    ] "+IPD,2,181:illa/5" <--- "illa/5"
    ] "+IPD,2,175:.0 (W" <--- ".0 (W"
    ] "+IPD,2,170:indows" <--- "indows"
    ] "+IPD,2,164: NT 6" <--- " NT 6"
    ] "+IPD,2,159:.3; WO" <--- ".3; WO"
    ] "+IPD,2,153:W64) " <--- "W64) "
    ] "+IPD,2,148:Apple" <--- "Apple"
    ] "+IPD,2,143:WebKit" <--- "WebKit"
    ] "+IPD,2,137:/537." <--- "/537."
    ] "+IPD,2,132:36 (KH" <--- "36 (KH"
    ] "+IPD,2,126:TML, " <--- "TML, "
    ] "+IPD,2,121:like G" <--- "like G"
    ] "+IPD,2,115:ecko)" <--- "ecko)"
    ] "+IPD,2,110: Chrom" <--- " Chrom"
    ] "+IPD,2,104:e/41." <--- "e/41."
    ] "+IPD,2,99:0.227" <--- "0.227"
    ] "+IPD,2,94:2.118 " <--- "2.118 "
    ] "+IPD,2,88:Safar" <--- "Safar"
    ] "+IPD,2,83:i/537." <--- "i/537."
    ] "+IPD,2,77:36\r\nA" <--- "36\r\nA"
    ] "+IPD,2,72:ccept" <--- "ccept"
    ] "+IPD,2,67:-Encod" <--- "-Encod"
    ] "+IPD,2,61:ing: " <--- "ing: "
    ] "+IPD,2,56:gzip, " <--- "gzip, "
    ] "+IPD,2,50:defla" <--- "defla"
    ] "+IPD,2,45:te, sd" <--- "te, sd"
    ] "+IPD,2,39:ch\r\nA" <--- "ch\r\nA"
    ] "+IPD,2,34:ccept" <--- "ccept"
    ] "+IPD,2,29:-Langu" <--- "-Langu"
    ] "+IPD,2,23:age: " <--- "age: "
    ] "+IPD,2,18:en-US," <--- "en-US,"
    ] "+IPD,2,12:en;q=" <--- "en;q="
    ] "+IPD,2,7:0.8\r\n" <--- "0.8\r\n"
    ] "+IPD,2,2:\r\n\r\nOK" <--- "\r\n\r\nOK"
    ] "OK\r\nLink\r" <--- "\r\nLink\r"
    ] "\n" <--- "\n"
    json
    ["AT+CIPSEND=2,64\r\nHTTP/1.0 200 OK\r\nServer: Espruino 1v76\r\nContent-Type: text/plain"
    ] "bu" <--- "bu"
    ] "busy" <--- "sy"
    ] "busy inet" <--- " inet"
    ] "busy inet...\r" <--- "...\r"
    ] "\n\r\nERRO" <--- "\n\r\nERRO"
    ] "ERROR\r\n\r\n" <--- "R\r\n\r\n"
    ] "wrong sy" <--- "wrong sy"
    ] "wrong synta" <--- "nta"
    ] "wrong syntax\r\n" <--- "x\r\n"
    ] "\r\nERRO" <--- "\r\nERRO"
    ] "ERROR\r\n\r\n" <--- "R\r\n\r\n"
    ] "wrong s" <--- "wrong s"
    ] "wrong synt" <--- "ynt"
    ] "wrong syntax\r" <--- "ax\r"
    ] "\n\r\nE" <--- "\n\r\nE"
    ] "ERROR\r" <--- "RROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=2,64\r\n\r\n\r\n{gtg:true,d­tf:false,missiles:[\"armed\",\"armed\",\­"repair\",\"moth"
    ] "bus" <--- "bus"
    ] "busy " <--- "y "
    ] "busy inet." <--- "inet."
    ] "busy inet...\r\n" <--- "..\r\n"
    ] "\r\nERROR" <--- "\r\nERROR"
    ] "ERROR\r\n\r\nw" <--- "\r\n\r\nw"
    ] "wrong syn" <--- "rong syn"
    ] "wrong syntax\r" <--- "tax\r"
    ] "\n\r\nER" <--- "\n\r\nER"
    ] "ERROR\r" <--- "ROR\r"
    ] "\n\r\nwr" <--- "\n\r\nwr"
    ] "wrong s" <--- "ong s"
    ] "wrong synt" <--- "ynt"
    ] "wrong syntax\r" <--- "ax\r"
    ] "\n\r\nE" <--- "\n\r\nE"
    ] "ERROR\r" <--- "RROR\r"
    ] "\n" <--- "\n"
    ["AT+CIPSEND=2,9\r\nballed\"]}"
    ] "bus" <--- "bus"
    ] "busy i" <--- "y i"
    ] "busy inet" <--- "net"
    ] "busy inet..." <--- "..."
    ] "busy inet...\r\n" <--- "\r\n"
    ["AT+CIPCLOSE=2\r\n"
    ] "\r\nERROR\r\n" <--- "\r\nERROR\r\n"
    ] "bu" <--- "bu"
    ] "busy " <--- "sy "
    ] "busy in" <--- "in"
    ] "busy inet." <--- "et."
    ] "busy inet...\r" <--- "..\r"
    ] "\n\r\nER" <--- "\n\r\nER"
    ] "ERROR\r" <--- "ROR\r"
    ] "\n" <--- "\n"
    > 
    
    

    What is going on? Does anyone know how to fix this?

  • Strange - so I can get it to stop responding, but it does seem to pull itself back together after a while and respond.

    Looks like it starts off with it responding busy to CIPSEND. Ideally I think Espruino should wait until there's a '>' but it doesn't bother right now. That doesn't seem to be the issue though as it's even responding 'busy' to even CIPCLOSE...

    I quickly googled ESP8266 "busy inet" and there some posts that imply that maybe Espruino should wait >1 sec between sending AT+CIPSEND commands. I'll have to look into it a bit further but it could be that this version of the ESP8266 firmware is a bit flaky as a server.

    Client seems rock solid though - the weather thing is still running fine.

  • Yeah - getting working server is critical for me- this problem is gating several projects that I'd really like to work on, and I'm sure as people get their pico's and ESP's, there will be many more people with the same problem.

  • Yes, sorry about that. It sucks because the firmware version I was told I was getting on the ESP8266 modules isn't what actually came, and then I had to try and get it to work as-is in a short timeframe - it could well be that this wouldn't have been a problem on newer firmware.

    Hopefully once the rest of the Picos are shipped (first half of next week) I'll be able to fix this properly. At least we've got working Picos, on time - and working a WiFi client. The server will be fixable in software, even if I have to write a firmware updater :)

  • Trying this on a Pico through the shim this seems much more reliable.

    0018000902-AI03 firmware

    Was something changed in the module in the past day or two?

    Only thing changed in code is that the file serving stuff is commented out since there's no E.openFile(), though none of the files requested were ever on the SD card. Could that have been causing a problem through spooky means?

  • Strange - it shouldn't have caused a problem - IRQs are always enabled during SPI send, and I only changed the code that I'd mentioned above.

    Thanks for letting me know about filesystem though - that should have been compiled in :(

    Is it possible it could still have been some power fluctuation issue?

  • Yeah, I'm suspicious of power fluctuation as well. I did use a larger cap on the pico shim - an excuse to use one of those 47 uf caps I bought because "wtf 47uf caps that tiny? must have!".

    I'll throw on a larger cap next time I try.

  • Regarding ESP8266 (firmware): may be cloning @Gordon and throw up some kickstarter money for a Gordon-quality ESCOMINO would get everyone in a better state of wifi!

  • Hi!
    I'm facing with the same issue. Only the first http request served.
    I'm using an ESP8266 with this firmware version:

    >Serial2.setup(115200,{
    :  rx:A3,
    :  tx:A2,
    :  bytesize:8,
    :  parity:'none',
    :  stopbits:1,
    :  flow:'none'});
    =undefined
    >Serial2.on('data',function(d) { console.log(d); });
    =undefined
    >Serial2.write("AT+GMR\r\n");
    =undefined
    AT+GMR
    AT version:0.21.0.0
    SDK version:0.9
    .5
    OK
    

    I also have insalled a temperature and air pressure sensor, which I wanted to serve as json data.
    But it arrives like this:

    AT+CIPSEND=0,47
    xt
    
    {"pressure":100727,"temperature":27.8375­}
    

    This is the code I used (Almost identical to the ESP8266's sample code)

    Serial2.setup(115200,{
      rx:A3,
      tx:A2,
      bytesize:8,
      parity:'none',
      stopbits:1,
      flow:'none'});
    status = "Connecting to ESP8266";
    var wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
      if (err) throw err;
      status = "Reseting wifi module";
      wifi.reset(function(err) {
        if (err) throw err;
        status = "Connecting to " + SSID;
        wifi.connect(SSID,code, function(err) {
          if (err) {status = err; throw err;}
          wifi.getIP(function(err, ip){
            status = err || ("IP: " + ip);
          });
          var http = require("http").createServer(onPageReque­st);
          http.listen(80);
          status = "HTTP server started";
          });
        });
      });
    function onPageRequest(req, res){
      res.writeHead(200, {'Content-Type': 'content/text'});
      res.end(JSON.stringify(lastValue));
      status = "Request served";
    }
    

    What is the advised firmware to use on ESP8266?
    Also I'm using an Espruino Pico with 1v79 firmware.

    (Excuse my English, I'm not a native speaker.)

  • What does the Espruino show when it fails to serve the page?

    Does it work better if you wait a minute or two between requests?

  • Nothing. Request handler executes w/o errors, but the browser just hangs and nothing happens.
    I waited 5 minutes between two requests and it just does the same thing.

    Before the first request:

    HTTP server started
    +CIFSR:STAIP,"10.0.0.2"
    +CIFSR:STAMAC,"18:f
    e:34:fd:b8:5f"
    OK
    CIFSR failed: +CIFSR:STAMAC,"18:fe:34:fd:b8:5f"
    OK
    

    First request:

    0,CONNECT
    +IPD,0,304:GET / HTTP/1.1
    H
    ost: 10.0.0.2
    User-Agent: Mozilla/5.0 (Windows NT 10.0;
     WOW64; rv:38.0) Gecko/20100101 Firefox/38.
    0
    Accept: text/html,application/xhtml+xml,a
    pplication/xml;q=0.9,*/*;q=0.8
    Accept-Lan
    guage: hu-HU,hu;q=0.8,en-US;q=0.5,en;q=0.3
    Accept-Encoding: gzip, deflate
    Connection:
    keep-alive
    "HELLO WORLD (1436085723627.167724609377)"
    >
    busy p...
    busy p...
    OK
    >
    >
    SEND OK
    0,CLOSED
    OK
    

    Second request:

    0,CONNECT
    +IPD,0,304:GET /
     HTTP/1.1
    Host: 10.0.0.2
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64;
    rv:38.0) Gecko/20100101 D@yÐP¬Ì ñÿÿÿðÍ cation/xhtml+xml,applicatio
    n/xml;q=0.9,*/*;q=0.8
    Accept-Language: hu-HU
    ,hu;q=0.8,en-US;q=0.5,en;q=0.3
    Accept-Enc
    oding: gzip, deflate
    Connection: keep-alive
    "HELLO WORLD (1436085950000.67041015625)"
    >
    busy p...
    busy p...
    busy p...
    >
    busy p...
    busy p...
    busy p...
    busy p...
    > 
    
  • I think this is because you're using a newer firmware on the ESP8266 - there's a post about someone else having issues with it somewhere else on the forum too :( The one the module is designed for is 0018000902-AI03 - if you flash that onto the ESP8266 then it'll almost certainly work.

    However it should be possible to tweak the existing driver to work with the new ESP8266 firmware - I'll see what can be done with that when I get some time, but if you want to get stuck in then the source is here and you can probably get a much clearer idea of what's going on by calling wifi.at.debug() to dump the commands and responses.

  • Thank you Gordon, I guess I will dig into this, I'll try to find out, whats going on with the new driver :)

    If anybody else looking for the 0018000902-AI03 firmware: Find it here

  • @Pho3nix Thanks, I was struggling to find the right one!

  • Hi - just to let you know I've now created a new driver that should work with the newer 0.25 firmware. Details on the ESP8266 page

  • @Gordon That was my plan for the weekend. I guess I need to find something else then ;)
    Thank you!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ESP8266 server only serves page once, sometimes twice

Posted by Avatar for DrAzzy @DrAzzy

Actions