-
Oh Gordon you genius!
Flow control works, you just have to reconfigure the UART to enable it.
AT+UART=<baudrate>,<databits>,<stopbits>,<parity>,<flow control>
: flow control
‣ 0: flow control is not enabled
‣ 1: enable RTS
‣ 2: enable CTS
‣ 3: enable both RTS and CTSnot sure what RTS is, but CTS works fine.
Also, looks like we now have the baud range that ESP8266 supports:
The range of baud rates supported: 110~115200*40.
From my reading I think the *40 has something to do with the clock speed of the serial line?
Because 115200*40 is 4608000, and that is the baud rate I set that got me into my very nasty mess of needing to reflash the ESP8266. I'm guessing the Espruino just can't go that high.
var wifi = require("EspruinoWiFi"); var http = require('http'); var indexOK = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'></head><body>OK!</body></html>"; var indexBAD = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'><link rel='stylesheet' href='3'></head><body>NOT OK!</body></html>"; var indexVERYBAD = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'><link rel='stylesheet' href='3'><link rel='stylesheet' href='4'></head><body>NOT OK!</body></html>"; function generateJunk(length) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for(var i = 0; i < length; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } function handleHTTPRequest(req, res) { //Flow control close digitalWrite(A15,1); switch (req.url) { case '/': res.writeHead(200, { "Content-Type": "text/html", }); // res.end(indexOK); res.end(indexVERYBAD); break; default: // Generate some CPU load var junk = generateJunk(1024); //console.log(process.memory()); res.writeHead(200, { "Content-Type": "text/css", }); res.end(junk); } //flow control open digitalWrite(A15,0); } wifi.startAP('test', { password: 'mytestap123', authMode: 'wpa2', }, function(err) { if (err) { throw err; } var at = wifi.at; at.cmd('AT+UART_CUR=115200,8,1,0,2\r\n', 10000, function (data) { if (data === 'OK') { // Flow control open digitalWrite(A15,0); // Reconfigure serial Serial2.setup(115200, { rx: A3, tx : A2 }); //Flush anything in at's buffer at.cmd('AT\r\n', 1000, function(data) { console.log(data); console.log('http server started'); http.createServer(handleHTTPRequest).listen(80); }); } }); });
-
-
-
Huh... this is interesting.
console.log('about to start ap'); console.log(E.getErrorFlags()); wifi.startAP('test', { password: 'mytestap123', authMode: 'wpa2', }, function(err) { if (err) { throw err; } console.log('started ap'); console.log(E.getErrorFlags()); console.log('about to start http'); http.createServer(handleHTTPRequest).listen(80); console.log('started http'); console.log(E.getErrorFlags()); });
about to start ap
[ ]
=undefined
started ap
[
"FIFO_FULL"
]
about to start http
started http
[ ] -
Aha, I keep forgetting the
getErrorFlags
.E.getErrorFlags()
=[
"FIFO_FULL"
]Is there any concept of multithreading in Espruino? I'm not even sure if the CPU supports it.
Pre-calculated junk works fine, I was just using it as an example of a "busy" Espruino, whether that is CPU or talking to the SD card.
I tried setting the SD card baud ridiculously high and it still read data, just again I get the stuck HTTP threads.
I'll try this hardware flow control and see if I can get anywhere.
-
Given the following code sample, I can fairly reliably have all the "stylesheets" fail to load when there is CPU load during try to respond to their HTTP requests.
Dial
var junk = generateJunk(45);
up and down to experiment, I got it as far as 1024 when using indexOK, and up to about 60 using indexBAD.If the indexBAD page loads first time, try refreshing a few times, eventually it should stall out.
I'm not sure if anything can be done here. Ideally no matter how intensive the CPU task the HTTP request would eventually complete.
var wifi = require("EspruinoWiFi"); var http = require('http'); var indexOK = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'></head><body>OK!</body></html>"; var indexBAD = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'><link rel='stylesheet' href='3'></head><body>NOT OK!</body></html>"; var indexVERYBAD = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'><link rel='stylesheet' href='3'><link rel='stylesheet' href='4'></head><body>NOT OK!</body></html>"; function generateJunk(length) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for(var i = 0; i < length; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } wifi.startAP('test', { password: 'mytestap123', authMode: 'wpa2', }, function(err) { if (err) { throw err; } http.createServer(function(req, res) { switch (req.url) { case '/': res.writeHead(200, { "Content-Type": "text/html", }); // res.end(indexOK); res.end(indexBAD); break; default: // Generate some CPU load var junk = generateJunk(45); //console.log(process.memory()); res.writeHead(200, { "Content-Type": "text/css", }); res.end(junk); } }).listen(80); });
-
I've got the following code running, deliberately without having an SD card in the slot, but the catch statement never seems to execute. Am I being stupid?
I see
ERROR: Unable to mount media : NOT_READY
on the console but notcaught an error
. If I remove all myconsole.log
, I still getERROR: Unable to mount media : NOT_READY
so I'm assuming it is being logged higher up the stack?SPI1.setup({ mosi: A7, miso: A6, sck: A5 }); E.connectSDCard(SPI1, B1); var fs = require("fs"); try { fs.readdirSync(); } catch (err) { console.log('caught an error'); console.log(err); }
-
Yes
at.debug
definitely causes some issues, its only switched on when I'm trying to debug something :DchunkSize
was definitely still set. I'm trying to figure out a way to sniff the traffic withoutat.debug
. I guess wireshark is my best bet but I'm running short on time, need to get this thing working.Going to try serving gzipped files and see if the size reduction will make this viable. I definitely don't want to switch away from the Espruino... maybe one day you will release an Espruino-Mega ;)
-
I'll try and work up a minimum breaking example tomorrow.
Can you think of any more tips for getting the maximum rates out of the wifi? At the moment I've pushed everything about as far as I think it'll go and I'm getting 16KB in 2.5 seconds, so about 6.4kBps. I must admit I was hoping for something a bit more in the mBps range (although perhaps thats a little over optimistic)... what is likely to be the bottleneck here, the ESP8266 or the Espruino itself?
I've found a thread or two to do with ESP8266 speed, https://github.com/esp8266/Arduino/issues/1853, http://www.esp8266.com/viewtopic.php?f=5&t=245 Espressif quote a slightly higher rate http://bbs.espressif.com/viewtopic.php?t=2187
If I watch the AT debug data, I see 64byte packets being sent more often than not. Is this something I can control?
["AT+CIPSEND=1,131\r\n"
] "\r\nOK\r\n> " <--- "\r\nOK\r\n> "
] "\r\nRecv 131 bytes\r\n" <--- "\r\nRecv 131 bytes\r\n"
] "\r\nSEND OK\r\n" <--- "\r\nSEND OK\r\n"
["AT+CIPSEND=1,64\r\n"
] "\r\nOK\r\n> " <--- "\r\nOK\r\n> "
] "\r\nRecv 64 bytes\r\n\r\nSEND OK\r\n" <--- "\r\nRecv 64 bytes\r\n\r\nSEND OK\r\n"
["AT+CIPSEND=1,64\r\n"
] "\r\nOK\r\n> " <--- "\r\nOK\r\n> "
] "\r\nRecv 64 bytes\r\n" <--- "\r\nRecv 64 bytes\r\n"
] "\r\nSEND OK\r\n" <--- "\r\nSEND OK\r\n"
["AT+CIPSEND=1,64\r\n"
] "\r\nOK\r\n> " <--- "\r\nOK\r\n> "According to the docs for AT+CIPSEND I think it will take up to 2048, so 64 is a bit tiny! http://www.ctr-electronics.com/downloads/pdf/4A-ESP8266__AT_Instruction_Set__EN_v0.40.pdf
-
Hmm, interesting.
Sending an index.html file that contains a link to a stylesheet with
pipe()
without a chunk size, works fine. If the stylesheet is sent usingpipe()
with a chunk size, all ok.However, if you send the index.html with a chunk size, the http request for the stylesheet never arrives at the Espruino even though the browser sends it. I think what is happening is that the connection is held open during the
pipe
, and when another request arrives, the ESP is too busy sending to deal with the arrival.Also +Gordon, while you're looking, can you give me any more info on https://www.espruino.com/Reference#l_SPI_setup with regards to the "baud" rate? What is the unit there? I see a default of
baud:integer=100000
. Can you give some wild guesses what I can increase that to in order to speed up the SD card reads? -
-
Looks like the Espruino_WiFi module doesn't like the 1.3.0 AT command set, so I've stuck with 0.50.0 for now.
esptool command to get that going:
esptool.py -p /dev/tty.SLAB_USBtoUART -b 115200 write_flash 0x00000 noboot/eagle.flash.bin 0x40000 noboot/eagle.irom0text.bin 0x7c000 esp_init_data_default.bin 0x3e000 blank.bin 0x7e000 blank.bin
AT+UART_CUR
now works, and properly resets to default params when the module reboots. Maximum baud I can get is1843200
, so the command is:AT+UART_CUR=1843200,8,1,0,0
-
-
No, I lied, 0.51+ only works on devices with 8Mbit flash and I think the esp8266 we have is 4Mbit. So I have 0.50 official http://bbs.espressif.com/viewtopic.php?f=46&t=1123
I have found some documentation that suggests even the newest firmwares will actually fit on 4Mbit, will give it a try, not sure who to believe! https://syonyk.blogspot.co.uk/2016/11/installing-latest-at-firmware-on-4mbit.html
-
The 0.40 firmware there looks to have some questionable strings in it, I've managed to find 0.60 from espressif official, will let you know how the flashing goes.
*** Modified by ***
HuangRui
vowstar@gmail.com
JiYaping
jyp1817@gmail.com
GET /ota/device/at/rom/v1/?is_format_simple=true HTTP/1.0
Host: service.vowstar.net -
I've got one https://www.amazon.co.uk/gp/product/B01CYBHM26 on the way, should arrive today.
Can you confirm which pins of the usb-ttl I'm hooking to which pins on the ESP8266 module on the WiFi?
I'm guessing I can use the
+
and-
pins on the WiFi itself and hook those to the 5v and GND on the usb-ttl. Not sure where to hook RXD and TXD.Assuming https://github.com/espruino/EspruinoBoard/blob/master/WiFi/pdf/espruino_wifi_sch.pdf is oriented in the real world, I've guessed as per my attachment.
Should I hook usb-ttl RXD to ESP8266 RXD and TXD to TXD or do I want to crossover?
Also, while I think of it, do you have a copy of the AT 0.40 firmware? I was going to flash with 0.25 as it was the newest I could find from your downloads (https://www.espruino.com/files/ESP8266_AT25-SDK112-512k.bin), but I'd rather flash 0.40, I just can't find it.
-
No luck there either. A different language of serial gobbledegook, but the flasher still complains :(
Serial2.setup(57600, { rx: A3, tx : A2 });
=undefined
Serial2.on('data', function(d) { USB.write(d); });
=undefined
=undefined
Serial1.setConsole();FEÚQ ALiÈVPØ¡ÑÜ»êÍ H×¥¡×¥ëL PËÔTGð
-> Serial1
Disconnected -
-
-
Still no joy. Should I expect a specific output before I disconnect the IDE? At the moment I get different responses depending on the baud but nothing readable.
USB.on('data', function(d) { Serial2.write(d); });
=undefined
Serial1.setConsole();þ
-> Serial1
Disconnectedor
=undefined
-> Serial1
ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ
DisconnectedBy doing some mad and barely reproducible set of steps, including a baud rate of 4608000(!), I can occasionally get the flasher to connect
esptool.py v1.3
Connecting....
Running Cesanta flasher stub...
Flash params set to 0x0200
Writing 520192 @ 0x0... 120832 (23 %)
A fatal error occurred: Unexpected packet while writing:but never to complete a write. I get different percentages of success but 23% is the highest so far.
I've ordered a new board because I'm pretty sure I've fried this one :(
-
I had hoped I'd managed to convert the instructions myself, but no luck.
Here's what I had
digitalWrite(A14,1); digitalWrite(A13,0); digitalWrite(A15,0); digitalWrite(A15,1); Serial2.setup(115200, { rx: A3, tx : A2 }); Serial2.on('data', function(d) { USB.write(d); }); USB.on('data', function(d) { Serial2.write(d); }); Serial1.setConsole();
but when I run esptool.py I just get:
esptool.py v1.3
Connecting....
Auto-detected Flash size: 32m
Running Cesanta flasher stub...A fatal error occurred: Invalid head of packet (b'\x13')
-
Oh poop now I killed it by setting an unsupported baud rate.
Gordon could you convert the instructions from http://www.espruino.com/ESP8266 for Flashing the ESP8266 so that they work for the Espruino WiFi? Looks like I need to reflash to get this working again.
-
-
For anyone as silly as me who decides to change the baud rate without waiting for a configurable wifi communication module, here is how to rescue yourself.
AT+CIOBAUD
seems to carry across reboots, which everyone says it doesn't, but it does!digitalWrite(A14, 0); Serial2.setup(9600, { rx: A3, tx : A2 }); at = require('AT').connect(Serial2); at.cmd("\r\nAT+RST\r\n", 10000, function cb(d) { at.cmd(“AT+CIOBAUD=115200\r\n”, 1000, function () { at.debug(); at.cmd(“AT+RST\r\n”, 1000); }); }); digitalWrite(A13, 1); digitalWrite(A14, 1);
+Gordon I guess there is no way to have flow control closed while I'm trying to pipe a long response back to the client, because ofc the data needs to flow back... would be nice if there was just a way to pause incoming connections!
Stuck again! Will your native implementation of the networking help me out of this situation?