Skip to content

Commit

Permalink
Hopping hack to sit on Freq1 for time and hop on success for Freq2
Browse files Browse the repository at this point in the history
  • Loading branch information
loopy321 committed Oct 21, 2021
1 parent 1026edf commit 390b5c1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rtl_433.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void usage(int exit_code)
" [-C native | si | customary] Convert units in decoded output.\n"
" [-n <value>] Specify number of samples to take (each sample is an I/Q pair)\n"
" [-T <seconds>] Specify number of seconds to run, also 12:34 or 1h23m45s\n"
" [-E hop | quit] Hop/Quit after outputting successful event(s)\n"
" [-E hop | quit | hop2] Hop/Quit after outputting successful event(s) (hop2=only hop on success for 2nd freq)\n"
" [-h] Output this usage help and exit\n"
" Use -d, -g, -R, -X, -F, -M, -r, -w, or -W without argument for more help\n\n",
DEFAULT_FREQUENCY, DEFAULT_HOP_TIME, DEFAULT_SAMPLE_RATE);
Expand Down Expand Up @@ -649,6 +649,9 @@ static void sdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx)
if (cfg->after_successful_events_flag == 1) {
cfg->exit_async = 1;
}
else if ((cfg->after_successful_events_flag == 3) && (cfg->frequency_index == 0)) { // do not hop on success if first frequency_index
cfg->hop_now = 0;
}
else {
cfg->hop_now = 1;
}
Expand Down Expand Up @@ -1185,6 +1188,9 @@ static void parse_conf_option(r_cfg_t *cfg, int opt, char *arg)
else if (arg && !strcmp(arg, "quit")) {
cfg->after_successful_events_flag = 1;
}
else if (arg && !strcmp(arg, "hop2")) {
cfg->after_successful_events_flag = 3;
}
else {
cfg->after_successful_events_flag = atobv(arg, 1);
}
Expand Down

5 comments on commit 390b5c1

@Ian-Zz
Copy link

@Ian-Zz Ian-Zz commented on 390b5c1 Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Howdy, First thanks a bunch for sharing this code. I think it's just what I need to help with my rtl readings (skipped hours in Home Assistant now and again).

I maybe wrong but it looks like this same code is now in the master rtl_433 repo. Which would be very cool.

Not cool is that I have no clue how to "flip" this codes switch in my HA ryl_433 add on's rtl_conf.template file. As of now mine looks like that... Can you give me a clue please what I could add to this file in HA to get that custom hop feature working. Thanks again.

output  mqtt://my.secret.ip.bla:1883,user=user,pass=pw,retain=1
frequency   912.60M 
frequency   433.92M
protocol 8
protocol 149
protocol 154
hop_interval  800
report_meta newmodel
convert si

@loopy321
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this branch, the following command works for me:

rtl_433 -f 433920000 -f 912600155 -H 130 -E hop2 -F "mqtt://192.168.1.100:1883,user=USER,pass=PASS,retain=0,devices=rtl_433[/model][/subtype][/id][/channel]"

Where the hop2=only hop on success for 2nd freq keeps reading on 433M for the full 130s, then hops to 912M for 130s or until successful reading.
Then, in Homeassistant, in configuration.yaml I have:

sensor:
  - platform: mqtt
    state_topic: "rtl_433/ERT-SCM/40066/consumption_data"  
    name: "Gas Meter"
    unit_of_measurement: CCF
    value_template: "{{ (value | float)/100 }}"
    device_class: gas
    state_class: total_increasing
    expire_after: 3600 # unavailable after 60min
    force_update: true
    icon: mdi:fire

Obviously need to adjust state_topic to your model/subtype/channel to your readings.

@Ian-Zz
Copy link

@Ian-Zz Ian-Zz commented on 390b5c1 Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch for that Bob. I ended up using/testing this repo on a Pi3 (not my Pi4 HA OS yet) and it works perfectly. Zero skipped hours now on my electric meter readings. It's just what I needed.

Now I'm still trying to get this repo and it's hop2 arguments to work within my own local hosted rtl_433-hass-addon.

@Spazholio
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off - THANK YOU. I found this from the original repo and it's EXACTLY what I was looking for. Well...almost. I actually have 3 frequencies that I want to cycle through instead of just 2:

  • 915M - listen for 2 minutes but as soon as it hears from my meter, hop
  • 315M - listen for 4 minutes for all my tires because why not, don't hop
  • 433.92M - listen for an hour, don't hop

I'm envisioning the command looking something like: ./rtl_433 -f 915M -H 120 -E hop2 -f 315M -H 240 -f 433.92M -H 3600.

Is that something that might be possible at some point, or should I bug @zuckschwerdt about this because it's going to take some refactoring?

@loopy321
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Spazholio you could easily invert the logic for frequency_index and change line 652 above to something like:

else if ((cfg->after_successful_events_flag == 3) && (cfg->frequency_index != 0)) { // hop on success for ONLY the first frequency

Then I think your command would be just as you envisioned.

Please sign in to comment.