The previous part of this project is here <link>
Yes, another post on this device. Even with this one, I'm not done; there will be others since I want to sample the RF from the sensor at some point and also bring up a separate little computer for just the weather station. But I was extremely lucky and one of my readers double checked my work and found a couple of mistakes.
Thanks go to Heath Paddock <link>; he double checked the wind speed and direction and found mistakes, then gave me code to correct my mistakes. Thank you Heath. Due to a couple of factors completely within my control I misread the wind direction conversion. He noticed it when he was testing the device and dropped me a line. Then he double checked the wind speed and noticed a mistake there as well.
I was getting the bits correctly, but the conversion was off; let's look at the wind direction first. The correct table for this sensor to convert from a number to direction looks like this:
Every single value is different; when I mess up, I do it in style. When he sent me the code, I climbed up on the roof and brought down the station to check and see what is happening. Yep, North was a six coming out of the USB port in report R1. I went through each of the other directions and they matched his numbers exactly, then I looked at my console and it was wrong. That just didn't make sense at all, so like all good computer users, I reset the darn thing. It was still wrong. I finally unplugged the console from the USB port on the Pi, pulled the batteries out of the console, and just to be complete, pulled the batteries out of the weather head. This is a sure sign of desperation, when you do something that you know won't help just because you can't think of anything else.
But that did it. A value of six (the pointer on the weather station was taped in place by now) corresponded to a N reading on the console. I have no explanation for what was going on, but it works fine now. No, I'm not going to try and recreate the situation. I'm quite happy with the way it works and will double check the readings each time I have to change batteries in either the console or the weather head.
At any rate, the wind direction seems to be working really well now. Next is the wind speed; Heath noticed an odd reading and asked me about it. I had seen the reading the day before I left for Christmas, so I knew what he was talking about, but I didn't have time to look into it. He took the time to examine the data he was receiving and found the solution. The wind speed sensor is granular to .5 MPH; yes MPH, not KPH, and is reported back doubled. The console does the usual 8 bit math and puts up a reading that is slightly off and loses the .5 granularity. It also does some degree of smoothing and only reports the speed at intervals so you have to be somewhat patient to see what's going on. Here's the code I'm currently using:
Yes, another post on this device. Even with this one, I'm not done; there will be others since I want to sample the RF from the sensor at some point and also bring up a separate little computer for just the weather station. But I was extremely lucky and one of my readers double checked my work and found a couple of mistakes.
Thanks go to Heath Paddock <link>; he double checked the wind speed and direction and found mistakes, then gave me code to correct my mistakes. Thank you Heath. Due to a couple of factors completely within my control I misread the wind direction conversion. He noticed it when he was testing the device and dropped me a line. Then he double checked the wind speed and noticed a mistake there as well.
I was getting the bits correctly, but the conversion was off; let's look at the wind direction first. The correct table for this sensor to convert from a number to direction looks like this:
// Array to translate the integer direction provided to text
char *Direction[] = {
"NW", // 0
"WSW", // 1
"WNW", // 2
"W", // 3
"NNW", // 4
"SW", // 5
"N", // 6
"SSW", // 7
"ENE", // 8
"SE", // 9
"E", // 10
"ESE", // 11
"NE", // 12
"SSE", // 13
"NNE", // 14
"S" };
But that did it. A value of six (the pointer on the weather station was taped in place by now) corresponded to a N reading on the console. I have no explanation for what was going on, but it works fine now. No, I'm not going to try and recreate the situation. I'm quite happy with the way it works and will double check the readings each time I have to change batteries in either the console or the weather head.
At any rate, the wind direction seems to be working really well now. Next is the wind speed; Heath noticed an odd reading and asked me about it. I had seen the reading the day before I left for Christmas, so I knew what he was talking about, but I didn't have time to look into it. He took the time to examine the data he was receiving and found the solution. The wind speed sensor is granular to .5 MPH; yes MPH, not KPH, and is reported back doubled. The console does the usual 8 bit math and puts up a reading that is slightly off and loses the .5 granularity. It also does some degree of smoothing and only reports the speed at intervals so you have to be somewhat patient to see what's going on. Here's the code I'm currently using:
int getWindSpeed(char *data){
int leftSide = (data[3] & 0x1f) << 3;
int rightSide = (data[4] & 0x70) >> 4;
float speed = (leftSide | rightSide) / 2.0;
return(speed);
}
Notice that I'm using a float to preserve the .5 granularity? I did that to get the most out of my sensor and because it looks cool on my web display. It won't match the console exactly, but that isn't really my goal.
There will probably be something else some clever person turns up that I missed or interpreted wrong, but that's part and parcel of hacking into a device with little or no information up front. The point is that multiple people have participated in this project over many miles of separation, and we all get to use it. I'll have the code updated in Github in an hour or so as well.
Now I have to climb back up on the roof and put it in place. There's a storm coming and I don't want to miss it.