LowPowerLab Forum

Hardware support => Moteino => Topic started by: kobuki on September 08, 2015, 06:21:44 PM

Title: New OOK library for Moteino
Post by: kobuki on September 08, 2015, 06:21:44 PM
Instead of the tl;dr below you can just go straight ahead to GitHub and grab the latest code (https://github.com/kobuki/RFM69OOK/). A lot of useful info has been gathered in this thread, if you have questions or suggestions, please post here.



First I thought I'll just continue an older thread of similar subject for this, but I think that if it gains any notable interest, it's better to have a separate one.

I continued with my OOK/RFM69 project and I can report success. I've succesfully created a working receiver and transmitter solution, and I'm including my current code for review and test for anyone interested. I'm trying to collect my notes in bullet points.

 • It's a work in progress, probably many optimisations, code refactorings could be done (some will be done), but it works. Pull requests will be very welcome after I'll have it uploaded to Github. I haven't decided yet if I'm creating a version that uses the original repo as base or I make it completely indepentent. It would be nice to be able to integrate it into the LPL codebase sometime. Maybe Felix is interested in it. I'm including this code here in an attempt to gauge interest.

 • I've taken an older version (from when I started coding on it) of Felix's RFM69 lib, gutted it and added the functions I deemed necessary. A note: many settings specified as defaults in the RFM69 DS aren't actually defaults. I had to set some of them explicitly. It is a separate class with a different name, so it can co-exist with the original lib. No inheritance (might be an option later).

 • There are 2 modes of operation for reception: polling and interrupt based. When polling, one can just call poll() to see if the OOK signal is currently active or not. Interrupt based means there is an interrupt attached to the pin change and pulse train decoding logic can be put into an ISR.

 • Transmission is very simple: after calling transmitBegin(), one can call send() to activate/deactivate the OOK signal. Simple timing loops can be used to modulate a proper pulse train, for instance. No provisions are made to support encoding modes of the RFM69, like Manchester encoding. Instead, I think the simplest and most efficient method for adding support for specific OOK hardware is grabbing and modifying existing freely available code for older transmitters like the RFM01 or RFM12b.

 • The minimum length of a pulse is tied to the reciprocal of the maximum bit rate of the OOK mode of the RFM69, which is 32768 Hz, resulting in a 30.52 us resolution. Since most OOK appliances use pulse lenghts close to 1 ms, it's more than adequate.

 • The first '1' pulse after a long silence or '0' is always perceived longer than the rest. It can probably be controlled a little better, needs some more experimenting. But see my previous point, it shouldn't pose a problem in practice. Other than this, accuracy is within 10% for short periods (below 500 us) and a lot better for longer ones, near 100%.

 • About the included zip: unzip it into a checked out copy of the LPL RFM69 library. It will not overwrite anything, just adds new files. The included test code is very primitive; it's just a playground. Feel free to modify it to fit your needs. I'm yet to test it with a real OOK transmitter. There is a separate receiver and a transmitter sketch.

 • About the hardware mod. First, please see the image in the first post of this thread (https://lowpowerlab.com/forum/index.php/topic,1271.msg8516.html#msg8516). The left-hand side modification needs to be done for both receivers and transmitters. More precisely: one needs to connect DIO2 of the RFM69 to Pin 3 of the Moteino. That's all. Obviously, a pair of Moteinos or a Moteino as receiver and some OOK hardware is needed for testing.

Any comments or suggestions are very welcome.
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 08, 2015, 07:14:31 PM
The Moteinos I have are the 915Mhz variety.  Would  they receive 433Mhz OOK, which is where the majority of OOK sensors broadcast (e.g. Oregon Scientific, Davis Instruments, etc.), just as  as well as a Moteino that's officially 433Mhz?  I'm thinking there might be a difference, given that they are different SKU's.

To me the potential appeal of using the RFM69 for receiving 433Mhz OOK is that hopefully the receiving range will be much greater  than what's otherwise possible with the usual $1 cheap  433Mhz receiver hardware that's commonly available from China on Ebay or AliExpress.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 08, 2015, 07:27:31 PM
It will work, with lowered sensitivity, naturally. I've once accidentally left 433 MHz settings on my 868 MHz module in one of the original LPL code examples and only after about an hour of experimentation I realised that. The motes were about 5m apart with only a door between them, yet RSSI was quite high, around 40..50 dBm. However if you use a dedicated mote for receiving your stations, having the proper radio surely helps. You can even swap the onboard module easily. For testing I'd suggest reducing the distance, though (if the transmitter is somewhere in your backyard or something).

BTW, Davis uses 915 MHz in the US/AU and 868 MHz in EU/UK, and FSK. I have a quite close friendship with its protocol ;)
Title: Re: New OOK library for Moteino
Post by: markbee on September 09, 2015, 08:00:11 AM
Awesome work! I'm also currently working on implementing OOK with the RFM69.
I tested the receiver and transmit code and got at least data (with a 433MHz switch device) when I tested the receiver code.
But I always get a lot of random data between the "real" data - looks like the threshold has to be adjusted?
I had no luck with the transmit code - there weas neither data received with the receiver code nor could I see any transmission with a RF Spectrum Analyzer.
Cheers
markbee
Title: Re: New OOK library for Moteino
Post by: kobuki on September 09, 2015, 08:10:09 AM
Thanks!

Yes, the sensitivity could be tuned. The normal RSSI threshold doesn't seem to play a role. I'll need to look into this. However random noise is being picked up by all receivers all the time, it's not abnormal. The important bit is that a well-defined pulse train can be caught and decoded. Most noise will fail at a very early stage of an attempted decoding process.

Transmitter: are you using the same moteino, with DIO2 connected to Pin3? It should work, my wonky test receiver code was happily and identifyably capturing the pattern the test transmitter generated, for 1-2 hours until I turned the motes off.
Title: Re: New OOK library for Moteino
Post by: markbee on September 09, 2015, 10:44:28 AM
I changed from my R5-USB 434MHz (DIO2 connected to Moteino Pin3) to the same modules with 868MHz and can read the transmitted bits (at least the 950*1000L delay is easy to identify). The bits preceding the long pause seem to be the bits I send, but are inverted? The timing is also a bit out of the programmed delay.
For example if I program the following 6 bits:
Code: [Select]
//snip
radio.send(1);
  delayMicros(100L);

  radio.send(0);
  delayMicros(500L);
 
  radio.send(1);
  delayMicros(100L);
 
  radio.send(0);
  delayMicros(500L);

  radio.send(1);
  delayMicros(100L);
 
  radio.send(0);
  delayMicros(950 * 1000L);

//snap

I get values like:

19 0 68
0 1 392
1 0 184
2 1 476
3 0 168
4 1 944972

19 0 384
0 1 384
1 0 228
2 1 476
3 0 132
4 1 945460

19 0 116
0 1 400
1 0 184
2 1 476
3 0 160
4 1 944868

19 0 52
0 1 420
1 0 184
2 1 472
3 0 156
4 1 944948
5 0 412
6 1 156
7 0 484
8 1 144
9 0 945524

and so on.

I'm not sure if I the bits are one after another but I would absolutely call this a succes for your code.

One of my first wishes would be to fine tune the threshold like having a "squelch" at least for debugging to see how good the timings are. I didn't test the interrupt sending/ receiving - do you have any code for that?

Cheers
markbee
Title: Re: New OOK library for Moteino
Post by: kobuki on September 09, 2015, 11:23:39 AM
The bits getting inverted must be some coding mistake on my part, TBH I only really cared cared about the lenght of the 0/1 pulses. Feel free to correct it if you'd like. I suggest lowering the output power for the transmitter. In close distances it seems to overshoot a lot. Additionally, I will probably need to set the fixed threshold per specs to make things more robust. Unfortunately there is only code for this module for OOK on the net, not much explaining for settings of the various parameters. I will give a shot at optimising the reception stability tonight and try with 433 MHz too.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 09, 2015, 01:13:17 PM
I tuned RSSI parameters, namely REG_OOKFIX and REG_RSSITHRESH. This made reception a lot more robust and eliminated most of the noise. Modified the receiver sample a bit to allow easier eyeballing the results. In 433 MHz mode the receiver is more precise at capturing the timings of the transmitter. In 868 MHz mode the received first burst is longer than it should be, but again, I'm intentionally testing the lower end of the timing limits. Timing resolution is about 30 us. In practice, OOK devices use very long pulses, closer to 1 ms. I'm using the same 868 MHz module for both frequency bands.

I uploaded the code to Github for easier management, see: https://github.com/kobuki/RFM69OOK (https://github.com/kobuki/RFM69OOK). I haven't bothered with copyrights, etc. yet, but it's an obvious derivative of Felix's library so I left his original copyright stuff there for now. Pull requests are welcome for notable improvements :)
Title: Re: New OOK library for Moteino
Post by: kobuki on September 09, 2015, 09:09:01 PM
Updated the Github repo:

More testing code
 - simple pulse width dumper (OOKReceiveTest2)
 - a working implementation of a Lidl L08037B outdoors temperature sensor OOK decoder (OOKReceiveTest3) -- what I had around...

So far, everything's working as expected. Especially when considering that I'm using a 868 MHz radio for this 433 MHz device with an antenna tuned for the former ;) I'm planning to introduce simple funcions for fine-tuning the radio for various OOK devices and test IRQ-based code. Currently I'm having problems with the IRQ code when using the HW serial routines.

I also can't seem to read out a sensible RSSI value when I receive a '1'. Anyone has an idea what could be happening with it?
Title: Re: New OOK library for Moteino
Post by: markbee on September 10, 2015, 10:03:34 AM
I tested your code and had problems with the noise (as I had before). I received a lot of data (noise) when testing the receive code with either the transmit code on a R5-USB nearby or a 433.9MHz remote switch nearby.
So I checked my test setting with an oscilloscope and found a very interesting effect. If the transmitter is very near, the RFM69 seems to overdrive and keep this status even if you cut it from the power supply for a short time.

See attached pictures with clear signal and overdrive situation.

Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 10:16:01 AM
I tested your code and had problems with the noise (as I had before). I received a lot of data (noise) when testing the receive code with either the transmit code on a R5-USB nearby or a 433.9MHz remote switch nearby.

I suggest lowering the output power for the transmitter. In close distances it seems to overshoot a lot. Additionally, I will probably need to set the fixed threshold per specs to make things more robust.

Yeah, I know. Thanks for the shots btw, they are the missing presentation of scientific evidence :) The interesting thing is the other thing you mentioned after power cutoff. I sometimes experience other weird behaviour, like interrupts triggering continuously for no reason until I reset the mote by unplugging and replugging it into the USB socket.

I'm currently testing the interrupt-based decoder, it's working so far, soon to be pushed to GitHub.

EDIT: Suggestion: try lowering REG_RSSITHRESH while raising REG_OOKFIX. One at a time. I think lowering RSSI sensitivity should help. The RFM69 module is indeed a very sensitive one, so probably some tuning might be needed for each installation.
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 10:52:43 AM
It doesn't look like a proper manchester encoding either.  The lows are all lasting about the same amount of time, and some of the highs look like much more than 2x the duration of the low.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 10:57:14 AM
Yeah. Basically all codes I've looked at use some unique timing scheme. Common in most ones though is that they use simple pulse lenght coding to represent 0 and 1 binary digits.

Just uploaded some code to GitHub, including a working IRQ-based decoder.
Title: Re: New OOK library for Moteino
Post by: markbee on September 10, 2015, 11:10:07 AM
Ok was thinking about REG_OOKFIX at the same time  ;) and upped REG_OOKFIX which is the way it definitely works now.
This is how it looks like with your transmit code:

1 0 324
2 1 308
3 0 212
4 1 216
5 0 104
6 1 332
7 0 308
8 1 220
9 0 216
10 1 112
11 0 348
12 1 300
13 0 212
14 1 204
15 0 124

and so on.

So if you have the transmitter nearby (e.g. to eliminate noise) this might be the way to go.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 11:17:58 AM
Cool. Until I set the OOK fixed threshold value, I also received a lot more noise.

What I can't seem to achieve is getting RSSI values out of the chip. It always reads -128 when calling readRSSI(), whether I use the force parameter or not. I called it in a loop every 100 us, and nothing. The same transmitter was operating and I could receive it just fine, so obviously some RSSI change must have occurred. No dice.
Title: Re: New OOK library for Moteino
Post by: markbee on September 10, 2015, 11:28:45 AM
Just a very impulse idea about RSSI - the bits are inverted and according to the data sheet "The RSSI sampling must occur during the reception of preamble in FSK, and
constant “1” reception in OOK." (datasheet page 27).
I still though had no time to look why the bits are inverted.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 11:52:20 AM
Yes, I've tried when I verifiably had a '1' signal, it didn't work either. I'm using the readRSSI() function from the orginal lib and it has always worked reliably in FSK mode, so I'm somewhat surprised.
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 12:04:41 PM
Is the idea to use knowledge of the preamble to time the taking of the RSSI measurement during a "HIGH" reception, and then use that RSSI to adjust the gain control?  This sounds far more involved than those $1 receivers, which, while inflexible, handled that aspect of it automatically.

Of course, they pretty much assumed machester encoding to continually set the AGC, so they wouldn't be as useful for these other types.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 12:11:11 PM
I don't think I completely understand the question, but I merely wanted to see what RSSI values I'm getting as a simple measure of the strengtht of the signal. The module handles everything automatically, using user-settable parameters. It even has multiple modes for OOK reception, and a lot of knobs and buttons for tuning most aspects of the reception process. But it's a $5 module ;) Not all modes are generally useful, though.
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 12:18:18 PM
Just a very impulse idea about RSSI - the bits are inverted and according to the data sheet "The RSSI sampling must occur during the reception of preamble in FSK, and
constant “1” reception in OOK." (datasheet page 27).
I still though had no time to look why the bits are inverted.

As an aside, Felix's library for the RFM69 seems to have a parameter for "forcing" the RSSI sampling to happen on demand rather than only during the preamble.  Also, the datasheet says it takes a duration of two bits to do the sample for the RSSI, so I presume increasing the datarate must increase the sample rate also (?).
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 12:19:46 PM
Been there too. (https://lowpowerlab.com/forum/index.php/topic,1286.msg8661.html#msg8661)
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 12:42:54 PM
Can you read the RSSI pin directly (mode 0 of the 4 pin modes), and it fluctuates in real-time, or do you actually have to explicitly command the chip to do a sample every time before it will update that pin?  Sorry for the bonehead question, but I found the datasheet a bit terse.

If it helps at all by way of contrast, the cheap OOK receivers give you an analog voltage in real-time to represent the signal strength.  In fact, that's the only output they typically give at all.  Then you can either read it using an ADC, or connect it to a digital input pin on the arduino and read it that way (which obviously assumes the AGC is working correctly).
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 12:50:17 PM
The RSSI output is on a digital pin -- and yes, the DS is very coarse about it. My guess is that it's just a simple threshold indicator. But I'd rather not hook another pin to the moteino from the module just for that...
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 01:31:43 PM
I'm assuming you've seen sevenwatt's blog regarding RFM69 OOK, but if not, it may be worth a look:  http://www.sevenwatt.com/main/category/ook/
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 01:42:25 PM
Yeah, read his great site about his projects. He's purely using the RSSI value in FSK mode to capture OOK signals - he's obviously successful at it, but I'm positive that a correctly set up RFM69 module in OOK mode is much more capable for that purpose.
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 03:23:57 PM
He's purely using the RSSI value in FSK mode to capture OOK signals....

I'm surprised to hear that, as one of his posts begins with "RFM69 OOK RSSI and optimal bitrate settings are key for proper reception and decoding of “foreign” OOK signals..." [bold emphasis added by me]  Well, he does seem to agree with you.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 03:26:31 PM
I've looked into his decoding soure code and he only used the RSSI values, to my surprise. He's experimenting with a lot of OOK stuff, so it's not surprising he digged deep into this as well.
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 10, 2015, 04:11:08 PM
It does look as though you are both connecting to DIO2: "When the RFM69 is used in continuous OOK mode, the signal can be read from the RFM69 DATA (DIO2) pin."

What I'm still not clear on is: is DIO2 presenting you with an analog value, or purely a binary value HIGH-LOW based on a threshhold that you set?  I do realize it says DIO2, not AIO2, but what really happens isn't constrained by silkscreen alone.  In looking at his plot of the the Oregon Scientific V1, it does seem as though he's reading an analog strength value (what he calls "raw RSSI"):  "...it is easy to record the raw RSSI and OOK data from a RFM69..."

Maybe it's just me, but I find it a lot easier and faster to read code when there's a high level description as to what's going on, and then try match that against the code, than it is to read code purely bottoms-up.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 10, 2015, 04:16:31 PM
I'd suggest some RTFM is due ;)

DIOx are all programmable digital IO pins. Their name also suggests that: Digital I/O. So they're purely digital, 1 or 0. He's using the RSSI register (see the DS!) in FSK mode to create those o'scope-like graphs, and to decode the signal.
Title: Re: New OOK library for Moteino
Post by: joelucid on September 11, 2015, 02:44:44 AM
Hey guys, this is very cool! I also use Moteinos to control RF power sockets. I've used OOK in packet mode which allows for the radio to create the timings. Just switch off the preamble, select OOK, fixed packet length and select the baud rate to get the right timings. Works like a charm without HW mods. Only receive though.

https://lowpowerlab.com/forum/index.php/topic,1115.msg7221.html#msg7221
Title: Re: New OOK library for Moteino
Post by: markbee on September 11, 2015, 02:46:50 AM
Nice!

Do you have any example code/ libs?
Title: Re: New OOK library for Moteino
Post by: kobuki on September 11, 2015, 03:20:50 AM
Hey guys, this is very cool! I also use Moteinos to control RF power sockets. I've used OOK in packet mode which allows for the radio to create the timings. Just switch off the preamble, select OOK, fixed packet length and select the baud rate to get the right timings. Works like a charm without HW mods. Only receive though.

https://lowpowerlab.com/forum/index.php/topic,1115.msg7221.html#msg7221

Thanks for the heads-up. Yeah, I am aware packet mode is possible in OOK mode as well, but I wanted complete control over the timing via software, have per-pulse interrupts (they're sufficiently long in most OOK protocols for that) and create a library that is simple and makes it easy to port other solutions to the RFM69. I might still implement packet mode, my only problem is that most coding schemes aren't based on any standard, so to create the correct timings, a peculiar bit layot must be created to be able to feed into the FIFO of the chip, and decoding, too, can only be done by manual programming. It's not impossible, but I find direct control better suited for now.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 11, 2015, 03:21:34 AM
Do you have any example code/ libs?

See on GitHub (https://github.com/kobuki/RFM69OOK/).
Title: Re: New OOK library for Moteino
Post by: markbee on September 14, 2015, 08:16:48 AM
Today I tested your library with a 434MHz remote switch but ran into timing problems. As you can see from the attached logic analyzer chart the timing with the dump-sketch doesn't correspondend with measured values.
The begin of the bit burst ist clearly identified by the 10.6ms pause. But afterwards the edges aren't recognized only the full pulse and there are a lot of very short false signals.
Maybe polling is to slow and it would be better to decode with the interrupt based routine.
I adjusted the REG_OOKFIX to 30 - maybe this comes into play for the wrong readings.

Cheers
markbee

EDIT: Just recognized in the library that the signal is polled with interrupt. I somehow thought the polling is done software-wise. So the next step may be to write an ISR to get the correct timings.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 14, 2015, 08:33:44 AM
A quick suggestion: move the receiver/transmitter further apart; raise rssi and fixed threshold; if you use a moteino for tx, lower the output power. This has always helped for me. The module is very sensitive and easily overshot and that results in many false readings, mostly short '1' signals. Someone else in this thread even posted nice scope screenshots about it.

Polling mode is fine, down to probably about 50 us. Interrupt mode is not going to help, but it's good for other applications.
Title: Re: New OOK library for Moteino
Post by: markbee on September 14, 2015, 08:52:18 AM
yeah the scope pictures that was me ;)

I already played a lot with REG_OOKFIX and REG_RSSITHRESH but to no avail. It does not get the edges but that ist very constant - so it looks more like it is counting the whole pulse, but does that quite precise.

Title: Re: New OOK library for Moteino
Post by: kobuki on September 14, 2015, 09:08:56 AM
EDIT: Just recognized in the library that the signal is polled with interrupt. I somehow thought the polling is done software-wise. So the next step may be to write an ISR to get the correct timings.

Nope, it's not. It's polled directly in loop(). Feel free to rewrite/fix the dumper code to fit your needs - it's nothing more than some playground, however I did use it to decode that cheap 433.9 MHz thermometer. So it can have a few use cases.

BTW, are you hooking up the DIO2 of the mote you do the polling on? Or is it the transmitter side on your image? I'm confident the mote is able to capture your signal properly. Your case might be an outlier that needs more tuning, but I'm sure it's possible. It must have something to do with too strong/distorted rf signal.
Title: Re: New OOK library for Moteino
Post by: markbee on September 14, 2015, 09:42:25 AM
In the previous logic analyzer picture the switch remote was hooked to the logic analyzer. I now hooked the logic analyzer to DIO2/ Pin3 (_interruptPin) and hmmm... the timing printed out by the code seems to be bang on (logic analyzer timing is identical with the timing spit out by the code). So there is something running afoul in the RFM69 as it seems and it's not the code which is the problem. I'm afraid I have to dig deeper into the datasheet ;)
Title: Re: New OOK library for Moteino
Post by: kobuki on September 14, 2015, 09:50:58 AM
One more hint: try lowering/increasing the bandwidth. I've added simple functions for that on the library class; see related defines at the end of RFM69OOKregisters.h. I'm curious about what you'll find.

EDIT: one more thing. It's important to use the proper frequency for reception. I first thought that the weather transmitter is transmitting on 433.92, but in fact it's on 433.90. My garage opener transmitter keyfob is exactly at 433.92 -- basically any skew made reception impossible or produced similar results to the ones you showed.
Title: Re: New OOK library for Moteino
Post by: markbee on September 14, 2015, 11:21:36 AM
Ok it's working now ;) I fine tuned some registers (BW registers e.g.) and now have a clear signal and timing from sender (remote switch) and receiver (Moteino R5USB) is almost identical (see chart and measurements).
The logic analyzer printout shows on top (CH0) the receiver and on CH1 the transmitter. You can also see the delay of the two signals.

Cheers
markbee

BTW the actual github files produce some compiler errors. I implemented the register settings as methods in a fork/ my own library. But I think you will put up the working files soon, so I don't do any pull requests ;)
Title: Re: New OOK library for Moteino
Post by: kobuki on September 14, 2015, 11:28:52 AM
Cool! Can you tell me what the actual delay is in microsecs? It's hard to see on the image. So the only thing was the BW? What values made it at the end?

My IDE compiles my GitHub code without a single warning. Can you copypaste the errors you see? I'm using the newest IDE (v1.6.5), this might be the problem, but I want to fix it ASAP if it causes compilation problems for others. Any significant change you think is worth integrating into the base?
Title: Re: New OOK library for Moteino
Post by: markbee on September 15, 2015, 04:48:57 AM
The signal length for the short pulse is about 340µs, the long pulse is about 1ms (measurement directly from the remote switch encoder IC). The deviation from the 434MHz remote switch to the actual signal received on the RFM69 is about 10%.
I adjusted the register  RF_RXBW_MANT and RF_RXBW_EXP to 125 kHz and if you have a look at the attached spectrum analyzer screenshots from two different remote switches (same manufacturer) you can see why  ;D
I also adjusted REG_OOKFIX, the frequency and did some changes to the code.
It's interesting to see how the frequency of both of the remote switches differ, so it's obvious you have to set the proper frequency in the code/ for the RFM 69.

I will test your actual github files later asap and post the compiler errors.

Cheers
Markus
Title: Re: New OOK library for Moteino
Post by: kobuki on September 15, 2015, 06:12:44 AM
Thanks. What did you have to change in the code? I think finding a middle value for frequency and somewhat larger BW will make all your transmitters work.

You have all sorts of good equipment at your disposal :)
Title: Re: New OOK library for Moteino
Post by: WhiteHare on September 15, 2015, 08:56:30 AM
@Markus What type of TI spectrum analyzer is it that you're using?  Judging from the output, it looks like it might be "affordable," yet a nice upgrade from using a cheapo RTL-SDR with SDR#.
Title: Re: New OOK library for Moteino
Post by: markbee on September 15, 2015, 09:06:34 AM
It's this one:

http://www.ti.com/tool/MSP-SA430-SUB1GHZ (http://www.ti.com/tool/MSP-SA430-SUB1GHZ)

It's only sub GHz and only three but important frequency ranges. Bought it cheap some time ago...

BTW I compared the sender (434MHz remote switch) and receiver Moteino R5USB pulses in a table if anyone is interested:

TX   RX   Diff. %
338   348   2,96%
1002   980   -2,20%
339   356   5,01%
1003   980   -2,29%
339   356   5,01%
1002   980   -2,20%
1020   996   -2,35%
336   348   3,57%
340   328   -3,53%
1005   1008   0,30%
1022   1028   0,59%
336   324   -3,57%
340   336   -1,18%
1006   992   -1,39%
1022   1000   -2,15%
336   348   3,57%
340   324   -4,71%
1006   996   -0,99%
1023   1012   -1,08%
336   340   1,19%
340   332   -2,35%
1007   996   -1,09%
1023   1004   -1,86%
336   340   1,19%
341   344   0,88%
1007   992   -1,49%
1023   1000   -2,25%
336   348   3,57%
341   340   -0,29%
1007   1008   0,10%
1023   1000   -2,25%
336   332   -1,19%
341   320   -6,16%
1007   1016   0,89%
1023   996   -2,64%
336   356   5,95%
341   328   -3,81%
1007   996   -1,09%
1024   1024   0,00%
336   320   -4,76%
1025   996   -2,83%
337   356   5,64%
1026   1012   -1,36%
337   308   -8,61%
1026   1012   -1,36%
337   348   3,26%
1027   1008   -1,85%
337   344   2,08%
341   328   -3,81%

Cheers
markbee
Title: Re: New OOK library for Moteino
Post by: kobuki on September 15, 2015, 09:11:15 AM
Average is -0,67%. Pretty good.

Could you find the compile error?

@WhiteHare: an SDR stick is not at all bad for this with proper settings for the band. In fact, you have a lot more detailed image. And the better ones can even see Wi-Fi signals.
Title: Re: New OOK library for Moteino
Post by: markbee on September 16, 2015, 03:51:12 AM
I downloaded the github files again, cleaned some stuff in my libraries ;) and now everything compiles fine. Did you get any further with the RSSI values?
Title: Re: New OOK library for Moteino
Post by: kobuki on September 16, 2015, 05:37:27 AM
No. From what I was able to gather, it's not possible to query RSSI values in OOK mode, sadly.
Title: Re: New OOK library for Moteino
Post by: markbee on September 16, 2015, 08:05:14 AM
Regarding the small changes I made in your code (e.g. OOKdumper) check for the datatypes to be correct. E.g. if you set TSIZE to 400 you need an integer for the variable pos & i in the for next loop and so on...
Title: Re: New OOK library for Moteino
Post by: kobuki on September 16, 2015, 08:21:27 AM
Loop variable i: thanks, fixed. Originally tt was shorter so byte was fine. Honestly, I didn't pay much attention to the dumper code. I'd expect anyone trying to use it tailor it to their specific needs.

EDIT: removed first paragraph; it was a product of misreading a part of your post.
Title: Re: New OOK library for Moteino
Post by: markbee on September 25, 2015, 04:20:34 AM
Did you ever succeed controlling a power socket with the transmitted code?
Title: Re: New OOK library for Moteino
Post by: kobuki on September 25, 2015, 07:26:11 AM
No, sorry, I don't have such a thing at the moment. Did you not succeed with it? I'm willing to help if I can, it would be great if I could include a working transmitter of any kind in the sources as an example.
Title: Re: New OOK library for Moteino
Post by: markbee on September 25, 2015, 10:11:07 AM
No I'm working at it at the moment. I thought it would be as easy as setting the RFM69 into TX mode with the appropiate register settings and then send the recorded bitbursts back. But that apparently doesn't work. I will have a more detailed look into it.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 25, 2015, 10:16:57 AM
It should be as simple as calling transmitBegin(), do your send() series and then transmitEnd(). With dummy data, I've been successful with it (see the OOKTransmitTest example). You might need to use setPowerLevel() to lower the RF output power if your receiver is very close (during testing). You posted nice scope shots about the process, it should work with the original receiver, too. However the receiver might use rolling code, some changing bits as flags you need to mimic in your transmitter, etc. What kind of receiver do you have?
Title: Re: New OOK library for Moteino
Post by: markbee on September 25, 2015, 10:40:06 AM
The funny thing is, I tested transmitting with your code but only had a logic analyzer attached and never checked if it was really transmitting. I now looked at the spectrum analyzer and can't see any transmission on 433.9 MHz when I run the code...

EDIT: Which type of RFM69 do you use? H, HW, CW or HCW? I currently use a RFM69HCW for the tests.
EDIT: Remote device is a simple power socket that should work receiving a simple bit burst.
Title: Re: New OOK library for Moteino
Post by: kobuki on September 25, 2015, 11:05:50 AM
I'm using RFM69W-433-S2 for 433 HMz stuff (tested with 868 MHz versions earlier, but they are not a good fit, obviously). Post your code so we can check it out.

EDIT: Remote device is a simple power socket that should work receiving a simple bit burst.

Brand, model...?
Title: Re: New OOK library for Moteino
Post by: markbee on September 28, 2015, 05:33:43 AM
Works now with a lot of devices (receiving & sending), but had to change and adjust some (a lot) settings, library & code. I will go into detail later, maybe with a detailed blog entry.

Cheers
narkbee
Title: Re: New OOK library for Moteino
Post by: kobuki on September 28, 2015, 07:35:49 AM
Thanks for the report. It would greatly help if you showed us the changed settings. I didn't need to change a lot of them besides the most important 3-4 ones to receive a sensible pulse train of any device I could find. So I'm wondering what needed to be changed so much on your side. Is it possible you upload/send your code? BTW, did you interpret all your devices for yourself or you were able to use a 3rd party lib to decode the lot of devices you have? I don't need a lenghty blog entry, just the basics so I can refine the public repo for others to gain from it (well, of course, if you'd allow that, too).
Title: Re: New OOK library for Moteino
Post by: pzingg on September 28, 2015, 07:39:12 PM
Newbie (to electronics as well as Arduino, not to mention 433 Mhz radios and OOK), so probably doing something drastically wrong. I'm using a MoteinoMEGA and the project is to receive and decode data a rain gauge that I am told uses OOK. (Basing things on this post: http://rayshobby.net/reverse-engineer-wireless-temperature-humidity-rain-sensors-part-3/ )

First hurdle (after soldering all the headers on my Moteino) is that when I use this sample code in setup:

Code: [Select]
  radio.initialize();
  radio.setFixedThreshold(30);
  radio.setFrequencyMHz(433.9);
  radio.receiveBegin();

and then poll radio.readAllRegs() in my loop, the only register that has any non-zero values in it is the first one (REG_OPMODE). So I'm thinking that the SPI/register stuff is not really working right.  Shouldn't the radio.initialize() call set up a lot of other values, and I should get them back if I call readAllRegs()?

The SS pin is 4 on the MEGA. Does it need a pulldown to keep it low?  Any other suggestions?
Title: Re: New OOK library for Moteino
Post by: kobuki on September 28, 2015, 07:46:12 PM
Sorry, I don't have a Mega, but I'll try to help. Did you hook the DIO2 pin to an interrupt pin on the mote? It's needed for RX and TX, whether using interrupts or not. It should be connected to PIN10. The register dump had an error, as it was from an old version of the original LPL code. It should be fixed in at least the latest GitHub revision of the OOK lib. What revision do you use?
Title: Re: New OOK library for Moteino
Post by: pzingg on September 28, 2015, 08:36:19 PM
Thanks for the tips (should have RTFM about the DIO2 pin). Cloned your latest RFM69OOK repo and installed it.  Semi-soldered into DIO2 which is not wired on the MoteinoMEGA, and patched it to the MEGA pin 10 (i0).  So I didn't see much in OOKDumper until (duh) I plugged in the antenna wire.

dumpAllRegs() is working, and I'm getting signals.  Now to debug my code.  Not sure that the interrupt handler I'm using works. Perhaps I should start out by trying to handle all the state changes in loop() with radio.poll() calls?
Title: Re: New OOK library for Moteino
Post by: kobuki on September 28, 2015, 08:42:37 PM
Yeah, the polling logic is definitely simpler. I'd started with that too, and then implemented the basic thermometer receiver based on that code. Anyway, it's good to see it works on the Mega too  8)
Title: Re: New OOK library for Moteino
Post by: kobuki on October 27, 2015, 06:07:43 PM
A little update. It seems that reading out RSSI values is possible after all in OOK continuous mode. I haven't conducted thorough tests yet, but it seems that until the RSSI threshold is reached by an incoming signal, the RSSI reg. just returns some arbitrary constant. Then it starts changing according to the RSSI it currently senses and stays that way. If I set the threshold to the highest sensitivity value then values start changing right away. I've written a few lines of code that spouts RSSI values in continuous OOK mode and logged a session into a file with RealTerm, and loaded the file in GoldWawe (not the best app to look at waveforms of this kind, but it's OK). Attached image is a screenshot showing a capture of the old, cheap 433.92 MHz I use for testing sometimes. It's actually a floor higher, and several thick walls away.

This of course opens up new possibilities for the OOK receiver. It becomes possible to receive and decode OOK signals without HW modifications to the Moteino, or in general, less pins need to be connected and free to use on an ATMega. Natural consequence of the ability to measure RSSI is the possibility to adapt the receiver to the signal strenght to achieve more accurate pulse length detection, and so on. Of course, someone else (http://www.sevenwatt.com/main/rfm69-ook-signals-sampled-with-rssi/) has already done something similar, and actually his work gave me the inspiration to dig into this more. I however want a more generally applicable simple lib for basic OOK reception for custom codes and experimentation, and not another variation of a multi-device all-inclusive receiver solution.
Title: Re: New OOK library for Moteino
Post by: janwolf on January 24, 2016, 03:48:53 PM
Hi

I'm very new to Aduino and RFM69. I'm starting a project to decode Visonic protocol with this RFM69 and Arduino. I've read your work. Very impressive. Now I have to choose the right library between RSSI approach and Intern OOK ! So have you made more test with RSSI approach. Which one will you choose ?

Many thanks
Jan
Title: Re: New OOK library for Moteino
Post by: kobuki on January 24, 2016, 03:55:39 PM
If you're new to Arduino then I recommend the original way that involves a small modification to the Moteino. It's a much simpler and more robust approach. BTW, are you sure that the Visonic RF protocol is OOK?
Title: Re: New OOK library for Moteino
Post by: janwolf on January 24, 2016, 04:35:19 PM
It seems that it is OOK (for hardware like MCT-302) as jeelib handle it (https://github.com/jcw/jeelib/blob/master/examples/RF12/ookRelay2/decoders.h).
I've found a PDF from russia describing the MCT-302 where the protocol is described. It's composed of 32 bits but does not have a preamble !

Jan
Title: Re: New OOK library for Moteino
Post by: janwolf on January 25, 2016, 10:17:58 AM
If you're new to Arduino then I recommend the original way that involves a small modification to the Moteino. It's a much simpler and more robust approach. BTW, are you sure that the Visonic RF protocol is OOK?

You mean to use your RFM69OOK code ? But, about the RSSI approach, have you continue to explore this way ?

Jan
Title: Re: New OOK library for Moteino
Post by: kobuki on January 25, 2016, 10:19:41 AM
Why else would you post in the thread about my OOK lib? :)

Yes, I'm suggesting using it. No further code for exploring purely RSSI-based solutions yet to try, sorry.
Title: Re: New OOK library for Moteino
Post by: MrSporty on November 29, 2016, 06:41:34 AM
The funny thing is, I tested transmitting with your code but only had a logic analyzer attached and never checked if it was really transmitting. I now looked at the spectrum analyzer and can't see any transmission on 433.9 MHz when I run the code...

EDIT: Which type of RFM69 do you use? H, HW, CW or HCW? I currently use a RFM69HCW for the tests.
EDIT: Remote device is a simple power socket that should work receiving a simple bit burst.

Works now with a lot of devices (receiving & sending), but had to change and adjust some (a lot) settings, library & code. I will go into detail later, maybe with a detailed blog entry.

Cheers
narkbee

Sorry for dredging up an old thread but I was wondering if you (markbee) had posted those changes anywhere as I'm having a devil of a time getting a basic RFM69 / Arduino setup to perform any form of OOK transmit.

The same setup will happily send and receive standard packet based data using the slew of example code available so I'm happy that the basics are in place. It will also receive KAKU-like data using the libs here :

https://github.com/SevenW/embapps/tree/master/ArduinoRFM69
Title: Re: New OOK library for Moteino
Post by: kobuki on November 29, 2016, 06:53:55 AM
I asked him several times too, he never bothered. He needed some general cloning device IIRC, and that needs a lot of additional coding, though there are no changes needed to the library itself, so I don't really get what he meand by that statement. You can just modulate OOK in the sketch in any way you want. The transmitter worked just fine for me. Though I didn't spend a lot of time on it, I was able to receive OOK signals just fine using a pair of moteinos. You did the extra jumper wire soldering on the Moteino, right?
Title: Re: New OOK library for Moteino
Post by: MrSporty on November 29, 2016, 08:00:29 AM
Thanks for the quick reply kobuki !

I have patched in the DIO2 pins to the int pins on a pair of setups that I have (fly wired Uno + RFM69). I initially purchased a batch of RFM69's from a china supplier and upon not being able to get them to transmit I decided to pick another up from a legit reseller. Unfortunately both seem to exhibit the same behavior.

I assumed that the DIO2 pin was just for an interrupt based reception but I can confirm they are wired correctly.

I know the SPI part is also working as I can use a "dumpreg" example and see that they are being loaded with the correct values. I know the setups will also transmit packet data fine because they are nice an noisy when checking them with an SDR dongle and a simple waterfall display.
Title: Re: New OOK library for Moteino
Post by: DenisJ on January 26, 2017, 03:54:42 AM
Hi there all
sorry Kobuki if I reopen this thread... I have a moteino mega usb with a RFM69HCW on it.

On the moteino mega usb board, I so a jumper near DIO2 pin of RFM69HCW ... it's like if you close this jumper
the DIO2 is mapping to the D21 pin of moteino.

I read on your lib (https://github.com/kobuki/RFM69OOK) that DIO2 must be connected to the pin 10 of moteino.

Can I change this pin someware in your lib please ? from 10 to 21... if yes where I must do it please ?

Thanks a lot
Denis
Title: Re: New OOK library for Moteino
Post by: kobuki on January 26, 2017, 05:15:38 AM
If you don't use interrupts but only polling, you can map DIO2 to any free digital input pin by changing RF69OOK_IRQ_PIN in RFM69OOK.h and solder your jumper accordingly. If you use interupts, your options are limited, and depend on the actual ATMega chip. In that case you also need to change the associated RF69OOK_IRQ_NUM as well.
Title: Re: New OOK library for Moteino
Post by: DenisJ on January 26, 2017, 05:26:20 AM
Sorry,
I'm little confusing ... I know I use the INT0 but on the DIO0 pin of the RFM60HCW
In this case the RFM69 lib from LowPowerLab it's work.

You tell me that I must use the INT0 on the DIO2 pin in this case ?
Sorry but like you understand I'm newbe in this world :-)

Thanks again
Denis
Title: Re: New OOK library for Moteino
Post by: kobuki on January 26, 2017, 05:39:50 AM
You can use INT0 or INT1 (pin 10 or 11), yes. Pin 10 is an example for one of the 2 available interrupts on the Mega.
Title: Re: New OOK library for Moteino
Post by: DenisJ on January 26, 2017, 05:54:02 AM
I'm on Arduino mega 2560 now ... cause I don't want to broke the beautiful Moteino mega :-)

Sorry, I still not understand if I must use only an interrupt ...or two.

So I ask you please... on the RFM69HCW module I will use DIO0 or DIO2 ...or all two ?

Thanks again
Denis
Title: Re: New OOK library for Moteino
Post by: kobuki on January 26, 2017, 06:06:33 AM
DIO0 is used for the normal operation of the Moteino. It's not used in my lib.
Title: Re: New OOK library for Moteino
Post by: DenisJ on January 26, 2017, 06:23:01 AM
YESSS !!! it's work :-)
I receive a lot of nums with your OOKDumper sketch.
Thanks a lot !!!

Now please I want to ask you another think...
have you ever test a New Kaku protocol using your modified RFM69 lib ?   

I want to send/receive some commands to a domotics program that is linked with RFLINK gateway (http://www.nemcon.nl/blog2/2015/07/devlist).

Thanks a lot again
Denis

Title: Re: New OOK library for Moteino
Post by: kobuki on January 26, 2017, 06:33:06 AM
I have no idea about the new KAKU protocol, sorry. But it's one of the most discussed protocols so I think you could find all required info on the net. Or someone else might be able to help here if you open a new thread.
Title: Re: New OOK library for Moteino
Post by: DenisJ on January 26, 2017, 06:39:57 AM
Ok ...no problem
Maybe if I can make it work I'll put it here in order to have it for future.

Let me tell you that you make a good work porting ASK/OOK to the RFM69 lib.

Thanks again
Denis
Title: Re: New OOK library for Moteino
Post by: AntoineLyon on September 26, 2017, 08:23:47 AM
Hi, sorry if this is not the absolute right place for my question.

I found your lib to be exactly what I'm looking to. 1/ I need to scan OOK signals, so OOKDumper may be useful, 2/and to generate a specific signal, see picture, and OOKTrasmitTest may be perfect for that.

But I'm using an Arduino Feather M0 with RFM69HCW, changed your lib to use   #define RF69OOK_SPI_CS      8 and #define RF69OOK_IRQ_PIN     3, but no signal seems to be received. Do you have an idea of what I'm missing ?

Thanks
Title: Re: New OOK library for Moteino
Post by: kobuki on September 26, 2017, 08:28:01 AM
I don't own any M0-based device so I can't help, sorry. Maybe other folks using something like the Feather can say something. IIRC Felix's RFM69 lib has been ported or patched to support M0, so you might get ideas looking at its code.
Title: Re: New OOK library for Moteino
Post by: AntoineLyon on September 26, 2017, 08:55:23 AM
I've already asked in a RH69 thread and Felix answered, but he has not explored the "not packetized" OOK. I will look on both libs deeper. Thanks.
Title: Re: New OOK library for Moteino
Post by: oldfart on September 30, 2017, 12:12:03 PM
My plan is (was)
Most hand-held remotes in Europe operate at 868Mhz - blinds/roller shutters/garage doors etc.
I want to integrate a [device/ESP8266/Moteino] into Home Assistant to open/close (and maybe get the state of) those devices.
Would involve:
1. learn the remote codes (a bit like the Broadlink RM pro) from the hand-held remote
2. get those codes and save into Home Assistant (in hex/binary/whatever)
3. re-transmit those codes to the device, using MQTT from Home Assistant

so far I have a Moteino Mega, thats as far as I got.
Spent a week trolling round the internet, looking for suitable code.
Any ideas/comments??
Title: Re: New OOK library for Moteino
Post by: miketuk on January 18, 2019, 07:39:29 AM
Hi

I would like to use the RFM69HCW to send data (or at least transmit a beacon), so thought this would be a good place to start.

I have hooked up the RFM69 on Sparkfun breakout to my Moteino and I am using the OOKTransmitTest.ino sketch.  To be sure, I have also taken DIO2 to pin 3 on the Moteino.

However, I am not seeing anything on 433.9mhz. I am listening with both my Kenwood THf7e and SDR# with a USB dongle. If I try with the LowPowerLabs provided libraries and using the Node.ino sketch, I see plenty of data on 433.0mhz, so I believe (!) everything is hooked up as it should be.

Any suggestions anyone?

Regards
Mike