Hey community,

I have a fleet of Davis weather stations connected to as many RaspberryPis, 
on which I am running the vantage drivers as a standalone program on docker 
container, deployed using Balena <https://www.balena.io/open/>.
I'd like my program to send data every minute to a REST API and I've been 
looking into some way to get archive data from a in loop, but I'm not sure 
I'm doing it the right way.

What I did was defining in the driver's main method something like:

*while True:*
* since_ts = datetime.datetime.timestamp(datetime.datetime.now() - 
datetime.timedelta(minutes=1))*
* for packet in vantage.genDavisArchiveRecords(since_ts):*
* try:*
* new_packet = weewx.units.to_METRICWX(packet)*
* davispusher.send_message(payload=new_packet)*
* log.debug(davispusher.payload)*
* except Exception as e:*
* log.debug("Found an exception: %s" % e)*
* time.sleep(1.2)*
* continue*
* time.sleep(60)*

Where davispusher is an instance of a simple class that is needed to add 
some values to the archive record and send the message and is defined as:
*class DavisPusher:*
* def __init__(self, host='https://mywebsite.somewhere, port=8080, 
endpoint='davis'):*
* self._endpoint = "{host}:{port}/{endpoint}".format(host=host, *
* endpoint=endpoint,*
* port=port)*
* self.payload = {}*

* def format_message(self,*
* payload: dict,*
* sensor_id: str = environ['SENSOR_ID'],*
* latitude: str = environ['LATITUDE'],*
* longitude: str = environ['LONGITUDE'],*
* altitude: str = environ['ALTITUDE'],*
* ) -> dict:*
* """Formats message for backend."""*

* payload_copy = payload.copy()*
* try:*
* self.payload = payload_copy*
* self.payload['sensor_id'] = sensor_id*
* self.payload['altitude'] = float(altitude)*
* self.payload['longitude'] = float(longitude)*
* self.payload['latitude'] = float(latitude)*

* except Exception:*
* self.payload = {}*
* def send_message(self, payload):*
* '''formats and sends message to backend'''*
* self.format_message(payload)*
* resp = requests.post(self._endpoint, data = json.dumps(self.payload), 
allow_redirects = True)*
* log.debug("got HTTP statuscode %s", resp.status_code)*

However, my logs are full of logging errors ("Bad file descriptor", "File 
"/usr/local/lib/python3.8/logging/handlers.py" No such file or directory")
I guess those are errors due to logging configuration, but I'm not sure how 
to address them. I created a GitHub Gist 
<https://gist.github.com/saveriogzz/c624c03e63a3be3d66daf57b25337b7e> in 
order not to pollute this post!

Also, what I would like to achieve is the possibility to configure the 
various consoles (set time, set coordinates) at startup using environment 
variables. How could I do this using the VantageConfigurator class?

Thanks a lot in advance for your help, I'm kind of alone in my work and I'd 
really appreciate your help.

Friendly greetings,
Saverio

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/e74ee3d4-774d-4314-bb4d-a6052d35c66en%40googlegroups.com.

Reply via email to