Can i grab loop data in a shell script

Skip to first unread message

Robin

unread,
Jul 31, 2019, 8:18:28 AM7/31/19
to weewx-user
Is it possible to get the current temperature to use in a shell script?

Let me explain what I am doing and what I would like to do.

I have a webcam. I use a shell script every five minutes to: 
  1. grab an image with avconv
  2. add text, including 'current' temperature (from a txt file generated using cheetah generator) and the time.
  3. save the image so that rsync uploads it to my website with the other files.
You can see the result here 

My problem is the txt file is 5 minutes old. There is normally small or no difference between 'current' and 5-minute old data. BUT, there are times when the difference is significant and I would like to "do better"!

I really am not good at this stuff, I meddle and poke until I get things sorted or I break something, normally the latter. So I was hoping that somebody could advise me.

Can I use in my script to get loop data so the temperature will be correct at the time of the grab?

Thanks, people.

gjr80

unread,
Jul 31, 2019, 10:09:30 AM7/31/19
to weewx-user
Robin,

There is no practical way for your shell script to access loop data directly, best solution I can think of is to write a custom service bound to the NEW_LOOP_PACKET event that writes the required data to a text file that you then read as you currently do. The service will be very basic, but unlike a template (which uses the cheetah template engine to do the hard work) your service will need to write the data to a file itself. Fairly straightforward, any of the loop based services that write data to a file (eg crt - https://github.com/weewx/weewx/wiki/crt) have all the building blocks you need, they are just a bit more complex.

Gary

Robin

unread,
Jul 31, 2019, 11:53:26 AM7/31/19
to weewx-user
Gary,

Thank you for pointing me in the right direction. 

It's time to "meddle and poke until I get things sorted or break something"!

RobbH

unread,
Jul 31, 2019, 12:00:54 PM7/31/19
to weewx-user
You might take a look at the crt service: https://github.com/weewx/weewx/wiki/crt

This writes a text file, realtime.txt every time new loop data is received. The current outside temperature is always the third field in the file. However, many loop packets may not include temperature data, in which case that field contains "NULL". So your script would have to monitor that file continuously and assign the current temperature to a variable every time it updates.

Alternately, if your archive cycle is five minutes and you're saving a webcam image every five minutes, couldn't you set it up so that your script runs one minute after weewx updates?

Robin

unread,
Jul 31, 2019, 3:16:03 PM7/31/19
to weewx-user
I did think about running the script after weewx updates, but the ease of saving the image to the web page folder so it gets uploaded using rsync was too appealing.

I am not a programmer and my Linux knowledge is at the 'just enough to survive' (most of the time) level.

I have had a look at the wiki and now realise that this is way beyond my current skill level.

Thank you, Gary and RobbH for your tips. I have a lot of learning to do before I can take this on.


Pat

unread,
Aug 1, 2019, 8:31:27 AM8/1/19
to weewx-user
Robin, 

Some questions


> from a txt file generated using cheetah generator

Where is this file located? What text is inside this file? Is it just the temperature or is it a full sentence?

RobbH

unread,
Aug 1, 2019, 9:17:03 PM8/1/19
to weewx-user
Robin, I just wanted to add that I can't speak for anyone else, but I know that I, also, have a lot of learning to do every time I start a project. This has been a great help to me when I'm working on Bash shell scripts:



On Wednesday, July 31, 2019 at 3:16:03 PM UTC-4, Robin wrote:

Robin

unread,
Aug 2, 2019, 1:24:21 AM8/2/19
to weewx-user
Good morning Pat,

Location /var/www/weewx/temperature.txt

The template for Cheetah generator to produce the file has a single line 

$current.outTemp.string

That's it.

Greg from Oz

unread,
Aug 2, 2019, 3:39:18 AM8/2/19
to weewx-user
Good camera. What make model etc is it?
My camera goes offline a lot but does the job.

Robin

unread,
Aug 2, 2019, 8:17:55 AM8/2/19
to weewx-user
Hi Greg,

The camera is unbranded 720p resolution, from China. It cost €4.99 three years ago. My camera also goes offline, typically about once a day. I bought a relay and written a routine to switch the relay off/pause/on to reset the camera.

I now invested in another Chinese camera this time 1080p. This time I'm splashing out €19. Last of the big spenders or what!!! I now need a cool day to install it.

Pat

unread,
Aug 2, 2019, 9:03:49 PM8/2/19
to weewx-user
Hi Robin, 

Try this attached file out. I took the CRT extension that everyone mentioned and just made it so that only outTemp is written to the file. 

If your LOOP is like mine, it doesn't always have outTemp, so I added the Cache system found in some other weewx extensions. This way once your LOOP provides outTemp, it'll save that to the cache and write to file. If your LOOP does not have outTemp, then the cached value will be written to the file. This way your file always has the outTemp value and not NULL. 

This install is a complete fork with renamed files and functions so it should not interfere with CRT if installed. (Hopefully)

How to install:

1. Have a backup in case something goes wrong. 

3. Download the attachment in this thread to your weewx machine and run wee_extension --install weewx-crt-0.18_outTemp_only.tgz

4. Edit your weewx.conf's new CumulusRealTime_outTemp section. I used the below in my testing:

[CumulusRealTime_outTemp]
    filename
= /var/www/weewx/temperature.txt
    temperature_units
= degree_F

4. Don't forget to disable your skin Cheetah Generator so that doesn't write old outTemp

5. Restart weewx and see if it works out for you. 

Hope this helps. 
weewx-crt-0.18_outTemp_only.tgz
Reply all
Reply to author
Forward
0 new messages