-
In the code titled //UDP_TCPclient1.js //2 Oct 2016
The following is the menu system.
Entering a character zero 0 followed by a return should reset the USB.
If you wrapped the code in an oninit() and saved it so it loads on boot,
then power up the board, quickly connect with WebIDE and type 0 return in the left pane
you should be able to reset the USB port.//Menus menu=function(){ USB.print(" \n\r"); USB.print("Select using digit and return key\n\r"); USB.print("1 LED Off\n\r"); USB.print("2 LED On\n\r"); USB.print("0 Exit\n\r"); }; parsecmd=function(){ USB.print("\n\r"); switch(this.sst.charAt(0)){ case "1"://LED off sst=""; USB.print("LED Off\n\r"); sendit("LED Off"); break; case "2"://LED On USB.print("LED On\n\r"); sst=""; sendit("LED On"); break; case"0"://Exit LoopbackA.print("USB.setConsole();\n\r"); sst=""; USB.print("Exit\n\r"); break; default: menu(); break; }//end switch sst };//end parsecmd //input cmd from terminal,send it to parsecmd() USB.on('data', function (data) { var i; sst+=data; USB.print(data); if(sst.length>0) if(sst.charAt(sst.length-1)==="\r")parsecmd(); }); //Espruino replies here LoopbackA.on('data',function(data){ USB.print(data); //sending data to terminal }); ///////////////////////// setTimeout(function () { var x; console.log("Start"); LoopbackB.setConsole(); x=test(); if(x!==0)console.log("Try again");//error seen if(x===0) console.log("Exit Seen"); }, 1000);
The left screen
>echo(0); =undefined Start -> LoopbackB <- USB Start connection process Try again Reset the ESP8266 Connecting to WiFi OKxx1 OKxx2 >0 I entered a zero return Exit <- LoopbackB =undefined =undefined >USB.setConsole(); -> USB 1 I entered a 1 return =1 >
-
If you upload and then enter 0 return in the left pane it exits the menu.
Once the two Picos connect via the UTP exchange the menu shows up.
The menu shows option zero '0' .
If you upload and don't use the zero to exit a second upload will display all sorts of stuff on the left pane and the zero option no longer works.
As for yellow warnings, I'm not seeing them in v1.86 or v1.88 of EspruinoPlease change the broadcast address so it doesn't UDP the entire Internet.
//var BroadIP="255.255.255.255";
var BroadIP="192.168.1.255"; -
Ah Ha!
The program creates a menu system for the left pane of the WebIDE by redirecting the USB port. If you enter a zero followed by a return in the left pane it will exit the menu mode and return to the Console mode.
The other method is to exit WebIDE and cycle the power on the PICO-ESP8266 and reconnect. -
This experiment used two Picos and two ESP8266. One Pico-ESP8266 (via serial) runs the server code and the other Pico-ESP8266 runs the client code.
The ESP8266Wifi_0v25.js file was copied from the modules on the Espruino site, edited and saved us the UDP file. The UDP file was placed in the local modules directory of the WebIDE project on my PC. Upper right hand corner of WebIDE 'Gear' icon, and the Projects Tab, sets up the projects directory.
The UDP modifications are based on ESP8266 firmware version 1.0 or later. -
The code you are trying to load is for either an espruino board or Pico connected via serial port to an ESP8266. It doesn't currently work on an ESP8266 flashed with the Espruino firmware. That would require modification to the Espruino source code and a recompile. As a consumer of Espruino I'm not currently setup to do such a task. Perhaps some of the ESP8266 folks on the Forum who are so equipped can comment further.
Some modules are built into the firmware and aren't listed in the modules on the Espruino site.
Which hardware combination are you trying to use?
-
The code you are trying to load is for either an espruino board or Pico connected via serial port to an ESP8266. It doesn't currently work on an ESP8266 running Espruino. That would require modification to the Espruino source code and a recompile. As a consumer of Espruino I'm not currently setup to do such a task. Perhaps some of the ESP8266 folks on the Forum who are so equipped can comment further.
-
Probably these links are more than you want for such a cool project, that's for you to decide.
But you did ask about phone orientation and mention the compass.http://rouel-projects.blogspot.com/p/calculations-with-iphones.html
https://www.safaribooksonline.com/library/view/basic-sensors-in/9781449309480/ch04.html
http://hackaday.com/2013/07/31/an-introduction-to-inertial-navigation-systems/
-
-
Found a solution changed 6 to 60 on the outer setInterval of the module
var dpin=B3; var F; var H; function DHT22(pin) { this.pin = pin; } DHT22.prototype.read = function (cb, n) { if (!n) n=10; var d = ""; var ht = this; pinMode(ht.pin); // set pin state to automatic digitalWrite(ht.pin,0); // digitalWrite([ht.pin,ht.pin,ht.pin,ht.pin,ht.pin],0x0a); this.watch = setWatch(function(t) { d+=0|(t.time-t.lastTime>0.00005); }, ht.pin, {edge:'falling',repeat:true} ); setTimeout(function() {pinMode(ht.pin,'input_pullup');},1); setTimeout(function() { clearWatch(ht.watch); delete ht.watch; var cks = parseInt(d.substr(2,8),2)+ parseInt(d.substr(10,8),2)+ parseInt(d.substr(18,8),2)+ parseInt(d.substr(26,8),2); console.log(n,d.length,cks&0xFF,parseInt(d.substr(34,8),2)); if (cks&&((cks&0xFF)==parseInt(d.substr(34,8),2))) { cb({ raw : d, rh : parseInt(d.substr(2,16),2)*0.1, temp : parseInt(d.substr(19,15),2)*0.2*(0.5-d[18]) }); } else { if (n>1) setTimeout(function() {ht.read(cb,--n);},500); else cb({err:true, checksumError:cks>0, raw:d, temp:-1, rh:-1}); } },60); //////Changed value to 60 from 6 }; //var dht = require("DHT22").connect(dpin); var dht=new DHT22(dpin); setInterval(function () { dht.read(function (a) { F=(a.temp+40)*9/5-40; H=a.rh; console.log("Temp is "+F.toString()+" and RH is "+H.toString()); }); // }); }, 1000);
Sample output Temperature in F.
>echo(0); =undefined 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3 10 42 164 164 Temp is 71.96 and RH is 45.3
-
Data rate is not an issue as I use the DH22 to turn my window AC on and off based on keeping temperature and RH within a comfort zone. In my climate humidity is a factor in maintaining comfort and temperature alone either freezes me or I wake up in the night with too much humidity. Sampling every minute or longer should suffice.
As to the two second interval, the module code does up to 10 retires one after the other. Perhaps the 2 second specification is related to the accuracy of the reading and not to the ability to read data from the device.
The hardware is setup on a solder less breadboard with 6 inch jumper wires and a 4.7k pullup resistors.
As to the double pulse idea, I tried that and it doesn't trigger the device any better than the single pulse.
Thanks for the alternate parts list, I will investigate.
-
Let me restate the problem.
I pulled the DHT22.js module and inserted a console.log for illustration.
Here is where the console.log was inserteddelete ht.watch; var cks = parseInt(d.substr(2,8),2)+ parseInt(d.substr(10,8),2)+ parseInt(d.substr(18,8),2)+ parseInt(d.substr(26,8),2); console.log('n=',n,'len=',d.length,' cks=',cks&0xFF,' chsum=',parseInt(d.substr(34,8),2)); if (cks&&((cks&0xFF)==parseInt(d.substr(34,8),2))) {
The example code
var dht=new DHT22(dpin); setInterval(function () { dht.read(function (a) { F=a.temp; H=a.rh; console.log("Temp is "+F.toString()+" and RH is "+H.toString()); }); }, 2000);
Produces the following output:
n= 3 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 10 len= 0 cks= 0 chsum= NaN n= 6 len= 0 cks= 0 chsum= NaN n= 9 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 5 len= 0 cks= 0 chsum= NaN n= 4 len= 42 cks= 202 chsum= 202 Temp is 23.2 and RH is 48.1 n= 10 len= 42 cks= 202 chsum= 202 Temp is 23.2 and RH is 48.1 n= 10 len= 42 cks= 202 chsum= 202 Temp is 23.2 and RH is 48.1 n= 10 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 10 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 10 len= 40 cks= 200 chsum= 50 n= 9 len= 41 cks= 200 chsum= 100 n= 8 len= 41 cks= 200 chsum= 100 n= 7 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 10 len= 0 cks= 0 chsum= NaN n= 9 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 10 len= 42 cks= 202 chsum= 202 Temp is 23.2 and RH is 48.1 n= 10 len= 42 cks= 201 chsum= 201 Temp is 23.2 and RH is 48
Notice that the module code produces a lot of retries n. 1st try n=10, 2nd try n=9...
By changing the example code to
var dht=new DHT22(dpin); setInterval(function () { dht.read(function (a) {}); dht.read(function (a) { F=a.temp; H=a.rh; console.log("Temp is "+F.toString()+" and RH is "+H.toString()); }); }, 2000);
Which gives to following output
>echo(0); =undefined n= 10 len= 43 cks= 201 chsum= 201 n= 10 len= 43 cks= 201 chsum= 201 Temp is 23.2 and RH is 48 n= 10 len= 43 cks= 199 chsum= 199 n= 10 len= 43 cks= 199 chsum= 199 Temp is 23.2 and RH is 47.8 n= 10 len= 43 cks= 198 chsum= 198 n= 10 len= 43 cks= 198 chsum= 198 Temp is 23.2 and RH is 47.7 n= 10 len= 43 cks= 198 chsum= 198 n= 10 len= 43 cks= 198 chsum= 198 Temp is 23.2 and RH is 47.7 n= 10 len= 43 cks= 198 chsum= 198 n= 10 len= 43 cks= 198 chsum= 198 Temp is 23.2 and RH is 47.7 n= 10 len= 43 cks= 199 chsum= 199 n= 10 len= 43 cks= 199 chsum= 199 Temp is 23.2 and RH is 47.8 n= 10 len= 43 cks= 199 chsum= 199 n= 10 len= 43 cks= 199 chsum= 199 Temp is 23.2 and RH is 47.8 n= 10 len= 43 cks= 199 chsum= 199 n= 10 len= 43 cks= 199 chsum= 199 Temp is 23.2 and RH is 47.8
This gives correct temperature and humidity readings without all the retries in the module code. From a programming perspective it is troubling as Gordon outlined above.
Even with the setInterval =1000.And finally changing the example code one more time so that the one dht.read completes before the 2nd one starts.
//var dht = require("DHT22").connect(dpin); var dht=new DHT22(dpin); setInterval(function () { dht.read(function (a) {//}); dht.read(function (a) { F=a.temp; // F=(a.temp+40)*9/5-40; H=a.rh; console.log("Temp is "+F.toString()+" and RH is "+H.toString()); }); }); }, 2000);
This gives;
=undefined n= 10 len= 40 cks= 199 chsum= 49 n= 9 len= 42 cks= 197 chsum= 197 n= 10 len= 0 cks= 0 chsum= NaN n= 9 len= 41 cks= 198 chsum= 99 n= 8 len= 42 cks= 197 chsum= 197 Temp is 23.2 and RH is 47.6 n= 10 len= 0 cks= 0 chsum= NaN n= 9 len= 41 cks= 198 chsum= 99 n= 8 len= 41 cks= 198 chsum= 99 n= 7 len= 41 cks= 198 chsum= 99 n= 10 len= 0 cks= 0 chsum= NaN n= 6 len= 41 cks= 198 chsum= 99 n= 9 len= 0 cks= 0 chsum= NaN n= 5 len= 41 cks= 198 chsum= 99 n= 8 len= 0 cks= 0 chsum= NaN n= 4 len= 42 cks= 197 chsum= 197 n= 10 len= 0 cks= 0 chsum= NaN n= 7 len= 0 cks= 0 chsum= NaN n= 9 len= 42 cks= 197 chsum= 197 Temp is 23.2 and RH is 47.6 n= 10 len= 0 cks= 0 chsum= NaN n= 6 len= 0 cks= 0 chsum= NaN n= 9 len= 42 cks= 197 chsum= 197 n= 10 len= 0 cks= 0 chsum= NaN n= 5 len= 0 cks= 0 chsum= NaN n= 4 len= 1 cks= 0 chsum= NaN n= 9 len= 43 cks= 197 chsum= 197 Temp is 23.2 and RH is 47.6
Changing the set interval from 1000 to 2000 helps.
On a scope the entire message takes just under 6ms. -
The package claims it is pre-charged, but I had to charge it.
A Red LED lights when charging and a Blue LED lights when it is charged.
So it sounds like the internal circuit does discharge the battery on the shelf.
Will investigate further.
Nice to know it can be found at a lower price if one is willing to wait, but also nice to have a local fast source. -
Running a PICO V1.87
This code//DHT22.js //10Oct2016 var dpin=B3; var F; var H; var dht = require("DHT22").connect(dpin); setInterval(function () { // dht.read(function (a) {}); dht.read(function (a) { F=(a.temp+40)*9/5-40; H=a.rh; console.log("Temp is "+F.toString()+" and RH is "+H.toString()); }); }, 1000);
produces the following output
>echo(0); =undefined Temp is 30.2 and RH is -1 Temp is 30.2 and RH is -1 Temp is 30.2 and RH is -1 Temp is 30.2 and RH is -1 Temp is 71.6 and RH is 52 Temp is 30.2 and RH is -1 Temp is 30.2 and RH is -1 Temp is 30.2 and RH is -1 Temp is 71.6 and RH is 51.6 Temp is 30.2 and RH is -1 Temp is 71.78 and RH is 51.6 Temp is 30.2 and RH is -1 Temp is 71.78 and RH is 51.6 >clearInterval(); =undefined
But this code
//DHT22.js //10Oct2016 var dpin=B3; var F; var H; var dht = require("DHT22").connect(dpin); setInterval(function () { dht.read(function (a) {}); dht.read(function (a) { F=(a.temp+40)*9/5-40; H=a.rh; console.log("Temp is "+F.toString()+" and RH is "+H.toString()); }); }, 1000);
Produces this output
>echo(0); =undefined Temp is 71.78 and RH is 51.6 Temp is 71.96 and RH is 51.7 Temp is 71.78 and RH is 51.6 Temp is 71.78 and RH is 51.6 Temp is 71.78 and RH is 51.6 Temp is 71.78 and RH is 51.6 Temp is 71.78 and RH is 51.6 Temp is 71.6 and RH is 51.5 Temp is 71.78 and RH is 51.6 Temp is 71.78 and RH is 51.8 Temp is 71.78 and RH is 51.8 >clearInterval(); =undefined >
Is there something missing in the module code?
Pin initialization?
A bit? -
1800 mAH
Has two USB ports, the micro is for charging the regular powers my PICO.
Here's a link on Amazonhttps://www.amazon.com/Xtreme-Universal-1800mAh-Power-Keychain/dp/B00JJ9PE2C
-
-
If you are running Espruino on an ESP8266 the code is part of the binary flashed to the device and will require one of the ESP8266 GURUs to make the changes and recompile the code.
If you are using the ESP8266 from another Espruino device through a serial port the code is in the module on the website.
To make the changes copy the module from the website and paste it into a file to edit.
On WebIDE options page create a project directory (if you haven't already). Put your edited module in the project.modules directory. Suggest that you rename the module and change the name in your test code. When modules load WebIDE looks in several locations for the file, one being the project modules directory.
As a first edit insert a console.log("It's me"); into the function you are going to change and see if you are on the right track by running your test code.For ESP8266+Espruino, the ESP8266WiFi_0v25 module provides a function called createAP
-
Thanks Gordon for clarifying where the changes need to occur.
from the Esp8266_at_instrunction_set_env1.5.4_0.pdf
AT+ CWSAP – Configuration of softAP mode
[@deprecated]. Please use AT+CWSAP_CUR or AT+CWSAP_DEF instead.AT+CWSAP_CUR – Set configuration of softAP mode, won’t save to Flash
Example AT+CWSAP_CUR="ESP8266", "1234567890", 5, 3
Command AT+CWSAP_CUR?
Response +CWSAP_CUR:, , , , ,
Parameters
string, ESP8266 softAP’ SSID
string, range: 8 ~ 64 bytes ASCII
channel id
0 OPEN
2 WPA_PSK
3 WPA2_PSK
4 WPA_WPA2_PSK
maximum count of stations that allowed to connect to ESP8266 soft-AP
range: [1, 4]
Broadcast SSID by default
0 broadcast SSID of ESP8266 soft-AP
1 do not broadcast SSID of ESP8266 soft-AP
Command AT+CWSAP_CUR=, , , [, ][, ]ESP8266 softAP don’t support WEP.
AT+ CWSAP_DEF – Set configuration of softAP mode, save to Flash
Example AT+CWSAP_DEF="ESP8266", "1234567890", 5, 3
Command AT+CWSAP_DEF?
Response +CWSAP_DEF:, , , , ,
Parameters
string, ESP8266 softAP’ SSID
string, range: 8 ~ 64 bytes ASCII
channel ID
0 OPEN
2 WPA_PSK
3 WPA2_PSK
4 WPA_WPA2_PSK
maximum count of stations that allowed to connect to ESP8266 soft-AP
range: [1, 4]
Broadcast SSID by default
0 broadcast SSID of ESP8266 soft-AP
1 do not broadcast SSID of ESP8266 soft-AP
Command AT+CWSAP_DEF=, , , [, ][, ]
Response
OK
ERROR
Parameters The same as above.
Notes
This command is only available when softAP mode enable.
ESP8266 softAP don’t support WEP.
This configuration will store in Flash system parameter area. -
Looking at a different module
http://www.espruino.com/modules/EspruinoWiFi.js
This looks like the relevant place to make the modification./* Create a WiFi access point allowing stations to connect. ssid - the AP's SSID options.password - the password - must be at least 8 characters (or 10 if all numbers) options.authMode - "open", "wpa2", "wpa", "wpa_wpa2" options.channel - the channel of the AP */ exports.startAP = function(ssid, options, callback) { options = options||{}; if (!options.password || options.password.length<8) throw new Error("Password must be at least 8 characters"); var enc = options.password?"3":"0"; // wpa2 or open if (options.authMode) { enc={ "open":0, "wpa":2, "wpa2":3, "wpa_wpa2":4 }[options.authMode]; if (enc===undefined) throw new Error("Unknown authMode "+options.authMode); } if (options.channel===undefined) options.channel=5; turnOn(MODE.AP, function(err) { if (err) return callback(err); at.cmd("AT+CWSAP="+JSON.stringify(ssid)+","+JSON.stringify(options.password)+","+options.channel+","+enc+"\r\n", 5000, function(cwm) { if (cwm!="OK") callback("CWSAP failed: "+(cwm?cwm:"Timeout")); else callback(null); }); }); };
-
This link on the Espruino site talks about a StartAP function for ESP8266
http://www.espruino.com/ESP8266_WifiUsage
1-alt. Create an access pointUsing the ESP8266 is not recommended in general because its functionality is very limited and you'll have to reconnect to the AP whenever something bad happens, but it's a handy mode if you're out on the road and don't have an AP you can use to get internet access. To get that going use:
var wifi = require("Wifi");
wifi.disconnect()
wifi.startAP("my-ssid", {password:"my-password"});Searching the ESP8266WiFi_0v25.js module there is no current startAP function implemented.
One other issue is the Firmware and SDK version of the ESP8266 you are using. Older versions may not support some of the newest AT commands. This would involve flashing the chip to the newer version.
-
Perhaps if you post your code we can figure out how to implement the AT commands that you need to hide the SSID.
Attached code snippet shows how I've implemented additional AT commands for other purposes mDNS.var mDNS="AT+MDNS=1,\"bob\",\"http\",8080\r\n"; function mysend(a){ Wifi.at.cmd(a, 1000, function(d){console.log(d+"xxx");}); } //var ddata=""; function test(){ if(Hardware===1)Serial=Serial2; if(Hardware===0)Serial=Serial4; if(Hardware===1){ digitalWrite(B9,1); // enable on Pico Shim V2 Serial.setup(115200, { rx: A3, tx : A2 }); //Pico } if(Hardware===0)Serial.setup(115200, { rx: C11, tx : C10 }); //espruino board console.log("Start connection process"); var wifi = require("ESP8266WiFi_0v25").connect(Serial, function(err) { if (err)return 1;// throw err; Wifi=wifi; console.log("Reset the ESP8266"); wifi.reset(function(err) { if (err)return 1;// throw err; Wifi.at.cmd("AT+CWMODE_CUR=3\r\n", 1000, function(d){console.log(d+"xx1");}); Wifi.at.cmd("AT+CIPMUX=1\r\n", 1000, function(d){console.log(d+"xx2");}); console.log("Connecting to WiFi"); wifi.connect(SSID,key, function(err) { if (err)return 1;//throw err; wifi.getIP(function(l,ip){ console.log("IP= ",ip,"\n\r"); console.log("WiFi Connected "); mysend(mDNS); //HTTP or Network Server goes here serveHTML();
-
There is a flag (ssid hidden) for this listed in the AT commands for the ESP8266.
- AT+CWSAP_CUR – Current config of softAP mode
AT+CWSAP_CUR – Set configuration of softAP mode, won’t save to Flash
Example AT+CWSAP_CUR="ESP8266", "1234567890", 5, 3
Command AT+CWSAP_CUR?
Response +CWSAP_CUR:, , , , ,
Parameters
string, ESP8266 softAP’ SSID
string, range: 8 ~ 64 bytes ASCII
channel id
0 OPEN
2 WPA_PSK
3 WPA2_PSK
4 WPA_WPA2_PSK
maximum count of stations that allowed to connect to ESP8266 soft-AP
range: [1, 4]
Broadcast SSID by default
0 broadcast SSID of ESP8266 soft-AP
1 do not broadcast SSID of ESP8266 soft-AP
Command AT+CWSAP_CUR=, , , [, ][, ]
Response
OK
ERROR
Parameters The same as above.
Notes
This command is only available when softAP mode enable.
ESP8266 softAP don’t support WEP.
This configuration will NOT store in Flash.
Espressif
https://cdn.sparkfun.com/assets/learn_tutorials/4/0/3/4A-ESP8266AT_Instruction_SetEN_v0.30.pdf
- AT+CWSAP_CUR – Current config of softAP mode
-
Some ideas to try:
Scope the LED pin to see if the frequency is correct.
Use the Pico to receive the code and the EWiFi to send,
Use the EWiFI to receive the code and the PICO to send, see if the data is sent and is correct.
Try a visible LED and slow down the pulses to .5 Hz to see if it flashes analogWrite(pinOne,0.5,{freq:0.5}); Alternately use an IR sensor to look at the IR LED. (Some digital cameras can see IR, Iphone Android etc).
I'm fiddling with a Pico and a DHT22 to control a window AC based on the room humidity using the IR remote signals. -
I've had a similar issue using two Picos one Posting data and one acting as a server. Client posts data (80 characters), server receives and echos data over and over and finally it crashes with the CIPSERVER fail message. I think it has to do with the number (5) of sockets. I though it might be the capacitor on the shim but haven't had time to install them for a test. Wifi.debug() displays the socket information.
-
Suggest trying I2C.setup and require lines before the settimeout.
leave the lcd lines inside the settimeout