Comments (15)
create a weewx service that gets the pressure (from a sensor or from a file or from a web page or whatever) and adds that value to the loop or record (depending on the service binding).
https://github.com/weewx/weewx/wiki/add-sensor
from weewx-sdr.
from weewx-sdr.
The data I want shows up about once every 10 minutes, so the service code would just be “spinning” waiting for that to happen. Is that going to cause issues with the rest of weewx? And, when I find the data and post it, should I just keep reading, or stop and restart.
a data collection service can be bound to each NEW_LOOP_PACKET event or to each NEW_ARCHIVE_RECORD event. in your case, go with the latter. so on each archive record your service would be invoked. no 'spinning' involved. just make sure that whatever you do to get the barometric data does not block for a very long time.
from weewx-sdr.
from weewx-sdr.
OK – it’ll basically block for 10 minutes or more.
you don't want to block in a service - it can screw up the rest of the weewx data processing.
put the socket read in a thread. the thread just opens a socket and waits for data. when it times out, it checks to see if the thread should still run, then tries to connect again. when it receives data, it puts data into a common variable.
then the NEW_ARCHIVE_RECORD callback (running in the main thread) just reads whatever is in the variable. (if you want to distinguish the age of the data, then use a queue instead of a dict)
from weewx-sdr.
from weewx-sdr.
threading is really easy in python. take a look at this driver for an example:
https://github.com/matthewwall/weewx-ws3000
from weewx-sdr.
from weewx-sdr.
something like this (the socket logic could be streamlined, but this should convey the idea):
import socket
import time
import weewx
from weewx.engine import StdService
class PressureService(StdService):
def __init__(self, engine, config_dict):
super(PressureService, self).__init__(engine, config_dict)
d = config_dict.get('PressureService', {})
self.server_name = d.get('server', 'localhost')
# the thread will set this each time it reads a new value.
# the service will read this each archive interval.
self.pressure = None
# start the thread that captures the pressure value
self._thread = PressureThread(self, self.server_name)
self._thread.start()
# bind this service to happen with each new archive record
self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
def shutDown(self):
# when the service shuts down, tell the thread to die and wait for it
if self._thread:
self._thread.running = False
self._thread.join()
self._thread = None
def new_archive_record(self, event):
# add the pressure value to the record. this assumes that
# the pressure is in units appropriate to the record's unit system.
event.record['barometer'] = self.pressure
class PressureThread(threading.Thread):
def __init__(self, service, server_name):
threading.Thread.__init__(self)
self.service = service
self.server_name = server_name
self.running = False
def run(self):
self.running = True
while self.running:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = (self.server_name, 2023)
sock.connect(server)
while self.running:
data = sock.recv(1024)
if data and data.find("N7QNM-10") != -1:
idx = data.find("b")
if idx >= 0:
p = float(data[idx+1:idx+6]) * 0.002953
service.pressure = p
except socket.error:
pass
time.sleep(1)
from weewx-sdr.
from weewx-sdr.
from weewx-sdr.
Is that correct? So, given that, I could put the callsign (N7QNM-10) and the port (2023) in parameters as well, correct?
right-o!
self.server_name = d.get('server', 'localhost')
self.port = int(d.get('port', 2023))
self.callsign = d.get('callsign', 'N7QNM-10')
d is a python dict, extracted from config_dict, which is a dict created from weewx.conf.
the keys of d are case-sensitive.
from weewx-sdr.
from weewx-sdr.
what does the log say?
that code won't run - you'll get an exception in the pressure thread as soon as you hit the service.pressure = p
line. try self.service.pressure = p
instead.
please continue this discussion by posting at the weewx dev forum:
http://groups.google.com/group/weewx-development
from weewx-sdr.
from weewx-sdr.
Related Issues (20)
- Parser for Kedsum temperature humidity sensor HOT 8
- Parser for Esperanza-EWS temperature humidity sensor
- Fine Offset WH1080 not parsing battery status correctly HOT 2
- Stopped receiving data from WHx080 HOT 1
- Rain totals not right HOT 3
- new insertion in sensor map HOT 19
- Fineoffset-WH32 HOT 1
- Multiple radios into single Weewx instance? HOT 2
- ecowitt wh41 HOT 5
- WS68 Support HOT 4
- problems with configuration on Dietpi
- WH3085 HOT 1
- new driver based on weewx-sdr for adafruit indoor sensor on usb. uses rtl-sdr rtl_433 for external
- DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead
- (Please) Add new Rubicson-Temperature device
- stuck on step 4 HOT 2
- WS90 Support HOT 2
- Incorrect delta for lightning strike
- unknown model Bresser-7in1 HOT 8
- Acurite Atlas lightning data not getting parsed? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from weewx-sdr.