Hi - this looks really cool, I didn't realise that there were a bunch of cheapish devices out there that shared the same protocol. Have you seen http://www.espruino.com/Remote+Control+Sockets ? That's not lightwaveRF, but it does use 433Mhz.
One thing that might help is that digitalPulse tries to output an actual pulse, so digitalPulse(A0,1,2) raises A0 for 2ms and then lowers it as well. And the pulses will go on in the background, so just because you finished the last pulse doesn't mean that it won't still be doing things (so the delay on setInterval might end up being too small).
Looking at that page on the protocol it seems like it's easier to actually think of the 'payload' a bit differently... For instance they're saying you get 11110110 and output a 1250us pause when you get 10. It'd be much easier to treat that as 111010 and to then output a 1250us pause when you just get 0 instead.
Have you been able to look at the output on an oscilloscope? I guess with 250uS pulses you're going to have to make sure that the code executes quickly, as if it doesn't you could well end up with pauses that'll cause you problems... Sadly Espruino isn't super quick at the moment.
I haven't tested this, but what about:
// 1 added to front, and 10 converted to 0 already
var encode = [
"1111010",
"1110110",
"1110101",
"1110011",
"1101110",
"1101101",
"1101011",
"1011110",
"1011101",
"1011011",
"1010111",
"0111110",
"0111101",
"0111011",
"0110111",
"0101111"];
function sendNibbles(nibbles) {
var repeat = 12;
var cmdStream = "var p=digitalPulse;";
cmdStream+="p(TX,1,0.25);p(TX,0,0.25);"; //msg start bit
nibbles.forEach(function(nibble) {
encode[nibbble].split("").forEach(function(bit) {
cmdStream+="p(TX,1,0.25);p(TX,0,"+(bit?"0.25":"1.25")+");";
});
});
cmdStream+="p(TX,1,0.25);p(TX,0,0.25);"; //msg end bit
cmdStream+="p(TX,1,0);"; // wait for it to finish - hopefully set to 0 after as well
var interval = setInterval(function() {
eval(cmdStream);
if (repeat-- == 1) clearInterval(interval);
}, 10.25); // delay 10250us between repeats
}
The code above will create a string of JavaScript code that'll then be executed very quickly. It's probably overkill, but hopefully it'll mean that you don't have any speed problems when sending the pulses
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi - this looks really cool, I didn't realise that there were a bunch of cheapish devices out there that shared the same protocol. Have you seen http://www.espruino.com/Remote+Control+Sockets ? That's not lightwaveRF, but it does use 433Mhz.
One thing that might help is that
digitalPulse
tries to output an actual pulse, sodigitalPulse(A0,1,2)
raises A0 for 2ms and then lowers it as well. And the pulses will go on in the background, so just because you finished the last pulse doesn't mean that it won't still be doing things (so the delay on setInterval might end up being too small).Looking at that page on the protocol it seems like it's easier to actually think of the 'payload' a bit differently... For instance they're saying you get
11110110
and output a 1250us pause when you get10
. It'd be much easier to treat that as111010
and to then output a 1250us pause when you just get0
instead.Have you been able to look at the output on an oscilloscope? I guess with 250uS pulses you're going to have to make sure that the code executes quickly, as if it doesn't you could well end up with pauses that'll cause you problems... Sadly Espruino isn't super quick at the moment.
I haven't tested this, but what about:
The code above will create a string of JavaScript code that'll then be executed very quickly. It's probably overkill, but hopefully it'll mean that you don't have any speed problems when sending the pulses