-
-
Here is an example that causes errors...
var wifi;
var wifiTry = 1;
function connectWifi(){
console.log("Connecting to WiFi");
wifi.connect("access","password", function(err) {
if (err) {
throw err;
}
console.log("Connected!");
wifi.getIP(function(e, ip) {
LED2.set();
console.log(ip);
});
});
}
//checks the ESP8266 connection status
function espStatus(callback){
wifi.at.cmd('AT+CIPSTATUS\r\n',1000,function(d){
console.log('ESP8266 '+d);
var status = d.slice(-1);//get the last character
if(status == 2){//connection is good
console.log('good connection');
wifiTry=0;
}else if(wifiTry>1){
clearInterval();//clearInterval is causing issues here
wifiTry=0;
console.log('end');
}else{//connection is bad and we need to reconnect
wifiTry++;
console.log('bad connection');
//need timeout to give esp8266 time to think.
setTimeout(connectWifi,500);
}
});
}
function onInit() {
clearInterval();
E.enableWatchdog(10, true); //should restart the pico if it freezes
// initialise the ESP8266, after a delay
setTimeout(function() {
digitalWrite(B9,1); // enable on Pico Shim V2
Serial2.setup(115200, { rx: A3, tx : A2 });
wifi = require("ESP8266WiFi_0v25").connect(Serial2, function(err){
if(err){
throw err;
}
connectWifi();
setInterval(espStatus, 30000);
});
}, 2000);
}
And this is the error:
Uncaught Error: Unknown Timeout
at line 1 col 52
...))?(d=p,b=f):clearTimeout(e);void 0===d&&0<g.length&&(a=g.sh...
^
in function "d" called from line 1 col 324
...c&&(e[c](k),n=!0);n||d&&d(k)}a=a.substr(f+1);"\n"==a[0]&&(a=...
^
in function called from system
-
under else if statement: Still clearing the setTimeout even though it is run after clearInterval
function espStatus(callback){
wifi.at.cmd('AT+CIPSTATUS\r\n',1000,function(d){
console.log('ESP8266 '+d);
var status = d.slice(-1);//get the last character
if(status == 2){//connection is good
console.log('good connection');
wifiTry=0;
}else if(wifiTry>3){
clearInterval();//clearInterval clears both intervals and timeouts!!
wifiTry=0;
setTimeout(startServer,500);
}else{//connection is bad and we need to reconnect
wifiTry++;
console.log('bad connection');
//need timeout to give esp8266 time to think.
setTimeout(connectWifi,500);
}
});
}
-
-
Shouldn't the following code output (from console.log()) onInit, foo, bar ?? Instead on onInit, foo ??
It seems that clearInterval is killing the setTimeout? That's not normal is it?function bar(){
console.log('bar');
}
function foo(){
console.log('foo');
setTimeout(bar, 500);
clearInterval();
}
function onInit(){
console.log('onInit');
setInterval(foo, 500);
}
onInit();
I'm on PICO:
"VERSION": "1v89.11",
"BUILD_DATE": "Nov 22 2016",
-
I set up my own pass through server app that is getting the information where it needs to go. Sorry @Gordon I just do not know what else to do with this. I wonder if this is something to do with my location and country? I did at one time get it to work on the wiznet, but my application would be much nicer with esp8266. I'll keep plugging at it every now and then. Thanks again.
-
A minute after gaining wifi connection this all happens right in a row...... no time gap.
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...
Performing the SSL/TLS handshake...
Then after another minute:
Connecting to Google
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 Not enough memory
ERROR: Failed! mbedtls_ssl_handshake returned Public key type mismatch
-
I recopied everything exactly from the example:
Connecting to Google
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 -0x3b10
ERROR: Failed! mbedtls_ssl_handshake returned -0x4290
I'll also put together a push through node app to get me going in the mean time and I'll keep trying to figure this out from my end. Let me know if you can think of anything else I can try on the Pico.
-
Linux: Yeah I've never had a problem with it.....
Latest Version: Ok Sorry about that I thought I downloaded the right version..... anyways downloaded from the link and.......
ESP8266 version check isAT version:0.25.0.0(Jun 12 2015 20:26:28)\r\nSDK version:1.1.2\r\ncompile time:Jun 17 2015 22:11:51
now we have:
Connecting to Google
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
ERROR: Failed! mbedtls_ssl_handshake returned -0x4290
and
ERROR: Failed! mbedtls_ssl_handshake returned Not enough memory
ERROR: Failed! mbedtls_ssl_handshake returned -0x4290
Right now I am really busy trying to understand exactly how this communication works. Do we really need the cert and key? I have a test client through NodeJs and it is sending fine with one of their known "root" CAs. I think these are them.
Much thanks for your help @Gordon. This is really going to do well for me once we get this figured out.
-
-
-
I jumped back to "VERSION": "1v86", "BUILD_DATE": "Jul 6 2016" and it gets the error codes as on post #108. On version "VERSION": "1v89", "BUILD_DATE": "Nov 15 2016" it just freezes up. As far as the code please reference Logging to Google sheets. I have tried my own 2048 bits keys as @Ollie stated. Nothing has changed from previous posts of 9 months ago. This is a project that I was working on then and decided that I might just wait a while for things to come around.
-
-
@Ollie I actually looked that thread over and did try that key. I also have the 47uF capacitor. I even put the E.enableWatchdog() to help with unplugging it every time. Not sure what to do now.....
-
-
var page = "<!DOCTYPE html>\n<html>\n <head>\n <title>Sprinkler System</title>\n <script>\n function response(arr,type){//arr is in JSON\n if(type===\"get\"){\n document.getElementById(\"get\").style.backgroundColor=arr.color;\n }else{\n document.getElementById(\"post\").style.backgroundColor=arr.color;\n }\n }\n \n function postServer(color){\n var req = new XMLHttpRequest(),\n obj = {'color':color,'the':'rest','are':'test','Red':'red','Purple':'purple','Green':'green','Yellow':'yellow'},\n arr;\n req.open(\"POST\",\"/\", true);\n req.setRequestHeader(\"Content-type\", \"application/json\");\n req.onreadystatechange = function(){\n if(req.readyState === 4){\n var status = req.status;\n if(status>=200 && status <300 || status === 304){\n arr=req.responseText;\n arr=JSON.parse(arr);\n response(arr,\"post\");\n }else{\n alert(\"something bad\");\n }\n }\n }\n \n obj=JSON.stringify(obj);\n console.log(obj);\n req.send(obj);\n }\n function postControl(){\n var color = document.getElementById(\"post\").style.backgroundColor;\n postServer(color);\n \n }\n \n function getServer(color){\n var req=new XMLHttpRequest(),\n arr;\n req.open(\"GET\", \"?color=\"+color, true);\n req.onreadystatechange = function(){\n if(req.readyState === 4){\n var status = req.status;\n if(status>=200 && status <300 || status === 304){\n arr=req.responseText;\n arr=JSON.parse(arr);\n response(arr,\"get\");\n }else{\n alert(\"something bad\");\n }\n }\n }\n req.send(null);\n }\n function getControl(){\n var color = document.getElementById(\"get\").style.backgroundColor;\n getServer(color);\n }\n </script>\n </head>\n <body>\n <button style=\"background-color:red\" id=\"post\" type=\"button\" onclick=\"postControl()\">POST</button>\n <button style=\"background-color:red\" id=\"get\" type=\"button\" onclick=\"getControl()\">GET</button>\n </body>\n</html>";
/*
server side javascript
*/
function colorChange(data){
var obj = {'color': null},
color = data.color;
if(color === "red"){
obj.color = 'green';
}else{
obj.color = 'red';
}
return obj;
}
function pageHandler(req, res) {
var info, data='';
if (req.method=="POST") {
// If it's a POST, save the data
req.on('data',function(chunk){
if(chunk){
data+=chunk;
}
if(data.length>=Number(req.headers['Content-Length'])){
data = JSON.parse(data);
data = colorChange(data);
res.writeHead(200);
res.end(JSON.stringify(data));
}else if(data.length>Number(req.headers['Content-Length'])){
res.writeHead(418);
res.end('alert("data was corrupted")');
}
});
} else {
// otherwise write the page out
if (req.url=="/") {
res.writeHead(200);
res.end(page);
} else {
info = url.parse(req.url, true);
if (info.query && "color" in info.query){
data = colorChange(info.query);
res.writeHead(200);
res.end(JSON.stringify(data));
} else {
res.writeHead(404);
res.end("404: Not found");
}
}
}
}
//WIFI
var WIFI_NAME = "WIFI";
var WIFI_PASS = "password";
digitalWrite(B9,1); // enable on Pico Shim V2
Serial2.setup(115200, { rx: A3, tx : A2 });
function onInit(){
var wifi = require("ESP8266WiFi_0v25").connect(Serial2, function(err) {
if (err) throw err;
wifi.reset(function(err) {
if (err) throw err;
console.log("Connecting to WiFi");
wifi.connect(WIFI_NAME, WIFI_PASS, function(err) {
if (err) {
onInit();
throw err;
}
console.log("Connected");
// print IP address
wifi.getIP(console.log);
// Create a server
require("http").createServer(pageHandler).listen(80);
});
});
});
}
onInit();
-
A simple web interface using the ESP8266 as a web server. This example sends the current buttons color to the ESPRUINO PICO and then the pico sends back the other color. (red or green) Changes the buttons color. There is a bunch of extra JSON and this is to represent multiple reads to get all of the JSON.
<!DOCTYPE html>
<html>
<head>
<title>POST GET EXAMPLE</title>
<script>
function response(arr,type){//arr is in JSON
if(type==="get"){
document.getElementById("get").style.backgroundColor=arr.color;
}else{
document.getElementById("post").style.backgroundColor=arr.color;
}
}
function postServer(color){
var req = new XMLHttpRequest(),
obj = {'color':color,'the':'rest','are':'test','Red':'red','Purple':'purple','Green':'green','Yellow':'yellow'},
arr;
req.open("POST","/", true);
req.setRequestHeader("Content-type", "application/json");
req.onreadystatechange = function(){
if(req.readyState === 4){
var status = req.status;
if(status>=200 && status <300 || status === 304){
arr=req.responseText;
arr=JSON.parse(arr);
response(arr,"post");
}else{
alert("something bad");
}
}
}
obj=JSON.stringify(obj);
console.log(obj);
req.send(obj);
}
function postControl(){
var color = document.getElementById("post").style.backgroundColor;
postServer(color);
}
function getServer(color){
var req=new XMLHttpRequest(),
arr;
req.open("GET", "?color="+color, true);
req.onreadystatechange = function(){
if(req.readyState === 4){
var status = req.status;
if(status>=200 && status <300 || status === 304){
arr=req.responseText;
arr=JSON.parse(arr);
response(arr,"get");
}else{
alert("something bad");
}
}
}
req.send(null);
}
function getControl(){
var color = document.getElementById("get").style.backgroundColor;
getServer(color);
}
</script>
</head>
<body>
<button style="background-color:red" id="post" type="button" onclick="postControl()">POST</button>
<button style="background-color:red" id="get" type="button" onclick="getControl()">GET</button>
</body>
</html>
-
-
-
-
So I actually tore into my oscilloscope and found that a wire on the horizontal deflection plate was disconnected. Anyways, I can say that when less than about 9.5 volts the pico keeps working. 10 volts will cause a slow resetting of the pico while at 13 volts it will reset quite a bit faster. Also at 10 volts it takes a few seconds before it started resetting where as 13 volts it's immediate. The USB side of the Schottky diode appears to be pulsing and the BAT side is steady. So at BAT 12 volts the USB side is jumping between around 3.3 volts and 8 volts. FET and B0 are not connected and when checked for resistance do not register at all. The supply side of the regulator is steady at BAT Volts and GND is steady 0v where 3.3 pulses to 0v
-
So I checked it over extensively and here is where I am at. I have a NRF905 connected exactly as follows:
var data, csn = B10, dr = B1, txen = A6, ce = A7;
SPI2.setup({sck:B13, miso:B14, mosi:B15});
var nrf = require("NRF905").connect(SPI2,csn,dr,txen,ce);
var myAddress = 0x17;
var masterAddress = 0x27;
function rx_callback(data){
console.log("got "+JSON.stringify(data));
}
E.on('init', function() {
clearWatch();
clearTimeout();
nrf.init(myAddress, rx_callback);
});
save();
When I have the PICO connected to the NRF905 with the computer powering everything works fine. When it is connected to the the battery without the NRF905 I can still talk to it with the computer. When connected with the battery and NRF905 then all connection is lost and am unable to reconnect. The pico led blinks very fast.
The pins seem to read as follows (connected to computer only, or connected to battery without NRF905):
Bat in is 13V, B15 is 3.3v, B14 is floating, B13 is 0v, B10 is 3.3v, B1 is floating, A7 is 3.3, A6 is 0v, A5 is floating.With the battery they are similar but seem to be resetting over and over.
GND is 0v, VBAT is 13V, VDD is 3.3v, B3 is floating, B4 is floating, B5-A8 are 0v.
I do have an oscilloscope but its currently not working properly..... And not sure where to even begin even if it were working......
-
-
I have not done the FET tutorial. This is consistent on every PICO I have tried thus far. Its a little concerning because the current project is similar to what your doing. I am actually creating a wireless sprinkler control system where I have solar panels built into the in ground sprinkler boxes connected to a 12 volt battery. I can add a lm7810 to the circuitry but was hoping to get away without having to. I did try cleaning the back up with alcohol and still no change.
Couldn't you also set up a captive portal with this?