-
Hi furuskog,
You could make a simple soil moisture sensor using two wires stuck in the soil and connected to 3.3v and A7, then just measure the voltage at A7 by doing something like..
var n=0,i=100; while (i--) n+=analogRead(A7);
Then you can log the data from your soil meter and any other sensors in a google spreadsheet like this example http://www.espruino.com/Logging+to+Google+Sheets
You could handle the alerts from google sheets as the there are add-ons which can email you etc
I made a similar garden thing which has sensors for light intensity, temperature, humidity and soil moisture http://forum.espruino.com/conversations/302202/
Hope that helps
Rob -
-
Yes, two typos there. I do mean CH_PD and it's hardwired to VCC with a 10k resistor (not 1k). GPIO0 and GPIO2 are disconnected. GPIO15 is hardwired to GND with a 10k resistor.
It does seem to me like it should work since when I pull CH_PD to GND or VCC manually with a wire everything works as expected i.e. when CH_PD is connected to GND the ESP8266 powers down and when connected to VCC it powers up.
-
-
Hi, I want to turn my ESP8266 off to save power.
When I try to pulling the CH_PIN pin high with digitalWrite(B9,1) it doesn't power up and I see Uncaught No 'ready' after AT+RST.
I tried using a timeout to give it some time to boot up and also tried pulsing the reset pin.
Also it seems my ESP8266 board has the CH_PD pin hardwired to Vcc via a 1k resistor. If I connect the CH_PD pin to GND, it powers down and if I connect it to the Picos 3.3v pin or leave it dangling it powers up.
-
Thanks for that advice @oesterle. I've had a go and I think it's improved but I can't close the wifi connection. wifi.disconnect() isn't recognised.
Serial1.setup(115200, { rx: B7, tx : B6 }); I2C3.setup({sda:B4,scl:A8}); var bh=require("BH1750").connect(I2C3); var dht = require("DHT11").connect(B5); function read_sensors(callback) { var n=0,i=100; while (i--) n+=analogRead(A7); bh.start(3); light_intensity = Math.round(bh.read()).toString(); soil_moisture = (100-Math.round(n)).toString(); dht.read(function (a) { temp = a.temp.toString(); humidity = a.rh.toString(); callback (light_intensity, soil_moisture, temp, humidity); }); } function send(l,m,t,h) { wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) { if (err) throw err; wifi.connect("Xxx", "xxx", function(err) { if (err) throw err; LED2.set(); sendForm(l,m,t,h); }); }); } function onInit() { USB.setConsole(1); clearInterval(); setInterval(function() { read_sensors(send); },30000); }
-
Hi, I let the program run for 25 hrs, sending to google every 2 minutes but when I look at google for the responses only 417 responses have been logged. It didn't crash but after the first few successful sends it either has the memory error, handshake failed or it works.
>Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... Performing the SSL/TLS handshake... Verifying peer X.509 certificate... it works >Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... ERROR: Failed! mbedtls_ssl_setup: Not enough memory ERROR: Unable to create socket Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... ERROR: Failed! mbedtls_ssl_setup: Not enough memory ERROR: Unable to create socket >Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... Performing the SSL/TLS handshake... ERROR: Failed! mbedtls_ssl_handshake returned -0x4290 >Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... Performing the SSL/TLS handshake... ERROR: Failed! mbedtls_ssl_handshake returned -0x4290 >process.memory(); ={ "free": 3920, "usage": 1180, "total": 5100, "history": 1, "stackEndAddress": 536958120, "flash_start": 134217728, "flash_binary_end": 377416, "flash_code_start": 134234112, "flash_length": 393216 } >Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... Performing the SSL/TLS handshake... Verifying peer X.509 certificate... it works
Is there something wrong with my code again?
function onInit() { USB.setConsole(1); var lastTemp = ""; var lastHumidity = ""; var lastLight = ""; var lastmeasure =""; I2C3.setup({sda:B4,scl:A8}); var bh=require("BH1750").connect(I2C3); var dht = require("DHT11").connect(B5); clearInterval(); setTimeout(function() { Serial1.setup(115200, { rx: B7, tx : B6 }); wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) { if (err) throw err; wifi.connect("xxx", "xxx", function(err) { if (err) throw err; LED2.set(); setInterval(function() { dht.read(function (a) { lastTemp = a.temp.toString(); lastHumidity = a.rh.toString(); }); bh.start(3,1); lastLight = Math.round(bh.read()).toString(); var n=0,i=100; while (i--) n+=analogRead(A7); lastmeasure = (100-Math.round(n)).toString(); setTimeout(function() { sendForm(lastTemp, lastHumidity, lastLight, lastmeasure); }, 5000); }, 120000); // once every 2min }); }); }, 2000); }
-
OK, found an answer in this post
The Web IBE reverts to Serial1 when USB is not connected, that must have been conflicting with the ESP8266 (which was also trying to use Serial1) adding USB.setConsole(1) forces the console to stay on USB.
-
Hi,
I want to connect my Pico to the internet with an ESP8266-12f.
When I send and save() the code using the Web IDE it's fine but then if I disconnect it and power it up with a usb power supply, it doesn't work.
function onInit() { Serial1.setup(115200, { rx: B7, tx : B6 }); var wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) { if (err) throw err; wifi.reset(function(err) { if (err) throw err; wifi.connect("xxx","xxx", function(err) { if (err) throw err; require("http").get("http://www.pur3.co.uk/hello.txt", function(res) { console.log("Response: ",res); res.on('data', function(d) { console.log("--->"+d); if (res.statusMessage == "OK") {LED2.set();} }); }); }); }); }); }
The Pico's green light should switch on if the http response is OK.
I tried this way aswell but still no joy.
E.on('init', function() { Serial1.setup(115200, { rx: B7, tx : B6 }); var wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) { if (err) throw err; wifi.reset(function(err) { if (err) throw err; wifi.connect("xxx","xxx", function(err) { if (err) throw err; require("http").get("http://www.pur3.co.uk/hello.txt", function(res) { console.log("Response: ",res); res.on('data', function(d) { console.log("--->"+d); if (res.statusMessage == "OK") {LED2.set();} }); }); }); }); }); });
-
Thanks @oesterle, it worked a treat.
-
Hi, I'm trying to add a BH1750 sensor to measure light intensity but now when I send the form, after one succesfull send, I get errors...
_____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v91 Copyright 2016 G.Williams > =undefined Saving key Saving cert Saving ca Done! >save() =undefined Erasing Flash..... Writing............................ Compressed 81600 bytes to 26255 Checking... Done! Running onInit()... Connecting to WiFi 192.168.1.68 Connecting to Google Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... Performing the SSL/TLS handshake... >Verifying peer X.509 certificate... Connected to Google Google connection closed, 65577 bytes received process.memory(); ={ "free": 3919, "usage": 1181, "total": 5100, "history": 1, "stackEndAddress": 536958444, "flash_start": 134217728, "flash_binary_end": 378496, "flash_code_start": 134234112, "flash_length": 393216 } Connecting to Google Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... ERROR: Failed! mbedtls_ssl_setup: Not enough memory ERROR: Unable to create socket Connecting with TLS... Loading the CA root certificate... Loading the Client certificate... Loading the Client Key... ERROR: Failed! mbedtls_ssl_setup: Not enough memory ERROR: Unable to create socket >process.memory(); ={ "free": 3868, "usage": 1232, "total": 5100, "history": 1, "stackEndAddress": 536958444, "flash_start": 134217728, "flash_binary_end": 378496, "flash_code_start": 134234112, "flash_length": 393216 }
but it seems like there is enough memory. I don't understand what I've done wrong.
function onInit() { I2C3.setup({sda:B4,scl:A8}); var bh=require("BH1750").connect(I2C3); bh.start(3); var dht = require("DHT11").connect(B5); clearInterval(); // initialise the ESP8266, after a delay setTimeout(function() { Serial1.setup(115200, { rx: B7, tx : B6 }); wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) { if (err) throw err; console.log("Connecting to WiFi"); wifi.connect("xxxx", "xxxx", function(err) { if (err) throw err; wifi.getIP(function(e,ip) { LED2.set(); console.log(ip); setInterval(function() { dht.read(function (a) { sendForm(a.temp.toString(), a.rh.toString(), Math.round(bh.read()).toString()); }); }, 60000); // once a minute }); }); }); }, 2000); }
-
-
Hi, I'm writing some code for my Pico with an ESP8266 which sends temperature and humidity sensor readings to a Google Form (like this tutorial).
I'm using a DHT11 sensor like this...
var dht = require("DHT11").connect(C11); dht.read(function (a) {Temp = a.temp.toString();Humidity = a.rh.toString();});
Then next I send the Temp and Humidity to Google like this...
sendForm(Temp, Humidity);
but the sensor hasn't finished reading yet, it's to soon to send the data. I can use setTimeout to wait a couple of seconds before sending, that works, but I'm thinking I need learn how to use a callback but I can't work out how to write it.
-
Does this tutorial work on Espruino on ESP8266?
I'm trying it but it doesn't send anything?
1v91 Copyright 2016 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 0xe0 chip 0x4016 >Saving key Saving cert Saving ca Done! =undefined undefined Connecting to Google Connecting to Google Connecting to Google
-
-
-
Hi @Robin, the flash recipe you quoted above does not look right, for 1v91 it's...
*** To flash a 4MB esp8266 (e.g. esp-12) using the serial port use: esptool.py --port [/dev/ttyUSB0|COM1] --baud 115200 write_flash \ --flash_freq 80m --flash_mode qio --flash_size 32m \ 0x0000 "boot_v1.6.bin" 0x1000 espruino_esp8266_user1.bin \ 0x3FC000 esp_init_data_default.bin 0x37E000 blank.bin
Also, how do you know the flash recipe for travis builds? The link to travis binaries doesn't include any flash instructions?
Thanks
Rob -
Should be fine. So I guess to get it to boot mode you ground GPIO0 with a resistor, apply power from Espruino, remove the resistor and flash.
In my case the board has v0.60.0 fw so just changing the module ESP8266WiFi_0v25 to ESP8266WiFi solved it for me.
Serial4.setup(115200, { rx: C11, tx : C10 }); var wifi = require("ESP8266WiFi_0v25").connect(Serial4, function() { // ^^^^^^^^^^^^^^^^ // Use ESP8266WiFi here (and 9600 baud) if you have an ESP8266 with firmware older than 0.25 ... }
-
-
-
-
Hi user72696,
Thanks very much for this example, it's the first time I've seen this REST approach so I thought I give your code a try.
It works. If I type "http://192.168.1.70:8080/hello" in the browser then Espruino says "Hello World". I didn't see any problem firing the websocket.
My ESP8266 is already connected to wifi with wifi.save() and I don't have the servos and leds connected so I changed the code a bit..
var wifi = require("Wifi"); var page = '<html><body><script>var ws;setTimeout(function(){'; page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");'; page += 'ws.onmessage = function (event) { console.log("MSG:"+event.data); };'; page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);'; page += '},1000);</script></body></html>'; //Write a response 200 with message on res var httpResp = (res, message) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(message); console.log(message); }; //Parse get request path in the form of /action/port/value and return object var parseREST = (req) => { var RESTReq = {}; var a = url.parse(req.url, true); var pathParts = a.pathname.split("/"); if (pathParts.length == 2 && pathParts[1] === "") { RESTReq.action = "default"; } if (pathParts.length > 1) { RESTReq.action = pathParts[1]; } if (pathParts.length > 2) { RESTReq.port = pathParts[2]; } if (pathParts.length > 3) { RESTReq.value = pathParts[3]; } console.log(JSON.stringify(RESTReq)); return RESTReq; }; function onPageRequest(req, res) { //Path mapping to function for REST API var RESTReq = parseREST(req); if (RESTReq.action == "default") { httpResp(res, "BIPed REST API 0.1"); } else if (RESTReq.action == "hello") { httpResp(res, "Hello World"); } else if(RESTReq.action== "wstest") { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(page); } else if (RESTReq.action == "ledOn") { // digitalWrite(D0, false); httpResp(res, "Red Led On"); } else if (RESTReq.action == "ledOff") { // digitalWrite(D0, true); httpResp(res, "Red Led Off"); } else if (RESTReq.action == "wifi") { httpResp(res, JSON.stringify(wifi.getStatus()) + JSON.stringify(wifi.getIP())); } else if (RESTReq.action == "write") { // digitalWrite(RESTReq.port, RESTReq.value); httpResp(res, JSON.stringify(RESTReq)); } else if (RESTReq.action == "servo") { if (RESTReq.value == "test") { // testServo(RESTReq.port); } else if (RESTReq.value > 0) { // move(RESTReq.port, RESTReq.value / 100); } else { // move(RESTReq.port, 0); } httpResp(res, JSON.stringify(RESTReq)); } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end(JSON.stringify(RESTReq)); } } var server = require('ws'); server.createServer(onPageRequest).listen(8080); server.on("websocket", function (ws) { console.log("WS Connected"); ws.send("Test"); ws.on('message', (msg) => { print("Websocket " + JSON.stringify(msg)); }); });
Also I got some weird "ACORN compiler.js" warnings?
-
The function getTC() is called inside its own definition, maybe that's why, you could try..
var ow = new OneWire(D14); var sensor = require("DS18B20").connect(ow); var cnt=1; function getTC() { sensor.getTemp(function (temp) { console.log("Temp is "+temp+"°C : ",cnt++); }); } setInterval( function() { if(sensor.isPresent()) getTC(); else console.log('no sensor detected'); }, 1000 );
Does that work?
-
esptool doesn't recognise the --chip esp32 option, have I got the wrong tool?
EDIT: yep with this tool it's looking good. Thanks Wilberforce!
I tried a similar sort of thing using a multi-pole switch, I switched the ground wires as well, it worked but there was a flash and the image was distorted momentarily after switching, the image kind of wobbled and vibrated for a second or two. Then the image was ok, there was no noise after the image had settled down but it didn't seem like it was doing the monitor any good so I used to turn the monitor off during switching as a precaution.
I suppose the electro-magnetic coil in the relay would interfere with the signal wire, could you wire it so the signal wire uses the normally closed position so the relay is not energised when the signal is connected?