avago
Posts: 14
Joined: Mon Jan 28, 2013 9:20 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Thu Feb 07, 2013 9:26 am

OK I see. Seems to be a method of asynchronous transmission, so the data rate must match the TX rate?
Still doesnt explain why the amplitudes vary in places.
If a man says something, and a women doesn't hear, is he still wrong?

User avatar
KarlS
Posts: 42
Joined: Fri Oct 12, 2012 1:10 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Wed Feb 13, 2013 4:09 pm

It’s been a few days since I last posted some results of my struggle to make sense of the FSK transmissions of my 915MHz Fine Offset (National Geographic NG265NC). Now, after weeks of try-and-error I finally get the results that I want. :D

Code: Select all

07:58:44 Temperature: -6.5°C --- Humidity:  92% --- Windspeed: 1.7m/s (6.1km/h) --- Windgust: 9.2m/s (33.0km/h) --- Bearing: SE
With my limited knowledge of electronics and no test equipment, I gave up – at least for the time being - on trying fine-tuning the RFM01 configuration so I would not get random bit errors, crc errors, shifted bits etc. My solution now is to eliminate these errors through software.

One thing I found was that the length of the FIFO read loop determines how often the data are resent by the RFM01.
• If I read 99 bytes, I get one long string.
• If I read 33 bytes, I get 3 identical strings of the first 33 bytes.
• If I read 20 bytes, I get 4 identical strings ...
• If I read the FIFO in 12 byte loops, I get 7 identical strings.

As I’m only interested in the first 10 – 12 bytes anyway, the next step is to compare every bit position over all 7 strings and correct any bit errors by applying a “majority vote”. The resulting string is (hopefully) free of random bit errors. Here is one of the resulting bit strings:

Code: Select all

                      sttt tttttttt   hhhhhh wwwwwwww gggggggg                       bbbb
07:58:44 10100110 10101000 01000001 01011100 00000101 00011011 00000000 00000000 00000110 ...
This is how you interpret it:
• Byte 0: Station ID
• Byte 1: high nibble unknown, bit 3 is the sign, bit 0-2 are the high part of the temperature
• Byte 2: low part of the temperature (with 1 decimal)
• Byte 3: bit 6-7 unknown, bit 0-5 humidity
• Byte 4: wind speed (value * 0.34 gives the speed in m/s)
• Byte 5: wind gust (value * 0.34 gives the speed in m/s)
• Byte 6: unknown (maybe rain counter)
• Byte 7: unknown (maybe rain counter)
• Byte 8: high nibble unknown, low nibble wind bearing (0 = N, 1 = NNE, 2 = NE, …)

Once the snow turns to rain in our part of the world, I'm sure to find the rain counter in byte 6 or 7. My next steps will be to include a BMP085 (it’s in the mail), write some routines to calculate 5 or 10 minute averages, and store the data in a MySQL database.

One interesting thing I noticed yesterday was that my console reported “lost sensor contact” errors for a few hours, while the Pi was happily receiving and recording data. :roll: Maybe it's time to ditch this unreliable console ...

avago
Posts: 14
Joined: Mon Jan 28, 2013 9:20 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Thu Feb 14, 2013 9:41 am

Nice work KarlS. You do sometimes find it's just easier to go with what you have rather than what others have! I did find I had a spare 00 at the beginning of my reception which ignored for several weeks until I fell upon the solution (wasn't flushing the FIFO at what I considered the end of reception)

I accidentally plugged my wind sensor into the rain sensor socket and the rain level shot up very quickly. Luckily it was the end of the month so I could reset it without the missus noticing :oops: you could try that if the plugs haven't frozen in and you're impatient.

I changed PIC devices from the 33f to 16f series and all the problems with SPI disappeared. I can now talk to the RM12 at any SPI speed I choose (I've tried 10, 5, 4, 2.5, 2,1M & 125kHz). The RM12 is the only chip that I've had SPI problems with on the 33f. Odd.
If a man says something, and a women doesn't hear, is he still wrong?

dickydodds
Posts: 25
Joined: Sun Oct 14, 2012 10:40 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Wed Feb 20, 2013 5:09 pm

Hey everyone, did you know maplin are changing out your N96GY USB weather stations? My anemometer started sticking about a monthago and I called them up and they say its a known problem. I swapped out my whole system last night and got a brand new one.

Am currently trying to tune in my rfm01 to get data out again. Mine was 6 months old and the anemometer is a slightly different design to the old one.

Though you aught to be aware.

dicky

SevenW
Posts: 3
Joined: Wed Feb 27, 2013 9:36 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Wed Feb 27, 2013 9:52 pm

@KarlS and @avago:
Can you share the c-code of the FIFO read-out section?
Starting from a working code is always easier.

What I understand from the thread on the SPI speed is that it does not really matter in the end, or should it be reduced during FIFO read out?

On the packet length, I interpret cii's work as that it sends out 33 bytes every 48seconds. At 17.24kpbs, a packet takes about 15ms. So that is what I should be looking for at 868.300MHz. I do not own one, but there are plenty around on the roofs. Downside it is more difficlt to experiment.

User avatar
KarlS
Posts: 42
Joined: Fri Oct 12, 2012 1:10 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Thu Feb 28, 2013 12:36 am

Of course I will share the code. There are a few things I should mention, however:
  • This program is based on the original program by Kevin Sangeelee and the help and suggestgions from all the other contributors to this forum thread. My sincere thanks to all of them.
  • This programm is a work in progress, there is still a lot of work to do. As described in one of my earlier posts, I'm not able to get rid of all bit errors, so at times I have to work around them.
  • My station use a 915MHz RFM01 receiver module, so you will need to change the corresponding setup values
  • At the moment I store the received/decoded data in a MySQL or Sqlite3 database. As I don't need the data at a 48 second interval, I wrote some functions to give me 10 min averages. Some of those are not trivial, for example the avgerage wind direction is quite difficult to compute (some vector math)
  • I seldom write comments in my source code before I'm pretty sure I won't change it again
[Edit:] I have changed the attachment to the most current version (2013/03/16)
[Edit 2:] I have changed the attachment to my most current (final) version (2013/03/27)

Cheers

Karl
Bridge Lake Weather Station
Attachments
fo2.zip
(42.68 KiB) Downloaded 380 times
Last edited by KarlS on Wed Mar 27, 2013 7:56 pm, edited 3 times in total.

avago
Posts: 14
Joined: Mon Jan 28, 2013 9:20 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Thu Feb 28, 2013 5:47 pm

I'll post my code in a few days - I'm away just now. Nag me in a week if I havent done it. Note mine is for a microchip 16f877.
If a man says something, and a women doesn't hear, is he still wrong?

SevenW
Posts: 3
Joined: Wed Feb 27, 2013 9:36 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Thu Feb 28, 2013 10:30 pm

So I have got this working with on what I assume to be a Alecto WS4000, using the program of KarlS, with few modifications:

Code: Select all

RFM01.h:
added:
	#define CRYSTAL_EN		(1 << 8)
and I am using in this file:
	#define BAND_868		(2 << 11)

As my receiver is based on Kevins design, DATA/nFFS is connected to GPIO 21. It requires pull up.
Added to end of function:
	void spi_init()
the lines:
	//pull-up DATA/nFFS
	#define DATA_PIN 21
	bcm2835_gpio_fsel(DATA_PIN, BCM2835_GPIO_FSEL_INPT);
	bcm2835_gpio_set_pud(DATA_PIN, BCM2835_GPIO_PUD_UP);
In function
    void rfm01_init()
The frequency band and frequency is changed:
    rfm01_cmd(CMD_CONFIG |          // -------- Configuration Setting Command --------
		BAND_868 |                  // selects the 868 MHz frequency band
		LOWBATT_EN |                // enable the low battery detector
		CRYSTAL_EN |                // the crystal is active during sleep mode
		LOAD_CAP_12C5 |             // 12.5pF crystal load capacitance
		BW_134);                    // 134kHz baseband bandwidth

    rfm01_cmd(CMD_FREQ |            // -------- Frequency Setting Command --------
		0x067c);                    // 868.300 MHz

In:
static void receive_records()
I reduced the receiver sleep time from 44s to 5ms, as I try to receive unknown stations as well:
        //bcm2835_delay(44000);													// idle loop until next possible transmission
        bcm2835_delay(5);													// idle loop until next possible transmission

I commented out all mysql related code in ng265.c, ng265func.c and MakeFile.
Finally I had to download and instal the proper bcm2835 library. Link is in ng265.c.

On the HW-side I had to solder the nIRQ to GPIO 22.

Then almost immediately it started receiving what I think is a weather station. Signals are nicely spaced 48 secs apart.
This is the extended logging of three receptions:

Code: Select all

22:57:50       8540     8400     8200     8000     8400     8000     8200     8000
22:57:50       87fe     877e     877e     87fd     87fd     87fd     877e     877e
22:57:50       87fe     877e     877e     87fe     87fe     87fe     877e     877e
22:57:50       877f     87fe     877d     877d     877d     877d     87fe     877e
22:57:50       877e     87fe     87fe     877e     877e     877e     87fe     87fe
22:57:50 f 00011000 00010100 01001111 00000001 00000010 00000000 11111101 00001110
22:57:50 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000000
22:57:50 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000000
22:57:50 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000000
22:57:50 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000000
22:57:50 c 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000000      (20 bit errors)
2013-02-28 22:57:50   Temperature: 2.3°C --- Humidity:  93% --- Windspeed: 0.0km/h --- Windgust: 0.0km/h --- Bearing: N
22:58:38       877e     87fe     877e     877e     877e     877e     877d     877d
22:58:38       8080     8080     8080     8080     8080     8080     8080     8180
22:58:38       817f     85c0     81c0     8400     8400     8400     8100     8580
22:58:38       87fe     877e     877e     87fe     87fe     87fe     877e     87fe
22:58:38       87fd     877e     877e     87fe     87fe     87fe     877e     877e
22:58:38 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000000
22:58:38 f 11101111 11110000 01111111 00111101 00011110 11001100 00111000 00001101
22:58:38 f 10000000 00010100 01011110 00000000 00000001 00000010 01110110 10000110
22:58:38 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010
22:58:38 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010
22:58:38 c 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010      (54 bit errors)
2013-02-28 22:58:38   Temperature: 2.3°C --- Humidity:  93% --- Windspeed: 0.0km/h --- Windgust: 0.0km/h --- Bearing: NE
22:59:26       87fe     877e     87fe     87fe     87fe     87fe     877e     87fe
22:59:26       87fe     877e     877e     87fd     87fd     87fd     877e     877e
22:59:26       877e     87fe     877e     877e     877e     877e     87fe     877e
22:59:26       87fe     87fe     877e     87fd     87fd     87fd     877e     877e
22:59:26       877e     87fe     877e     877e     877e     877e     87fe     877d
22:59:26 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010
22:59:26 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010
22:59:26 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010
22:59:26 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000100
22:59:26 f 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000100
22:59:26 c 11110000 00010111 01011101 00000000 00000000 00000011 11000110 00000010      (4 bit errors)
2013-02-28 22:59:26   Temperature: 2.3°C --- Humidity:  93% --- Windspeed: 0.0km/h --- Windgust: 0.0km/h --- Bearing: NE
Although I do not understand the logged raw values yet, the temperature is close, and the anemometer of this station is stuck so zero windspeed is expected.

Thanks KarlS for the code and thank all of you for reverse engineering the protocol.
Next step: Get this working on the JeeNode with a RFM12B.
SevenW

SevenW
Posts: 3
Joined: Wed Feb 27, 2013 9:36 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Sat Mar 02, 2013 8:46 pm

I did some investigations into the "WH1080 V2 protocol", which I have documented on a personal web page: http://www.sevenwatt.com/main/wh1080-protocol-v2-fsk/.

The main findings are:
- six transmissions of a 16-byte package
- three preample and 2 synchron bytes remain invisible with RFM01B and RFM01.
- payload is ten bytes
- The last byte of the payload is the CRC, same as in the WH1080 V1 protocol.

In total this is the 3 times 33 three bytes reported, or 99 bytes.
What I still have to figure out is how to detect the end of a package, other then counting bytes. I expect the RFM01 / RFM12B should provide me some info through the VDI indicator or something like that. It may be reported through the status bits. I will look into it.

SevenW

User avatar
KarlS
Posts: 42
Joined: Fri Oct 12, 2012 1:10 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 05, 2013 8:26 pm

The BMP085 arrived and I have it working using Kevin's bmp085.c program. To calculate the true pressure the program uses the (indoor) temperature measured by the BMP085. Wouldn't it be better to use the outside temperature as measured by the weather station?

Code: Select all

long t = (b5 + 8)  >> 4;
gives the true indoor temperature and b5 is later used to calculate the true pressure. Now, if I know the outside temperature, then b5out can be calculated as

Code: Select all

long b5out = (outside_temp * 160) - 8;
and I can use b5out in

Code: Select all

long b6 = b5out - 4000;

ksangeelee
Posts: 192
Joined: Sun Dec 25, 2011 5:25 pm
Location: Edinburgh, UK
Contact: Website

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Wed Mar 06, 2013 10:01 am

KarlS wrote:The BMP085 arrived and I have it working using Kevin's bmp085.c program. To calculate the true pressure the program uses the (indoor) temperature measured by the BMP085. Wouldn't it be better to use the outside temperature as measured by the weather station?
As I recall, the temperature is used to account for the temperature coefficient of the pressure sensor itself, so the outdoor temperature wouldn't correspond to the temperature of the actual BMP085 module.

User avatar
KarlS
Posts: 42
Joined: Fri Oct 12, 2012 1:10 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Wed Mar 06, 2013 1:38 pm

Ahh right, that should have been obvious :oops:

However, the reason why I'm asking is that my measurements are about 0.5 hPa off from those of a nearby (2km) professional weather station. And as Wikipedia (where would I be without it?) says: “Temperature and humidity also affect the atmospheric pressure, and it is necessary to know these to compute an accurate figure.”

But maybe 0.5 hPa isn’t something to get too excited about …

ksangeelee
Posts: 192
Joined: Sun Dec 25, 2011 5:25 pm
Location: Edinburgh, UK
Contact: Website

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Wed Mar 06, 2013 1:58 pm

KarlS wrote:Ahh right, that should have been obvious :oops:
Well, it had me too for a bit :)
KarlS wrote:However, the reason why I'm asking is that my measurements are about 0.5 hPa off from those of a nearby (2km) professional weather station. And as Wikipedia (where would I be without it?) says: “Temperature and humidity also affect the atmospheric pressure, and it is necessary to know these to compute an accurate figure.”

But maybe 0.5 hPa isn’t something to get too excited about …
Did you remember to configure your own altitude correctly? Did you compare readings at exactly the same time of day? I tested against my LCD display's barometer, and it corresponded exactly (I was impressed by the Fine Offset sensor).

User avatar
KarlS
Posts: 42
Joined: Fri Oct 12, 2012 1:10 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Thu Mar 07, 2013 9:36 pm

ksangeelee wrote:Did you remember to configure your own altitude correctly? Did you compare readings at exactly the same time of day?
Yes to both questions. It's still off by (today) 1.5hPa. Maybe the difference between inside (20°C) and outside (-10°C) makes a difference. BTW looking into this, I found an error in the bmp085.c program: the line

Code: Select all

	char up_buf[2];
should read

Code: Select all

	char up_buf[3];
I hoped this would solve my problem, but it didn't. I'm still working on this ...

Meanwhile the program that I posted a week ago has been greatly improved. It now accepts command line parameters for printing, use of a database and/or the BMP085 module, conversion from metric to imperial, optional wind speed multiplier ... so if anyone who downloaded the alpha version is interested in a beta, please send me a PM.

tb63
Posts: 14
Joined: Mon Aug 06, 2012 2:40 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Sat Mar 23, 2013 8:51 pm

Hi all,

I have this data that I think looks good using LNA_0,RSSI_97 but no decoded information comes out . Any suggestions ??
Thsnk

Code: Select all

Initialising RFM01
SPI: mode 0, 8-bit, 1000 KHz
Ctrl+C to exit
  LNA_0,RSSI_73 idx 0     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_0,RSSI_79 idx 1     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_0,RSSI_85 idx 2     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_0,RSSI_91 idx 3     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_0,RSSI_97 idx 4   100.00<   6.90  100.00  100.00  100.00  100.00
 LNA_0,RSSI_103 idx 5   100.00  100.00  100.00  100.00  100.00  100.00
  LNA_6,RSSI_73 idx 6     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_6,RSSI_79 idx 7     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_6,RSSI_85 idx 8     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_6,RSSI_91 idx 9     0.00    0.00    0.00    0.00    0.00    0.00
  LNA_6,RSSI_97 idx 10   45.98    0.00   70.11   13.48   11.49   48.28
 LNA_6,RSSI_103 idx 11  100.00  100.00  100.00  100.00  100.00  100.00
 LNA_14,RSSI_73 idx 12    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_14,RSSI_79 idx 13    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_14,RSSI_85 idx 14    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_14,RSSI_91 idx 15    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_14,RSSI_97 idx 16    0.00    0.00    0.00    0.00    0.00    0.00
LNA_14,RSSI_103 idx 17  100.00    0.00  100.00  100.00  100.00  100.00
 LNA_20,RSSI_73 idx 18    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_20,RSSI_79 idx 19    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_20,RSSI_85 idx 20    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_20,RSSI_91 idx 21    0.00    0.00    0.00    0.00    0.00    0.00
 LNA_20,RSSI_97 idx 22    0.00    0.00    0.00    0.00    0.00    0.00
LNA_20,RSSI_103 idx 23  100.00    0.00  100.00  100.00  100.00  100.00
RSSI Duty 100.00

dickydodds
Posts: 25
Joined: Sun Oct 14, 2012 10:40 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Sat Mar 23, 2013 9:23 pm

look at previous posts - I describe how to setup the right values - safe to say, do NOT use any that says 100.00 thats just noise - try and use one near to where the 100's end.

Try LNA_0,RSSI_9 and bandwidth 200 that might be better but you need to play.

I found LN 0 to be the best - experiment around there.

Dicky

tb63
Posts: 14
Joined: Mon Aug 06, 2012 2:40 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Sun Mar 24, 2013 6:07 am

dickydodds wrote:...
I found LN 0 to be the best - experiment around there.
Dicky
Thanks dickydodds ,

With LNA_0,RSSI_91 and bandwidth 134 each time my LCD flashes I got this :

Code: Select all

Data bits = 88   (offset 8) (6 short) Packet signature found
Frequency deviation -4.0KHz (-4)
a5 11 da 54 01 03 09 4f 0e e5 crc ok (gap 130s)
Pulse stats: Hi: 183 - 372   Lo: 1331 - 1435  (88 point)
Threshold now 851
calculate_values
Station Id: 0A51
Temperature: 7.4C, Humidity: 84%
Wind speed: 0.34 m/s, Gust Speed 1.02 m/s, NW
Wind speed: 0.8 mph, Gust Speed 2.3 mph, NW
Total rain: 714.9 mm
Listening for transmission
Data bits = 88   (offset 8) (6 short) Packet signature found
Frequency deviation -3.0KHz (-3)
a5 11 db 54 00 01 09 4f 0e d8 crc ok (gap 48s)
Pulse stats: Hi: 382 - 504   Lo: 1433 - 1528  (88 point)
Threshold now 968
calculate_values
Station Id: 0A51
Temperature: 7.5C, Humidity: 84%
Wind speed: 0.00 m/s, Gust Speed 0.34 m/s, NW
Wind speed: 0.0 mph, Gust Speed 0.8 mph, NW
Total rain: 714.9 mm
The station is PCE FW-20 868Mhz at a distance of 30 meters and outside my home.
Perfectly working

Thanks

dickydodds
Posts: 25
Joined: Sun Oct 14, 2012 10:40 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Sun Mar 24, 2013 10:17 pm

Glad to give back what the forum guys gave me :D

So, you got it working over 30 meters? That's ace!

I had to move mine higher up by 1 meter and its about 10 meters away in my garage because it kept losing the signal. Seems ok now though.

I just cant get my second one working in my house next to the weather station - approx 30 meters away but the station seems to work ok! Weird!

basti122303
Posts: 35
Joined: Fri Jun 15, 2012 8:37 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 26, 2013 8:32 am

I use a PCE FWS-20 and have still some problems with the sensor witch is placed next to the raspberry.

Sometimes it lose the connection, "hang up" with showing

Code: Select all

Listening for transmission
So i have insert some debug output i think its "hang up" in the scheduler_realtime() function.
How can i solve this with a timer, that the "scheduler_realtime()" function is exited after 60 seconds?
I've try this with a "signal(SIGALRM, exitfunc);" -- without luck.
Here is my code with debug output:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <time.h>
#include <sched.h>
#include <sqlite3.h>

#include "bcm2835.h"
#include "rfm01.h"
// time to wait (48 * LOGGING_INTERVAL)
#define LOGGING_INTERVAL  (1)

#define DATADIR "/home/pi/weatherlogger-db/data/raw/"
#define DATABASE "/home/pi/weather.db"
// Presure sensor?
#define USE_BMP085
// Meter above sea_level
#define ALTITUDE_M	210.0f

// timer stuff
#include <stdio.h>      /* printf */
#include <time.h>       /* clock_t, clock, CLOCKS_PER_SEC */
#include <math.h>       /* sqrt */

#include <signal.h>
#include <stdlib.h>
// end



static int fd = -1;
static const char *device = "/dev/spidev0.0";
static uint8_t mode=0;
static uint8_t bits = 8;
static uint32_t speed = 1000000;
static uint16_t delay=0;
static inited = 0;
int g_low_threshold = 1000;

char *direction_name[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};



uint16_t cmd_reset	= CMD_RESET;
uint16_t cmd_status = CMD_STATUS;

// Expected bit rate: 95 = 1959, 99 = 1700, 9c = 1500, a1 = 1268, aa = 1000, b8 - 756, d5 = 500
uint16_t cmd_drate = CMD_DRATE|0xaa;	// drate is c8xx rather than c6xx
// uint16_t cmd_freq	= CMD_FREQ|0x620; // 433.92 MHz
uint16_t cmd_freq	= CMD_FREQ|0x67c; // 868.3 MHz

uint16_t cmd_afc	= CMD_AFC|AFC_ON|AFC_OUT_ON|AFC_MANUAL|AFC_FINE|AFC_RL_7;
uint16_t cmd_dcycle = CMD_LOWDUTY|0x00;
uint16_t cmd_fifo	= CMD_FIFO|0x00;

uint16_t cmd_config	= CMD_CONFIG|BAND_868|LOAD_CAP_12C0|BW_134;
uint16_t cmd_rcon = (CMD_RCON|RX_EN|VDI_DRSSI|LNA_0|RSSI_97);
uint16_t cmd_dfilter = (CMD_DFILTER|CR_LOCK_FAST|FILTER_OOK);


void exitfunc(int sig)
{
    _exit(0);
}

void uninit(void);
void scheduler_realtime();
void scheduler_standard();
void calculate_values(unsigned char *buf, float temp, float pressure);
uint8_t _crc8( uint8_t *addr, uint8_t len);

sqlite3* db = NULL;

static void pabort(const char *s)
{
    if(inited)
    {
        uninit();
    }
	perror(s);
	abort();
}

static uint16_t send_command16(int fd, uint16_t cmd)
{
	uint8_t tx[2];
	uint8_t *buf = (uint8_t *)&cmd;
	tx[0] = buf[1];
	tx[1] = buf[0];

	//printf("SPI %02x%02x\n", buf[1], buf[0]);

	uint8_t rx[2] = {0, 0};
	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = 2,
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	if(ioctl(fd, SPI_IOC_MESSAGE(1), &tr) < 1)
		pabort("can't send spi message");
	
	return (((uint16_t)rx[0]) << 8) + rx[1];
}

void sendReset(void)
{
    send_command16(fd, cmd_fifo); // in case reset sensitivity is low
    send_command16(fd, cmd_reset);

}

void setupChip(void)
{
    send_command16(fd, cmd_status);
    send_command16(fd, cmd_config);
    send_command16(fd, cmd_freq);
    send_command16(fd, cmd_drate);
    send_command16(fd, cmd_rcon);
    send_command16(fd, cmd_dfilter);
    send_command16(fd, cmd_fifo);
    send_command16(fd, cmd_afc);
    send_command16(fd, cmd_dcycle);
	
}

void init(void)
{
    if(sqlite3_open(DATABASE, &db) != 0)
    {
       printf("Failed to open DB\n");
        exit (-1);
    }

    if(map_peripheral(&gpio) == -1) 
    {
	  printf("Failed to map the GPIO registers into the virtual memory space.\n");
	  exit(-1);
    }
    
    if(map_peripheral(&timer_arm) == -1)
    {
        printf("Failed to map the registers into the virtual memory space.\n");
        unmap_peripheral(&gpio);
        exit(-1);
    }

    
    inited = 1;

	// 0xF90200; // run at 1MHz
	TIMER_ARM_CONTROL = TIMER_ARM_C_DISABLE|TIMER_ARM_C_FREE_EN
							|TIMER_ARM_C_16BIT|TIMER_ARM_C_PS1
							|TIMER_ARM_C_FPS(0xf9);
	
	// Init GPIO21 (on pin 13) as input (DATA), GPIO22 (pin 15) as output (nRES)
	*(gpio.addr + 2) = (*(gpio.addr + 2) & 0xfffffe07)|(0x001 << 6);
	
	fd = open(device, O_RDWR);
	if (fd < 0)
	{
	    pabort("Failed to open device");
	}

	// SPI mode
	if(ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1)
	{
	    pabort("Can't set SPI mode");
	}

	// Bits per word (driver only supports 8 -bits I think, but RFM12B handles this ok)
	if(ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1)
	{
		pabort("Can't set bits per word");
	}

	// SPI clock speed (Hz)
	if(ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1)
	{
		pabort("Can't set SPI clock speed");
	}

	
}

void uninit(void)
{
    if(inited)
    {
        unmap_peripheral(&gpio);
        unmap_peripheral(&timer_arm);
        if(fd != -1)
        {
            close(fd);
            fd = -1;
        }
        sqlite3_close(db);
        inited = 0;
    }
}

void strobe_afc(int fd) {

	send_command16(fd, cmd_afc|AFC_STROBE); // Strobe high
	send_command16(fd, cmd_afc & (~AFC_ON)); // Strobe low, disable AFC processing
	uint16_t status = send_command16(fd, cmd_status);
	// get offs bits and extend two's complement to a byte
	int8_t offset = (status & STATUS_OFFS) | (status & STATUS_OFFSIGN ? 0xe0 : 0);
	
	float freq_offs = (float)offset;
	send_command16(fd, cmd_afc); // Strobe low, re-enable AFC

	printf("Frequency deviation %0.1fKHz (%d)\n", freq_offs, (int)offset);

	send_command16(fd, cmd_rcon);
}


void main_loop(void)
{
printf("inside main_loop()\n");
    uint16_t status;
    uint8_t device_id = 0xa1;

    uint8_t rssi = 0, oldrssi = 0;
    unsigned int shorts = 0;
    unsigned int rssitime, oldrssitime, now;
    int count = 0, timeout = 1;
    time_t last_valid = time(0);
    int crc_passed;

    unsigned int rssitime_buf[500];
    unsigned char bytes[11];

    oldrssitime = TIMER_ARM_COUNT;

// mycounter AND timer
    int mycounter = 0;
    int myseconds = 60;
    clock_t endwait;

    endwait = clock () + myseconds * CLOCKS_PER_SEC ;
// exit program, debug use
//    signal(SIGALRM, exitfunc);
//    alarm(120);

// printf("set signal -- exit program in next 120 second\n");
// test signal exit program
// while (1);

    // Switch to realtime scheduler
    scheduler_realtime();

// main loop while
// change for timer
//    do
printf("while after scheduler_realtime()");
    while(clock() < endwait) // Ctrl+C to exit for now...
    {
       // Read the GPIO pin for clocked DATA value
        status = ((*(gpio.addr + 13)) >> 21) & 1;
        rssi = status;
        rssitime = TIMER_ARM_COUNT;
        // Check if the pin transitioned
        if(rssi != oldrssi)
        {
            // If falling edge (1 -> 0), then store bit pulse duration
            if(rssi == 0)
            {
                rssitime_buf[count] = rssitime - oldrssitime;
                if(++count == 500)
                    count = 499;
            }
            oldrssi = rssi;
            oldrssitime = rssitime;
            timeout = 0;
        }
        // Check time since last transition. If timeout, then dump packet.
        int packet_offset = 0;
        now = TIMER_ARM_COUNT;

        if(!timeout && (now - oldrssitime) > 5000)
        { // && count > 0

	printf ("inside time out");
            if(count > 60)
            { // then maybe something at least interesting
                // Look for device_id
                int idx, matchcount = 0;
                uint8_t bit;
                for(idx=0; idx < count; idx++)
                {
                    bit = rssitime_buf[idx] < g_low_threshold ? 1 : 0;
                    //if( bit == (device_id & (0x80 >> matchcount)) >> (7-matchcount) )
                    //{
                        matchcount++;
                    //}
                    //else
                    //{
                     //   matchcount = 0;
                   // }
                    if(matchcount == 8)
                    {
                        packet_offset = idx - 7;
                        break;
                    }
                }
                printf("\rData bits = %d   (offset %d) (%d short)\n", count, packet_offset, shorts);
                if(count == 88 && matchcount == 8)
                { // then probably a data packet

                    // LED on
                    *(gpio.addr + (0x1c >> 2)) = 1 << 22;

                    strobe_afc(fd); // lock frequency to good signal

                    int b;
                    uint8_t byte;
                    for(idx=0; idx < 11; idx++)
                    {
                        byte = 0;
                        for(b=0; b < 8; b++)
                        {
                            // Short pulses 1, long pulses 0
                            uint8_t bit = rssitime_buf[packet_offset + (idx * 8 + b)] < g_low_threshold ? 1 : 0;
                            byte = (byte << 1) + bit;
                        }
                        bytes[idx] = byte;
                        printf("%02x ", byte);
                    }
                    crc_passed = bytes[10] == _crc8(bytes+1, 9);
                    printf("crc %s (gap %ds)\n", crc_passed ? "ok" : "fail", (int)(time(0) - last_valid));
                    last_valid = time(0);
                    fflush(stdout);
                }
            }
            else
            {
                if(shorts++ % 10 == 0)
                {
                    printf(".");
                    fflush(stdout);
                }
            }

	    printf("set timeout to 1");
            timeout = 1;

            // If we get enough bits, then dump stats to indicate pulse lengths coming from the device.
            if(count > 40)
            {
                // These are slightly confusing - lo used to mean low side of threshold, but printf below reports them as binary
                // 0 and 1. So the meanings are opposite - to be fixed.
                unsigned int idx, min_lo=999999, min_hi=999999, max_lo = 0, max_hi = 0;
                unsigned int val;
                for(idx = 0; idx < count; idx++)
                {
                    // printf("RSSI 1 -> 0  %3d: %4dus ( %s )\n", idx, rssitime_buf[idx],
                    // rssitime_buf[idx] >= LOW_THRESHOLD ? "Hi" : "Lo");
                    val = rssitime_buf[idx];

                    // Short pulses are binary '1', long pulses are binary '0'
                    if(val < g_low_threshold)
                    {
                        if(val < min_lo)
                            min_lo = val;
                        if(val > max_lo)
                            max_lo = val;
                    }
                    else
                    {
                        if(val < min_hi)
                            min_hi = val;
                        if(val > max_hi)
                            max_hi = val;
                    }
                }

                printf("Pulse stats: Hi: %u - %u   Lo: %u - %u  (%d point)\n", min_lo, max_lo, min_hi, max_hi, count);

                // Recalculate the pulse threshold if we got a perfect read.
                if(count == 88 && crc_passed)
                {
                    //g_low_threshold = ( ((max_lo + min_lo) / 2) + ((max_hi + min_hi) / 2)) / 2;
                    g_low_threshold =(max_lo + min_hi) / 2;
                    printf("Threshold now %d\n", g_low_threshold);

                    // Note the time of the last reading...
                    unsigned int wait_start = TIMER_ARM_COUNT, elapsed;

                    // at this point, we can do other stuff that requires the RT scheduler

		    float temp = 21.0f;
		    float pressure = 1000.0f;
#ifdef USE_BMP085
			
                    read_bmp085(ALTITUDE_M, &temp, &pressure); // read pressure, calculate for the given altitude
#endif

                    calculate_values(bytes+1, temp, pressure);

                    // Wait for remainder of 47 seconds in standard scheduler until we can expect the next read
                    scheduler_standard();
		    // debug output mycounter
		    printf("mycounter debug %i\n",mycounter);
		    if (mycounter == 10){
			printf("BREAK\n");
			break;
		    }
                    do
                    {
                        elapsed = (TIMER_ARM_COUNT - wait_start) / 1000000;
                        printf("Wait %us \r", (48*LOGGING_INTERVAL) - elapsed);
			fflush(stdout);
                        usleep(250000);
                    }while(elapsed < (48*LOGGING_INTERVAL)- 5);
		    mycounter = mycounter++;
		    printf("mycounter ++ %i\n",mycounter);
                    printf("Listening for transmission\n");
                    scheduler_realtime();
                }
            }
            count = 0;


            // LED off
            *(gpio.addr + (0x28 >> 2)) = 1 << 22;
        }
        usleep(5); // No point running with nanosecond loops when pulses are in the hundreds of microseconds...
    }
//    while(1); // Ctrl+C to exit for now...
// change for timer
}

float sample_rssi(int fd, int duration, int interval) {

	unsigned int start_time, now;
	unsigned int loop_count = 0, rssi_total = 0;

	start_time = TIMER_ARM_COUNT;

	do {
		uint16_t status = send_command16(fd, cmd_status);
		int rssi = (status & STATUS_RSSI) ? 1 : 0;
		loop_count++;
		rssi_total+=rssi;
		now = TIMER_ARM_COUNT;
		usleep(interval);	// microseconds
	} while(now - start_time < (duration * 1000));	// duration as microseconds

	float duty = ((float)rssi_total/loop_count) * 100;

	return duty;
}

void initial_rfm (int argc) {
    init();
    //sendReset();
    setupChip();
    usleep(5000);	// Allow crystal oscillator to start

    uint16_t bw_scale[6] = {BW_67, BW_134, BW_200, BW_270, BW_340, BW_400};

struct RSSI rssi_scale[24] = {
	L0R73,L0R79,L0R85,L0R91,L0R97,L0R103,
	L6R73,L6R79,L6R85,L6R91,L6R97,L6R103,
	L14R73,L14R79,L14R85,L14R91,L14R97,L14R103,
	L20R73,L20R79,L20R85,L20R91,L20R97,L20R103,
};

    
	int idx1, idx2;
	for(idx1=0; idx1 < 24; idx1++) 
	{

		uint16_t cmd_rcon_mod = (cmd_rcon & ~(RSSI_X2|LNA_XX)) | (rssi_scale[idx1].rssi_setth |rssi_scale[idx1].g_lna);

		printf("%15s idx %-2d  ", rssi_scale[idx1].name, idx1);
		
		for(idx2=0; idx2 < 6; idx2++) {
		
			uint16_t cmd_config_mod = (cmd_config & ~BW_X2) | bw_scale[idx2];

			send_command16(fd, cmd_config_mod);
			send_command16(fd, cmd_rcon_mod);
			usleep(1000);
		
			rssi_scale[idx1].duty[idx2] = sample_rssi(fd, 50, 100);
			
			if(cmd_rcon_mod == cmd_rcon && cmd_config_mod == cmd_config)
				printf("%6.2f< ", rssi_scale[idx1].duty[idx2]);
			else
				printf("%6.2f  ", rssi_scale[idx1].duty[idx2]);
			fflush(stdout);
		}
		printf("\n");
	}
	send_command16(fd, cmd_config);
	send_command16(fd, cmd_rcon);
	usleep(1000);

	do {
		float duty = sample_rssi(fd, 250, 100);
		printf("RSSI Duty %0.2f\r", duty);
		fflush(stdout);
		usleep(250000);
	} while(argc > 1);
}


int main(int argc, char** argv)
{
    // init and main loop in extra while to reinital every 480 seconds (48*10)
    do {
       printf("starting initial_rfm\n");
       initial_rfm(argc);
       printf("starting main loop -go\n");
       main_loop();
       printf("uninit\n");
       uninit();
    } while(1); // Ctrl+C to exit

//    printf("uninit\n");
//    uninit();    
    return 0; 
}

FILE* create_or_open(void)
{
    time_t now;
    struct tm * timeinfo;
    now = time (NULL);
    time ( &now);
    timeinfo = localtime ( &now);

    char buffer[100];
    int written = sprintf(buffer, "mkdir -p %s", DATADIR);

    strftime(buffer+written, 100-written, "%Y/%Y-%m", timeinfo);
    system(buffer);

    written = sprintf(buffer, "%s", DATADIR);

    strftime(buffer+written, 100-written, "%Y/%Y-%m/%Y-%m-%d.txt", timeinfo);

    FILE* file = fopen(buffer, "a+");
    if(file != NULL)
    {
        strftime(buffer, 100, "%Y-%m-%d %H:%M:%S,", timeinfo);
        fprintf(file, "%s", buffer);
    }
    return file;
}


void calculate_dew_point(float temp, float humidity, float* dp)
{
  float a =  17.27;
  float b = 237.7;
  float gamma = ((a * temp)/(b+temp)) + log(humidity/100.0);
  if(a == gamma)
    *dp = 0;
  else
    *dp= (b*gamma)/(a-gamma);
}

void calculate_values(unsigned char *buf, float temp, float pressure) {

    unsigned short device_id = ((unsigned short)buf[0] << 4) | (buf[1] >> 4);
    unsigned short temperature_raw = (((unsigned short)buf[1] & 0x0f) << 8) | buf[2];
    float temperature = ((float)temperature_raw - 400) / 10;
    int humidity = buf[3];

    unsigned short wind_avg_raw = (unsigned short)buf[4];
    float wind_avg_ms = roundf((float)wind_avg_raw * 34.0f) / 100;
    float wind_avg_mph = wind_avg_ms * 2.23693629f;
    float wind_avg_kmh = wind_avg_ms * 3.6f;
    
    unsigned short wind_gust_raw = (unsigned short)buf[5];
    float wind_gust_ms = roundf((float)wind_gust_raw * 34.0f) / 100;
    float wind_gust_mph = wind_gust_ms * 2.23693629f;
    float wind_gust_kmh = wind_gust_ms * 3.6f;

    unsigned short rain_raw = (((unsigned short)buf[6] & 0x0f) << 8) | buf[7];

    float rain = (float)rain_raw * 0.3f;

    int direction = buf[8] & 0x0f;

    char *direction_str = direction_name[direction];

    float 

    dp = 0;
    calculate_dew_point(temperature, (float) humidity, &dp);	

    int x = 0;
    char buffer_string[128] = "";
    char* bfrptr = buffer_string;
    for(x = 0; x < 9; x++)
    {
        snprintf(bfrptr, 10, "0x%02x,", buf[x]);
        bfrptr += 5;
    }
    
    time_t rawtime;
    time ( &rawtime );
    
    struct tm* timeInfo;
    char timebuffer[128] = "";
    timeInfo = localtime(&rawtime);

    strftime(timebuffer, 128, "%Y-%m-%d %H:%M:%S", timeInfo);	

    printf("\nTime is: %s\n", timebuffer );
    
    printf("buffer string is %s\n", buffer_string);

    printf("Station Id: %04X\n", device_id);
    printf("Temperature: %0.1fC, Humidity: %d%%\n", temperature, humidity);
    printf("Wind speed: %0.1f mph, Gust Speed %0.1f mph, %s\n", wind_avg_mph, wind_gust_mph, direction_str);
    printf("Total rain: %0.1f mm\n", rain);
    printf("Drew point: %0.1fC\n", dp);

    FILE* file = create_or_open();
    if(file != NULL)
    {
        // delay in mins, hum in, temp_in, hum_out, temp_out, abs_pressure, wind_ave, wind_gust, wind_dir, rain,
        fprintf(file,"1,50,%0.1f,%d,%0.1f,%.1f,%0.1f,%0.1f,%d,%0.1f\n",
              temp, humidity, temperature, pressure, wind_avg_kmh, wind_gust_kmh, direction, rain);
        fclose(file);
    }

   char* sql = sqlite3_mprintf("INSERT INTO raw_data(timestamp,in_temp,out_temp,in_humidity,out_humidity,pressure,wind_avg_kmh,wind_gust_kmh,wind_direction,rainfall,bytes) values (%Q, %f,%f,%d,%d,%f,%f,%f,%d,%0.1f,%Q)",
                                 timebuffer, temp, temperature,50,humidity,pressure,wind_avg_kmh,wind_gust_kmh,direction,rain,buffer_string);
   char* zerrMsg = NULL;
   int  db_write = sqlite3_exec(db, sql, NULL, 0, &zerrMsg);
   sqlite3_free(sql);
   if(db_write != SQLITE_OK)
   {
       printf("SQL error: %s\n", zerrMsg);
       sqlite3_free(zerrMsg);
   }

   sql = sqlite3_mprintf("INSERT INTO derived_data(timestamp,dew_point) values(%Q, %f)", timebuffer, dp);
   zerrMsg = NULL;
   db_write = sqlite3_exec(db, sql, NULL, 0, &zerrMsg);
   sqlite3_free(sql);
   if(db_write != SQLITE_OK)
   {
       printf("SQL error: %s\n", zerrMsg);
       sqlite3_free(zerrMsg);
   }

}

/*
* Function taken from Luc Small (http://lucsmall.com), itself
* derived from the OneWire Arduino library. Modifications to
* the polynomial according to Fine Offset's CRC8 calulations.
*/
uint8_t _crc8( uint8_t *addr, uint8_t len)
{
    uint8_t crc = 0;

    // Indicated changes are from reference CRC-8 function in OneWire library
    while (len--)
    {
        uint8_t inbyte = *addr++;
        uint8_t i;
        for (i = 8; i; i--)
        {
            uint8_t mix = (crc ^ inbyte) & 0x80; // changed from & 0x01
            crc <<= 1; // changed from right shift
            if (mix)
                crc ^= 0x31;// changed from 0x8C;
            inbyte <<= 1; // changed from right shift
        }
    }
    return crc;
}

void scheduler_realtime() {

	printf ("[DEBUG] -- scheduler_realtime()");
    struct sched_param p;

    p.__sched_priority = sched_get_priority_max(SCHED_RR);

    if( sched_setscheduler( 0, SCHED_RR, &p ) == -1 )
    {
        perror("Failed to switch to realtime scheduler.");
    }
}

void scheduler_standard() {

    struct sched_param p;

    p.__sched_priority = 0;

    if( sched_setscheduler( 0, SCHED_OTHER, &p ) == -1 )
    {
        perror("Failed to switch to normal scheduler.");
    }
}

aideen
Posts: 17
Joined: Fri Jun 15, 2012 11:43 pm
Location: Cambridge, UK

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 26, 2013 8:53 am

If you're not using the bmp085 you need to undefine it's use in one of the header files.

tb63
Posts: 14
Joined: Mon Aug 06, 2012 2:40 pm

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 26, 2013 10:31 am

My PCE-FWS20 - 868 station is working fine now . Thanks to the work of Kevin Sangeelee and KarlS. Now my project Sint Wind PI ( a remote weather station with telephone answering capability, web data publish, webcams , cameras .... ) for Hang Gliding and Paragliding also support RFM01-WH1080.

With PCE-FWS20 I only found an initialization problem with the code of Kevin . His code was not working but after lunching the KarlS code it was working. So mixed up the 2 initializations and now it works. I also put all options in the command line so no need to recompile each time ( for example ) :

wh1080_rf -r 91 -l 0 -f 868 -b 134

code in :

http://www.vololiberomontecucco.it Use google translator :-)

Image

ksangeelee
Posts: 192
Joined: Sun Dec 25, 2011 5:25 pm
Location: Edinburgh, UK
Contact: Website

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 26, 2013 12:17 pm

tb63 wrote:With PCE-FWS20 I only found an initialization problem with the code of Kevin . His code was not working but after lunching the KarlS code it was working. So mixed up the 2 initializations and now it works.
Well hacked! Karl's unit, I think, generates a 915MHz FSK signal, whereas mine generates a 433MHz OOK signal. The configuration for each type of transmitter is quite different - it's impressive how many variants of these weather stations people have managed to get working.

basti122303
Posts: 35
Joined: Fri Jun 15, 2012 8:37 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 26, 2013 3:32 pm

tb63, thanks i found your code here: https://github.com/ToninoTarsi/swpi/

which "bcm2835.h" did you use to compile wh1080_rf?

I try this one included in http://www.susa.net/wordpress/2012/08/r ... nd-rfm12b/ -- i get compiler errors
I also try http://www.airspayce.com/mikem/bcm2835/index.html (version 1.25) with the same result.

basti122303
Posts: 35
Joined: Fri Jun 15, 2012 8:37 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Tue Mar 26, 2013 10:07 pm

I don't understand:
- with the code i post above i get data (source https://github.com/kenmcc/wh1080listener)
- with swpi code i get no data

Code: Select all

[email protected]:/home/develop/wh1080/wh1080listener.bak# ./weatherlogger 
starting initial_rfm
  LNA_0,RSSI_73 idx 0     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_79 idx 1     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_85 idx 2     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_91 idx 3     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_97 idx 4     0.00    0.00<   0.00    0.00    0.00    0.00  
 LNA_0,RSSI_103 idx 5     0.00    0.00    0.00    4.32   90.27  100.00  
  LNA_6,RSSI_73 idx 6     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_79 idx 7     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_85 idx 8     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_91 idx 9     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_97 idx 10    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_6,RSSI_103 idx 11    0.00    0.00    0.00    0.00   87.57  100.00  
 LNA_14,RSSI_73 idx 12    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_79 idx 13    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_85 idx 14    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_91 idx 15    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_97 idx 16    0.00    0.00    0.00    0.00    0.00    0.00  
LNA_14,RSSI_103 idx 17    0.00    0.00    0.00    0.00    1.63   95.11  
 LNA_20,RSSI_73 idx 18    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_79 idx 19    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_85 idx 20    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_91 idx 21    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_97 idx 22    0.00    0.00    0.00    0.00    0.00    0.00  
LNA_20,RSSI_103 idx 23    0.00    0.00    0.00    0.00    1.65   83.70  
starting main loop
Data bits = 88   (offset 0) (1 short)
Frequency deviation 5.0KHz (5)
ff a2 e2 75 1d 00 00 00 00 0e 38 crc ok (gap 0s)
Pulse stats: Hi: 681 - 785   Lo: 1677 - 1825  (88 point)
Threshold now 1231
Temperature: 20.9C
Pressure p0 (sea level): 999.4 hPa

Time is: 2013-03-26 22:29:27
buffer string is 0xa2,0xe2,0x75,0x1d,0x00,0x00,0x00,0x00,0x0e,
Station Id: 0A2E
Temperature: 22.9C, Humidity: 29%
Wind speed: 0.0 mph, Gust Speed 0.0 mph, NW
Total rain: 0.0 mm
Drew point: 3.9C
mycounter debug 0
mycounter++ 1
Listening for transmission
Data bits = 88   (offset 0) (1 short)
Frequency deviation 4.0KHz (4)
ff a2 e2 75 1d 00 00 00 00 0e 38 crc ok (gap 48s)
Pulse stats: Hi: 680 - 817   Lo: 1709 - 1809  (88 point)
Threshold now 1263
Temperature: 20.9C
Pressure p0 (sea level): 999.4 hPa

Time is: 2013-03-26 22:30:15
buffer string is 0xa2,0xe2,0x75,0x1d,0x00,0x00,0x00,0x00,0x0e,
Station Id: 0A2E
Temperature: 22.9C, Humidity: 29%
Wind speed: 0.0 mph, Gust Speed 0.0 mph, NW
Total rain: 0.0 mm
Drew point: 3.9C
^C
[email protected]:/home/develop/wh1080/wh1080listener.bak# 
[email protected]:/home/develop/swpi.orig/wh1080_rf# ./wh1080_rf 
frequenzy : 868 - bw : 134 - rssi : 97 - lna: 0
Initialising RFM01
SPI: mode 0, 8-bit, 1000 KHz
Ctrl+C to exit
  LNA_0,RSSI_73 idx 0     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_79 idx 1     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_85 idx 2     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_91 idx 3     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_0,RSSI_97 idx 4     0.00    0.00<   0.00    0.00    0.00    0.00  
 LNA_0,RSSI_103 idx 5     0.00    0.00   38.04  100.00  100.00  100.00  
  LNA_6,RSSI_73 idx 6     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_79 idx 7     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_85 idx 8     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_91 idx 9     0.00    0.00    0.00    0.00    0.00    0.00  
  LNA_6,RSSI_97 idx 10    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_6,RSSI_103 idx 11    0.00    0.00   45.65   94.62  100.00  100.00  
 LNA_14,RSSI_73 idx 12    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_79 idx 13    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_85 idx 14    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_91 idx 15    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_14,RSSI_97 idx 16    0.00    0.00    0.00    0.00    0.00    0.00  
LNA_14,RSSI_103 idx 17    0.00    0.00   21.51  100.00  100.00  100.00  
 LNA_20,RSSI_73 idx 18    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_79 idx 19    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_85 idx 20    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_91 idx 21    0.00    0.00    0.00    0.00    0.00    0.00  
 LNA_20,RSSI_97 idx 22    0.00    0.00    0.00    0.00    0.00    0.00  
LNA_20,RSSI_103 idx 23    0.00    0.00    7.45   98.92  100.00  100.00  

.
try to build get

Code: Select all

#include "bcm2835.h" // change <bcm2835.h> use from https://github.com/kenmcc/wh1080listener

Code: Select all

[email protected]:/home/develop/wh_test# make
gcc -c -Wall -std=gnu99 wh1080_rf.c
wh1080_rf.c:53:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
make: *** [wh1080_rf.o] Error 1
[email protected]:/home/develop/wh_test# 
[email protected]:/home/develop/wh1080/wh1080listener# 
[email protected]:/home/develop/wh_test# make clean
rm -f wh1080_rf.o bcm2835.o bmp085.o wh1080_rf spi_init.o spi_init
[email protected]:/home/develop/wh_test# make
gcc -c -Wall -std=gnu99 wh1080_rf.c
In file included from wh1080_rf.c:53:0:
bcm2835.h:77:8: error: redefinition of ‘struct bcm2835_peripheral’
rf_bcm2835.h:77:8: note: originally defined here
bcm2835.h:85:34: error: conflicting types for ‘gpio’
rf_bcm2835.h:85:34: note: previous declaration of ‘gpio’ was here
bcm2835.h:86:34: error: conflicting types for ‘bsc0’
rf_bcm2835.h:86:34: note: previous declaration of ‘bsc0’ was here
bcm2835.h:87:34: error: conflicting types for ‘timer_arm’
rf_bcm2835.h:87:34: note: previous declaration of ‘timer_arm’ was here
bcm2835.h:94:12: error: conflicting types for ‘map_peripheral’
rf_bcm2835.h:94:12: note: previous declaration of ‘map_peripheral’ was here
bcm2835.h:95:13: error: conflicting types for ‘unmap_peripheral’
rf_bcm2835.h:95:13: note: previous declaration of ‘unmap_peripheral’ was here
In file included from wh1080_rf.c:55:0:
rfm01.h:24:0: warning: "BAND_868" redefined [enabled by default]
wh1080_rf.h:40:0: note: this is the location of the previous definition
wh1080_rf.c: In function ‘spi_init’:
wh1080_rf.c:103:2: warning: implicit declaration of function ‘bcm2835_init’ [-Wimplicit-function-declaration]
wh1080_rf.c:104:2: warning: implicit declaration of function ‘bcm2835_spi_begin’ [-Wimplicit-function-declaration]
wh1080_rf.c:105:2: warning: implicit declaration of function ‘bcm2835_spi_setBitOrder’ [-Wimplicit-function-declaration]
wh1080_rf.c:105:26: error: ‘BCM2835_SPI_BIT_ORDER_MSBFIRST’ undeclared (first use in this function)
wh1080_rf.c:105:26: note: each undeclared identifier is reported only once for each function it appears in
wh1080_rf.c:106:2: warning: implicit declaration of function ‘bcm2835_spi_setDataMode’ [-Wimplicit-function-declaration]
wh1080_rf.c:106:26: error: ‘BCM2835_SPI_MODE0’ undeclared (first use in this function)
wh1080_rf.c:107:2: warning: implicit declaration of function ‘bcm2835_spi_setClockDivider’ [-Wimplicit-function-declaration]
wh1080_rf.c:107:30: error: ‘BCM2835_SPI_CLOCK_DIVIDER_32’ undeclared (first use in this function)
wh1080_rf.c:108:2: warning: implicit declaration of function ‘bcm2835_spi_chipSelect’ [-Wimplicit-function-declaration]
wh1080_rf.c:108:25: error: ‘BCM2835_SPI_CS0’ undeclared (first use in this function)
wh1080_rf.c:109:2: warning: implicit declaration of function ‘bcm2835_spi_setChipSelectPolarity’ [-Wimplicit-function-declaration]
wh1080_rf.c:111:2: warning: implicit declaration of function ‘bcm2835_gpio_fsel’ [-Wimplicit-function-declaration]
wh1080_rf.c:111:20: error: ‘RPI_V2_GPIO_P1_15’ undeclared (first use in this function)
wh1080_rf.c:111:31: error: ‘BCM2835_GPIO_FSEL_INPT’ undeclared (first use in this function)
wh1080_rf.c:112:2: warning: implicit declaration of function ‘bcm2835_gpio_set_pud’ [-Wimplicit-function-declaration]
wh1080_rf.c:112:34: error: ‘BCM2835_GPIO_PUD_UP’ undeclared (first use in this function)
wh1080_rf.c:114:20: error: ‘RPI_V2_GPIO_P1_13’ undeclared (first use in this function)
wh1080_rf.c: At top level:
wh1080_rf.c:284:13: warning: ‘rfm01_init_new’ defined but not used [-Wunused-function]
make: *** [wh1080_rf.o] Error 1
Is this code also for Raspberry Rev. 1 ?

basti122303
Posts: 35
Joined: Fri Jun 15, 2012 8:37 am

Re: Fine Offset WH1081 (Maplin N96GY) sensors working on Pi

Sat Mar 30, 2013 10:04 am

I the end I switch back tocode from susa side but there are also problems with the connection.
After 12 hours the pi get only:

Code: Select all

...Pulse stats: Hi: 143 - 988   Lo: 1005 - 1222  (42 point)
Pulse stats: Hi: 157 - 993   Lo: 1013 - 1238  (53 point)
Pulse stats: Hi: 294 - 997   Lo: 1010 - 1214  (51 point)
.Pulse stats: Hi: 112 - 978   Lo: 1003 - 1254  (59 point)
Pulse stats: Hi: 358 - 992   Lo: 1000 - 1249  (47 point)
.Pulse stats: Hi: 595 - 994   Lo: 1002 - 1283  (57 point)
Pulse stats: Hi: 111 - 987   Lo: 1002 - 1221  (59 point)
The Rain sensor is only a reed switch.
Did anybody know howto connect the 1-wire bus to raspberry?
Can I use this http://www.sheepwalkelectronics.co.uk/RPI1.shtml for the 2 wind sensors?

Return to “Automation, sensing and robotics”