-
I've adjusted a promise module for Espruino a while ago, you can have look at it here:
https://github.com/ifavo/espruino-modules/blob/master/org.favo.promise.jsThis is how it works:
https://github.com/ifavo/espruino-modules/blob/master/org.favo.promise-Examples.jsIt's maybe not be perfectly optimized for Espruino for now, but I'm using it in different JS based projects for a while now and its doing what its meant to do :)
-
-
I've seen that in the code, Gordon, but I can not find a reference list of the codes ( looked at https://www.sparkfun.com/datasheets/RF/nRF2401rev1_1.pdf ).
But I also got it stable with a small trick last night.
I've put both sensors power inputs on an analog output which provides 3.3V and I turn them on just 500ms and initialize the connections again before I am going to read from them, then I turn the signal off, when I'm done.Suddenly I am still receiving data (with sometimes a little noise). yay!
Btw. they are currently 4 meters apart with one wall in between, this is the maximum I've managed. This is where I will want to use a pico in the future as a repeating node :-)Thanks a lot for your time and input!
I can't put my finger on it, but I think its a performance issue that comes up after a while which makes the sending part choke on its data. The issues must be within the TSL module or the I2C connection because just reading from it influences the NRF sending and also freezes the terminal eventually.
Thanks again and have a great weekend,
Mario -
Hi Charles,
The ESP8266 drivers are not available as javascript modules. They are meant to be available as internal modules. At the moment they are not compiled into the current firmware. You will need to compile it yourself.
To compile it yourself, there is a nice step by step tutorial for building it on github where you will also find the source code:
https://github.com/espruino/Espruino
To add the ESP8266 drivers you will need to edit the
Makefile
and change two lines:Change:
USE_CC3000=1
#USE_ESP8266=1to:
#USE_CC3000=1
USE_ESP8266=1To include the drivers and remove the drivers for CC3000 (another wifi module).
After that is done, you will need to flash your espruino from within the IDE with the advanced option and the new firmware.
I've done this just a few days ago to test a few things, you can use this link to get my binary:
http://sammelsurium.hpm12.de/espruino_1v72_espruino_1r3.bin for flashingI did not get them to work yet, but its also currently stated that development for the ESP is in progress and not yet fully working.
Cheers,
Mario -
I did some long running sending tests with different situations:
- Sending just from within the DHT callback > package loss wasn't too big and was still sending data after 12hrs
- Sending data just from within the TSL callbacks > package loss starts very fast and moved to sending nearly 100% junk after a few hours
- Sending data with an interval, separate from the callbacks > some package loss and was still sending after 12hrs
- Just sending "Hello World" without using doing any sensor readings in an interval > some package loss and still sending after while
- Sending in shorter/longer intervals (every 5seconds vs. every minute) > less package loss on smaller intervals and nearly no "noise" in the received data packages, over time the noise did not increase while using longer intervals resulted in an increased loss of data/more noise in the data packages over time
What I learned from these tests, is that I should send data not within callbacks but rather in an independent scope/interval outside of all the callbacks.
I tried to fine tune the sending process by:
- using different data rates, which didn't change a lot
- using
.setTXPower(3)
to maybe send a stronger signal, which didn't change anything as far as I can tell (while setting it to 0 resulted in no data sent anymore) - re-sending the data if
.sendString()
fails for some reason, which helps a lot but results in strange results. Failed sendings produce the error messageTX not received 30
but still send some part of the data.
What I've seen in the very beginning, became very strange and repeatable when I re-sent data that was not successfully sent. Data packages arrived combined at the target node.
For example:
Sending
Hello World
sometimes arrived asHelloSªorldHello World
orWorSªiQ¦llo World
orWorSªiQ¦llo WorldrS¶‘=Q¦llo World
.
Which looks like sent data is combined at the recipients end and the data packages are not correctly differentiated when received. It's maybe the NULL or EOT Byte thats not correctly received sometimes, leading to merged data packages.I am using a slightly modified version of the example code from the website at the recipients side which seems to be very stable:
var dataLine = ""; setInterval(function() { while (nrf.getDataPipe() !== undefined) { var data = nrf.getData(); for (var i in data) { var ch = data[i]; if ((ch===0 || ch===4) && dataLine!=="") { status.lastNrfLine = dataLine; // remove noise in the beginning of the line if ( dataLine.indexOf('{') > 0 ) { dataLine = dataLine.substr(dataLine.indexOf('{')); } // remove noise at the end of the line if ( (dataLine.lastIndexOf('}')+1) != dataLine.length ) { dataLine = dataLine.substr(0, dataLine.lastIndexOf('}') + 1); } if ( dataLine.substr(0,1) == "{" && dataLine.substr(-1) == "}" ) { status.lastNrfPacket = dataLine; try { // replace -1 values because JSON.parse fails on them // https://github.com/espruino/Espruino/issues/456 while ( dataLine.indexOf(":-1") >= 0 ) { dataLine = dataLine.replace(':-1', ':\"-1\"'); } handleNrfInput(JSON.parse(dataLine)); } catch (e) { // ignore failed packets... } } dataLine = ""; } else if (ch!==0 && ch!==4 && ch >= 32) { // 0 = NULL, 4 = EOT, <32 = all command codes dataLine += String.fromCharCode(ch); } } } }, 50);
So much from my NRF-adventures, I think, now I can get to a stable solution with an independent interval that sends the data in the global scope instead of sending data within the callback-scopes. I also think that I will find out more about the real problems with further testing and networking more nodes.
Is there anywhere I can lookup the error codes for the sending? What does
TX not received 30
mean?Cheers,
Mario - Sending just from within the DHT callback > package loss wasn't too big and was still sending data after 12hrs
-
Thank you, Gordon!
I already added a capacitor on both, that didn't change much.
I kept testing last night with the transmissions and I think the problem is maybe in combination with the TSL readings. By reducing the package size I got it to send good data every now and then but whenever a reading from the TSL2561 was scheduled, the data package gets still messed up.
Its like trying to send data within callbacks after reading from the TSL does mess it up. After 30 or so more seconds it works again.
I am 100% sure that I am sending strings and I also convert all readings with
Math.round()
to make it impossible to have junk in my values from using possibly faulty readouts.Tonight I will try to remove the TSL and maybe don't send data within the callbacks.
-
Thanks a lot, both of you, for taking time to give me some help! :)
This looks like the relay I am using:
http://i00.i.aliimg.com/wsphoto/v0/691867674/Best-price-10pcs-1-relay-module-5V-relay-drive-all-the-way-module.jpgBefore I left for work this morning, I quickly tested the register with 5v input and it shuts off the relay whenever I give a signal on it. I will try the other two options tonight.
I am not so experienced in the technical details, so excuse the following question:
When I control the relay directly via a pin on the board, the relay is turned off whenever I turn the signal off. Why is it the other way around on the register? Shouldn't it also turn off when the signal drops?
Thank you and have a great start into this week,
Mario -
-
Hi!
I'm testing communication between two espruinos with NRF24L01+, one should be a weather station on the outside and the other one the recipient on the inside.
They work fine if close to each other but the longer the first one is sending data, the more noise gets mixed into the datastream.
Also when I move them further apart, the noise starts right after the first data packe. Only the first package is sent correctly and all following packages get a lot of noise.
I am not sure whats happening here. Is it possible that using other stuff on the sender (a TSL2561 and a DHT22) could influence the data quality a lot? To me it looks like it does, because the first data package is sent perfectly before anything is read from both sensors but once I'm reading data from them, the data gets messed up.
Does anybody has any idea on whats happening?
Cheers,
Mario -
Hi everyone!
I want to control several 8-channel-relais from the espruino without using up all the pins on the board.
Thats why I connected a shift register (74HC595) where I can control each pin. I've successfully tested this with LEDs on all the outputs.
Now I have connected a single channel relais for testing on one of the shift registers output and it immediately turns on and won't turn off, no matter if there is a signal on the registers output.
The relais VCC is connected to the espruino 5V, the control PIN (IN) to the register and the GND to the espruinos GND. The register on the other hand gets its power from the 3.3V.
Is it possible that somebody points me into the right direction on how to figure this out?
Thank you,
Mario -
Thank you for the links @DrAzzy, they seem to shed some light on it. I'm going to read everything in there tomorrow :)
-
Hi!
I'm playing around with a pair of 433MHz receiver/transmitters and while everything works great on the transmitting part, I was trying to pair two espruinos (as test-replacement while waiting for my NRF24L01+).
The problem I ran into is that when I set watches for the receiver it seems to put too much load on the board, making it nearly impossible to run anything else.
Is there a trick to handle the receiving part with less processing power or is this a waste of time and I shouldn't even try?
As soon as I pull the plug from A0 (data line), the terminal becomes responsive again.I just used one of the example snippets:
var t,n; // When the signal rises, check if it was after ~5ms of delay - if so (and if we have a code) display it. function sigOn(e) { var d = e.time-t; if (d>0.005 && n>0) { console.log("0b"+n.toString(2)); n=0; } t = e.time; } // When the signal falls, measure the length of our pulse. // If it was within range, record a 1 or a 0 depending on the length. // If it wasn't in range, zero it function sigOff(e) { var d = e.time-t; t = e.time; if (d>0.0001 && d<0.001) n = (n<<1) | ((d>=0.0004)?1:0); else n=0; } setWatch(sigOn,A0,{repeat:true,edge:"rising"}); setWatch(sigOff,A0,{repeat:true,edge:"falling"});
Thanks for any advice!
Mario -
-
-
-
-
@allObjects its pretty easy, the documentation provided great examples, its just this:
var wlan = require("CC3000").connect(); if ( wlan ) { wlan.connect( "<network id>", "<network password>", function (s) { console.log("connect callback"); if ( s == "dhcp" ) { LED3.write(1); console.log(wlan.getIP()); } }); }
I've put a little longer test that also writes a logfile on a github gist: https://gist.github.com/ifavo/d3cc923dca4c94526f35
The
connect()
call on the required module takes a little while and freezes the the espurino for some seconds. It prints a timeout error if the wiring is wrong and returns a working wlan object only when everything is good.The
wlan.connect()
needs network id and password to identify on your wpa2 network. From the network code I understand that only WPA2 and unprotected (no password) networks are currently supported. If you are using WEP you may need to re-configure your router.And well, the callback is called multiple times (whenver the connection state changes) and only if its parameter is
String("dhcp")
, you'll have your connection. When it was working, I had multiple calls of it with no arguments provided, so you'll really want to check this.You can also use
wlan.setIP()
to set your static address like this:wlan.setIP({ ip: "192.168.176.63", subnet: "255.255.255.0", gateway: "192.168.178.1", dns: "192.168.178.1" });
-
Thank you, Gordon!
I already tried that to provoke an error by entering invalid credentials and to connect to a different network, but didn't do anything – same results. Also checked all pins several times and discovered that whenever one pin isn't correctly connected, loading the driver will already print an error – which is good to know for future debugging :)
I'm using one from Adafruit ordered at digitalmeans ( https://digitalmeans.co.uk/shop/adafruit_cc3000_wifi_breakout_with_onboard_ceramic_antenna_v1_1?search=cc3000 ). What puzzles me most is that it worked the day before, which means that the firmware can't be the reason (or it would not have worked before?), test code is also the same (copy & paste) and if I access the pins separately on the espruino (read/writes), everything works fine too :(
At the end of this week I will receive another CC3000 and two more espruino boards, trying another CC3000 should help shed some light on where the problem is.
-
Hi Gordon,
The espruino is still usable after the calling both
connect()
functions, I can enter new commands and do whatever I want with it – only when trying awlan.reconnect()
it will hang for a while.
.getIP()
only tells me that there is no internet connection, as does.setIP()
: My router logs all connection attempts and known devices and when they were last seen, thats why I think it's not even trying.VIN is connected to Bat, when putting it on the 3.3V the module-driver will just print a timeout when calling
require
on it. The CC3000 was the only thing connected to the espruino in my last tests.Since it was working one day and stopped working on the next, maybe there is something that can be reset on the CC3000? Is there anything it can remember? Otherwise its maybe just broken ;)
But basically if it does not work, there's no way to find out why it doesn't work?
Cheers,
Mario -
wow, thank you @allObjects ! I will try to read more about it, for now its little more confusing but I'm coming from pure software development and need to think a little differently about things like this, I'll try to get it all into my head ;-)
For now working with pulse & write/read got really easy, I especially love how easily you can queue several pulse calls and your hint to
getPinMode()
was an eye opener. -
hi there!
I've had a working WiFi connection with a CC3000 yesterday but suddenly today it is no longer connecting to my network.
There are no error messages,
wlan = require("CC3000").connect();
returns a valid wlan object andwlan.connect(…, …, …);
returns true but the callback is never called. My WiFi router also shows no connection attempt.How can I debug and find out what is happening?
Thank you,
Mario -
@DrAzzy, nope, it is in ms.
@allObjects, thanks, that explains a lot! -
Hi there!
I'm new to the whole topic and I've received my first espruino this week and wanted to play around with it on this weekend. Most things work great out of the box but I am struggling a little with understanding the read/write functions.
I'm trying to light an LED for only 100ms by entering
digitalPulse(C8,1,100);
, but .. the LED stays on indefinite. When reading the current status withdigitalRead(C8);
it turns off again. In additiondigitalRead
always returns 1.So I tried the same with the analog functions by entering
analogWrite(A0,1);
which turns it on and withanalogWrite(A0,0);
I can turn it off. But what puzzles me, is when I runanalogRead(A0);
it also turns it off.My question therefor is: Why do the reading functions turn it off? I was expecting to receive what I've written / the current status of the pin.
Thanks for taking time to read and answer! :)
Mario
@Gordon, you are welcome to use it.
It is based on https://github.com/iskugor/js-promise-simple/ and was not put under a specific license. There are a lot of adaptions of the simple promises out there.
I've put my modules in the default
modules
folder so it behaves like every other of your modules.