weewx-wd has a lot of overhead for what you're trying to do.
you could use a csv service to emit loop data on every sensor reading, then have another process that monitors that file to display on lcd or web page or whatever. emit the data as csv or json or whatever format works best for the javascript side of things.
[...]
How about an option to change it from appending to re-writing? Maybe an "append = true"?
def write_data(self, data):
# if self.header and not os.path.exists(self.filename):
# self.write_line(self.sort_keys(data))
# self.write_line(self.sort_data(data))
flag = "a" if self.mode == 'append' else "w"
with open(self.filename, flag) as f:
if self.header and not os.path.exists(self.filename) or flag == "w":
f.write('%s\n' % ','.join(self.sort_keys(data)))
f.write('%s\n' % ','.join(self.sort_data(data)))
# def write_line(self, fields):
# flag = "a" if self.mode == 'append' else "w"
# with open(self.filename, flag) as f:
# f.write('%s\n' % ','.join(fields))
I decided to try a different approach. Rather than write the loop data to a file, I'm now using IPC. I've got an extension running that tries to connect to a local process, then it sends the data packet. One advantage is that the data does not go thru a string conversion. Also, watching the display updating, you can see it's updating more frequently. The process that updates the LCD display is running as a Server, with the weewx extension running as a Client.
Kill the local process your extension connects to and see if weewx aborts. I know I messed my extension up quite a few times before getting the right try/except logic in it to handle the possible cases.
def send_data(self, data):
try:
conn = Client(self.address, authkey=self.key)
conn.send(data)
conn.close()
except Exception, e:
# no logging - too many log entries!
# syslog.syslog(syslog.LOG_ERR, "wxdata: send error. %s" % e)
# conn.close()
It dawned on me today that the coolest thing about using IPC to communicate between weewx and my graphic display is that they no longer have to be on the same machine. I moved weewx back to the Beagle Bone Black that it was running on before I started this effort. The Pi with the touch screen display can be anywhere I want it to be as long as it has a network connection.
a weewx service that publishes all of the LOOP data via socket/http is pretty powerful. that would let you make the weather data from *any* type of hardware available to any number of clients, concurrently. the trick is to design a schema/protocol (or use an existing one, if such exists?) that has legs.
m
What I am thinking of doing is turning this around, with a Server running on the weewx side. The only way I can think of to do this is to use two IPC's (InterProcess Connection). The present weewx extension would receive the LOOP packet and send it to another process on the same machine. That process would open up two server connections - one to receive the data from weewx, and a second to listen for data requests. When it got a request it would send back the latest LOOP packet. Anyone with the correct ip address, port number, and authentication key could request data from this server. I have to do some testing to see if I can work out how to handle running two server processes; I'm thinking they need to be separate threads.
Is there another way to obtain the current LOOP packet or does this make sense?
you could run a weewx service that spawns a thread on startup and registers itself for NEW_LOOP_PACKET events. each time the service gets a new loop packet, it simply sets a 'current data' member of the thread to be a copy of the loop packet. the thread simply listens for requests (on a socket, via http, whatever). if you want to handle multiple clients, then have the thread spawn a separate thread to handle each request.
[WXDATA]
binding = loop
address = hhhhhhhh.local # default is "localhost"
port = 6000
key = "wxdata key"