-
• #2
Ok got it working with:
var WIFI_NAME = "ssid"; var WIFI_OPTIONS = { password : "pw" }; var wifi = require("EspruinoWiFi"); wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) { ...
But the behavior is the same as with separate ESP8266 module: HTTP request is well received and handled by this code, but response does not arrive to browser when making the request:
var wifi = require("EspruinoWiFi"); wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) { if (err) { console.log("ERROR connect:"); console.log(err); wifi.stopAP(); } else { console.log("Connected"); wifi.getIP(function (err, ip) { if (err) { console.log("ERROR getIP():"); console.log(err); return; } console.log("Web server ip: " + ip.ip); var http = require("http"); http.createServer( function(req, res) { console.log("Client req: " + req.url); if (req.url == "/favicon.ico") { res.writeHead(200, {'Content-Type': 'image/x-icon'}); res.write(favicon); console.log("Client served with favicon.ico"); } else { res.writeHead(200, {'Content-Type': 'application/json', 'Connection': 'close'}); var values = "\nsensors(["+ "{\"sensor\":\"A0\",\"value\":\""+analogRead(A0)+"\"},"+ "{\"sensor\":\"A1\",\"value\":\""+analogRead(A1)+"\"},"+ "{\"sensor\":\"A2\",\"value\":\""+analogRead(A2)+"\"},"+ "{\"sensor\":\"A3\",\"value\":\""+analogRead(A3)+"\"},"+ "{\"sensor\":\"A4\",\"value\":\""+analogRead(A4)+"\"},"+ "{\"sensor\":\"A5\",\"value\":\""+analogRead(A5)+"\"}])"; res.write(values); console.log("Client served with: " + values); } res.end(); }).listen(80); }); } });
Console says "Client served with: ...", but that response never arrives to chrome browser that I am testing with.
What is wrong with the code above or the setup (EspruinoWifi plugged into laptop USB)?
-
• #3
Also the web server tries to respond only once and does not even get the following requests until reset..
-
• #4
Serving favicon.ico works multiple times to the browser so what is wrong with the JSON response since that hangs?
-
• #5
Attached file contains code to serve HTML. It does both a Get and Post method.
You will need to edit the SSID and router password.
Adjust the serial port stuff to fit your hardware.The IP address will display in the WebIDE
Mine was 192.168.3
I used it in the Browser as follows:You will need to modify the doGet() function at the bottom to serve your content.
function doGet(req,res){ var a = url.parse(req.url, true); console.log("Get"); res.writeHead(200, {'Content-Type': 'text/html'}); res.write(KMtext); res.end(""); }
1 Attachment
-
• #6
The setup procedure is documented on http://www.espruino.com/WiFi - I'm afraid the boards that I'm selling right now don't have the 'getting started' card (just the web address on the PCB). I will add one, but I'm a bit busy getting Puck.js out there at the moment so intentionally haven't been pushing EspruinoWifi very much.
I'm pretty sure your problem is that you're reading analog values from A2 and A3, which the ESP8266 is connected to (so it'll put those pins into analog input mode, which will then cause the ESP8266 to become unresponsive).
If you remove
analogRead(A2)
andanalogRead(A3)
it should work fine - I just tested and it works here. -
• #7
Yes that was the reason.
Ok, so those analog pins cannot be used.
What are all the analog pins that can be used? -
• #8
There's a diagram here: http://www.espruino.com/WiFi#pinout
The pins marked with blue
ADC
on the board itself can be used. On Espruino WiFi any pin that you can physically connect to is free for you to use (although B6/B7 have the Espruino console on them when USB is disconnected - I'll update the docs).Anything with a Pink mark is used for other functionality and can't be used.
-
• #9
Is it the same when using ESP8266 as a separate module that A2 and A3 should not be used?
By the way, Thanks for the quick solution!
-
• #10
And can I somehow detect if an analog pin is connected or not?
-
• #11
Any pin which you have connected to the ESP8266 should not be used for any other purpose. I don't know how you wired it - if you're using the Pico shim, it does use those same pins (see the pinout chart in http://www.espruino.com/ESP8266 ); I think the pico shim pinout was recycled for the WiFi. If you are not using the Pico shim, only you know which pins you have it connected to.
There is not a way to detect if a pin is already "used" for something else. As Gordon noted, the pinout chart marks which ones are unavailable on the board, before you start connecting stuff to it.
Once you start connecting other devices to it, it's your responsibility to know which pins you connected things to - I can't think of a good way to make it warn you about using pins that aren't available because you've already connected them to something else.It would be nice if there were a way to warn the user when they yanked pins out from under something - maybe an E.warnOnModeChange(pin) call that could be put into a module to mark those pins as being used for something?
-
• #12
Is it the same when using ESP8266 as a separate module that A2 and A3 should not be used?
As @DrAzzy says, yes. The wiring for the Espruino WiFi isn't exactly the same as the shim (so that you have a few more analogs available), but A2+A3 are some of the only UART pins so have to be used.
Probably the easiest thing is to figure out which analogs you want to use, and then put them in an array:
var ANALOGS = [A0,A1,A4,A5,...]
. You can then just doanalogRead(ANALOGS[...])
in your code, which might be a bit more readable.The whole pin naming is a bit confusing, but Espruino boards use the pin names provided by the chip's manufacturer rather than making up new ones. It's a pain when starting off but makes it a whole lot easier and less confusing if you move on to more advanced things.
It would be nice if there were a way to warn the user when they yanked pins out from under something
Hmm - interesting idea... I wonder whether that would get annoying for some users? I guess there could be a way to explicitly disable it though.
-
• #13
Thanks for the reply and support!
I used the pico shim v1 with the ESP8266.The plan is to support old standard zero to 180 ohm analog fuel tank level gauges. (I did the same with Arduino, but it was not reliable enough and hang after awhile and even watchdog did not work.)
To measure the resistor sensor it would be connected like this:
|------Sensor-----A1 pin
|
|----------------GND pin
|
|------Rref------+3.3v pinThe idea was to use 20 ohm resistor as Rref to give enough value range for analog measurement as the sensor resistance varies between 0 and 180 ohms.
Do you see any problems in this plan or ideas for improvement?
The same wiring would be done for all ADC pins available to enable several sensors to be read.Now I would like to know if there is the resistor sensor connected or not.
And then make another standard sensor that works from 30 to 240 ohms range as an alternative option that would be selected with e.g. dip switch for changing the Rref or telling the option to Espruino as digital input so that the values can be scaled accordingly.
-
• #14
I'm not 100% sure I understand - usually you would do:
____ ____ -----------|____|--------------|-------|____|--------- 3.3v GND Sensor | 20 Ohm Espruino Analog
Is that what you had planned? The only things I would suggest are:
- Use twisted pair cables to the sensors, to reduce noise
Put a resistor and large capacitor (10uF?) between GND and the analog input, near the Espruino board. The fuel sensor value won't move quickly, and the capacitor will help to stop noise being transferred to Espruino.
____ ____ -----------|____|--------------|-------|____|--------- 3.3v GND Sensor _|_ 20 Ohm | | | | |_| 1k Ohm 10uF | | | | -------------| |---------------| GND | | | Espruino Analog
- Use twisted pair cables to the sensors, to reduce noise
-
• #15
Anything with a Pink mark is used for other functionality and can't be used.
Espruino Wifi PINOUT Documentation states as first line:
Purple boxes show pins that are used for other functionality on the board. You should avoid using these unless you know that the marked device is not used.
...and these pins are listed in the PINS NOT ON CONNECTORS.
In other words, pins that are not on connectors of the board should not be used (in the code).
Purple/Pink... mileage varies with color calibration of the display... :)
A subject oriented comment:
With a 0..240 Ohm sensor and a current limiting resistor of 20 Ohm, a lot of power / current is used for just one sensor: 165mA... if yo have many of those, you might consider a separate 3.3V supply to not make the board to brown out... Last but not least when running of a regular USB, which supplies only 500mA... and ESP8266 is already consuming a lot of that... (at least during transmitter calibration phase(s)). Depending on the length of the line and the environmental noise, going for a 240 (270) Ohm resistor gives you still an 'incredible' resolution. Regarding placement of the capacitor and 1 KOhm resistor: @Gordon, I assume it is 'board-side' of the wires.
-
• #16
@allObjects good point about the power consumption - that could cause real problems.
And yes, the capacitor/1k resistor should be as close to the board as possible.
-
• #17
With 270 Ohm resistor can I use all the analog pins?
What would be good step-down converter for 3.3V output? The DC voltage available may vary a lot from 9V to 16V (around 12V) or from 18V to 30V (around 24V), so I need converter that accepts wide input voltage range and stable 3.3V output.
With external power can the GND pin sink the current without overheating? -
• #18
All grounds should go to a single point... and because you measure with Espruino, I'd put all grounds to one point where also Espruino GND connects to (as short as possible)... Both power supplies - the Espruino (for controls) and the peripherals (sensors) - go to one point, to which also all sensor grounds and Espruino ground goe (Espruino with as short as possible line). I'd not connect the sensor grounds on the Espruino pin. Intentionally I said both power supplies... I would separate them... or having good filtering / decoupling.
From your context I conclude that your power environment is 12 or 24 volts with +4-3V and +6-6V... (Car or Truck/heavy Vehicle DC ...or solar/UPS battery bank). You have options to run different resistors to limit current even more while having full range over 3.3V by the gauge's/sensors max resistance. Going beyond 5 V supply for the sensors, you would have to protect the inputs with some Zener diodes.
Depending on the noise and length of sensor line lengths, you could go for higher resistors than 270 ohms... of course all dependent on the accuracy you expect from measures... and shielded wires could help with it.
-
• #19
In terms of 3.3v power supplies, I can't really recommend anything - it'd just be a matter of checking datasheets.
However, with 270 Ohm things would be much better - you wouldn't get full swing on the ADC input, but it's accurate enough that you'd still get a pretty good fuel level reading. I guess each sensor might draw 10mA, so you have loads of room on the Pico's 250mA voltage regulator.
It means you can use the Pico's voltage regulator, so you can feed it with higher voltages - 5 to 12 volts might be a good start. You could use a totally standard voltage regulator. For instance ST's L78S05CV looks like it'll take up to 35V in and give you 5v out, so would do you fine.
I just bought the Espruino Wifi (in order to overcome the problems of using separate ESP8266 module that did not respond to HTTP requests and flashing an upgrade did not work).
I cannot Espruino Wifi board v1.1 to work and cannot find working examples..
This code:
Serial2.setup(115200, { rx: A3, tx : A2 });
var wifi = require("ESP8266WiFi_0v25").connect(Serial2, function(err) {
I get error: "No 'ready' after AT+RST"
What module name should be used?
It has Espruino 1v87.
Could someone post simplified web server code?