magellannh / rtl-wx

RTL-Wx logs data from 433Mhz wireless sensors using an RTL-SDR dongle. The Wiki has some screenshots of the results
GNU General Public License v2.0
21 stars 7 forks source link

Oregon THN132N integration #2

Open deennoo opened 10 years ago

deennoo commented 10 years ago

Hello,

I made my own THN132N copy with an arduino and a ds18b20

As RTL-433 last release can reconize Oregon THN132N, is this possible to include it on RTL-WX ?

I try to do it my self but i have to say that i'm really not a programmer...

deennoo commented 10 years ago

I answer a bit myself

I put thn132n on rtl-433fm-decode.c

And when ./rtl-wx i can see my sensor information but nothing happen on the server.

I don't know on which part on rlt-wx.c i have to put thn132n information

Please can you help ?

magellannh commented 10 years ago

Sorry for the delay in responding to this. I don't have a system to use to help you debug this right now, but I can try to explain how it works. I assume you're using the latest rtl-wx. If not, I'd suggest starting from there.

In that case, to add a sensor you may need to add some code for the new sensor in both rtl-433fm-decode.c and in rtl-wx.c.

When rtl-433fm-decode.c gets a message from a sensor, the message is validated and then sent to rtl-wx.c using a callback function.

In rtl-433fm-decode.c, the callback is done with code that looks like this: if (os_msg_ok_callback != NULL) { os_msg_ok_callback(msg, (num_valid_v2_bits+7)>>3, sensor_id); return 1; }

The os_msg_ok_callback() routine is set at initialization to point to a function in rtl-wx.c called WX_process_os_msg_ok(). So if you add a new sensor, you'll want to make sure the code for the new sensor in rtl-433fm-decode.c calls os_msg_callback() as in the code above.

Then, you need to make sure that WX_process_os_msg_ok() knows how to decode the new sensor type.

I think in the THN132 message is formatted the same as other OS multi-channel temperature/humidity sensors. So in rtl-wx.c, the THN132 can probably be treated as another EXT sensor. It may be as easy as tricking the rtl-wx.x code by hardcoding the sensor ID to 0x1d20 in rtl-433fm-decode.c before calling the os_msg_ok_callback() for THN132 messages. Then it will look to rtl-wx.c like an already known sensor type and no code changes would be needed.

If the THN132's msg format isn't the same as the 0x1d20 sensor, you might have to add the THN132's sensor type to this if statement in WX_process_os_msg_ok() and then adjust the code in any places needed to handle the differences in messages for this new sensor.

In this case, you'd change: if ((sensor_id == 0x1d20) || (sensor_id == 0xf824)) { To if ((sensor_id == 0x1d20) || (sensor_id == 0xf824) || (sensor_id==0x????)) { /* replace ???? with sensor ID for THN132N */

Then make any other changes in that "if" code block to get the code to handle the new sensor type correctly.

Hope that helps. If you get it working against the latest code and do a pull request, I'll be happy to merge it back in.

deennoo commented 10 years ago

Thank you for your comment

Of Course i use your last version on my PI (some bug are present and i was need to correct some <<<<<<< and === on rtl.wx, because gcc give some error)

THN132N use oregon 2.1 protocol with 129 bit this is just en temp sensor without humidity

my competences on programming are real null, for the moment i just copy and past some code part from rtl_433 to your files, and use gcc error to learn where are the fault (sometime some } or{ missing)

As i can see for now my THN132n code part doesn't got os_msg_ok_callback() lines. :+1:

} else if (sensor_id == 0xec40 && num_valid_v2_bits==129) { if ( validate_os_v2_message(msg, 129, num_valid_v2_bits, 12) == 0) { int channel = ((msg[2] >> 4)&0x0f); if (channel == 4) channel = 3; // sensor 3 channel number is 0x04 int battery_low = (msg[3] >> 2 & 0x01);
unsigned char rolling_code = ((msg[2] << 4)&0xF0) | ((msg[3] >> 4)&0x0F); float temp_c = get_os_temperature(msg, sensor_id); if (sensor_id == 0xec40) fprintf(stderr, "Thermo Sensor THN132N, Channel %d, Battery: %s, Rolling-code 0x%0X, ", channel, battery_low?"Low":"Ok", rolling_code); fprintf(stderr, "Temp: %3.1f°C %3.1f°F\n", temp_c, ((temp_c*9)/5)+32); } return 1;

I'll try to add them

One more question : does your code can allow do add other sensor who are not Oregon's one ? (of course with some work to do this)

I just have a look to my version of rtl-wx.c i got yesterday and i can find this line //if ((sensor_id == 0x1d20) || (sensor_id == 0x1d30) || (sensor_id == 0x5d60) || (sensor_id == 0xf824))

as you can see it's look none active because // is in front of this, please can you confirm ,

magellannh commented 10 years ago

I'm not sure where your copy of rtl-wx.c came from, but that if shouldn't have a // in front of it.

The latest source is here: https://github.com/magellannh/rtl-wx/blob/master/src/rtl-wx.c

The 'if' statement is at line 593.

After I first posted rtl-wx on github, I did a very big rework of the code and unfortunately this was after the code got forked a couple of times. Now my repo is very different from some of the forks and it would be hard to manually merge everything back into one.

magellannh commented 10 years ago

Adding non-oregon sensors should be relatively easy to do. You can either add a new callback routine for the new sensor type or you could fake out the current os_msg_ok_callback() by building a message array from the data from the other (new) sensor that looks exactly like a message from a known Oregon sensor type. Either way would work fine.

The main rtl-wx code is set up to handle one outdoor sensor, one indoor sensor, and I think up to 10 extra sensors. There's a way in rtl-wx.conf to rename the sensors so you can call them anything you like.

Also, when using the highcharts web stuff, you can rewrite web page code to include only the sensors you want and you can call them any names you like (eg outdoor, study, bedroom, etc).

This html file has an example of this: https://github.com/magellannh/rtl-wx/blob/master/www/rtl-wx.htm

And it produces a web page like this: https://github.com/magellannh/rtl-wx/blob/master/doc/screenshots/monitoring-webpage-1.PNG

This one is more complicated than you want, because it uses 6 Oregon temp/hum sensors plus an Efergy electricity sensor (on electric main) plus an Owl electricity sensor on the oil burner circuit to monitor fuel consumption. But you can use it as an example at least.

deennoo commented 10 years ago

Hello Magellannh.

Remembering that i'm working with an home made THN132N (arduino and ds18b20) (no humidty sensor, i put the value i want on it, for hum, channel and Product ID)

I got some good result, just by adding some line about THN132N (already use on rtl_433) on your last rtl_433fm-decode.c. (I will try to put a request when the last problem will be solve).

RTL-wx show the good information @ the good time

The only bad point is the channel :

RTL-WX always showing Channel 3, even if I put Channel 1 on my sensor. ID is well decode (remeber that i can put the product ID i want on my sensor)

I know :

channel 1 = 0x10 channel 2 = 0x20 channel 3 = 0x40

How can i correct this ?

magellannh commented 10 years ago

Here's the code from rtl-wx.c for the channel decode:

if ((sensor_id == 0x1d20) || (sensor_id == 0xf824)) { int channel = ((msg[2] >> 4)&0x0f); if ((channel >= 4) && (sensor_id == 0x1d20)) channel = 3; else if (channel > (MAX_SENSOR_CHANNEL_INDEX+1)) channel = MAX_SENSOR_CHANNEL_INDEX+1; else if (channel < 1) channel = 1;

What's sensor type value are you using? Did you set it to either 0x1d20 or 0xf824? If not, it looks like the channel variable won't get initialized.

If you run the app in standalone mode and select option 't' to toggle raw message data output, what do the messages look like?

deennoo commented 9 years ago

i'm working on it, i just get a succes by optimise my thn132n copy who now work with 2 * 1.5v aa battery (work on 5v by the past).

the message i got is this one : RTL-433FM OS Msg: ec 40 1a a0 14 10 93 00 00 00 00 00 00 00 00 00 00 00 00 00

Humidity is false because thn132n does have humd sensor, temp is the real one.