Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calculating an average over time for all packages received in a given time span #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michalrus
Copy link

Hello!

This seems useful to me:

  • after a warmup receive all packets that the device is sending anyways for a given time,
  • and output their average at the very end,
  • which can then be fed to some external service, say InfluxDB etc.

Esp. if we output it as JSON:

diff --git a/pmlog.py b/pmlog.py
index 489ad7f..59f987a 100755
--- a/pmlog.py
+++ b/pmlog.py
@@ -7,6 +7,7 @@ import struct
 import logging
 import argparse
 import operator
+import json
 from collections import namedtuple
 from threading import Event

@@ -175,7 +176,7 @@ def run_average(sensor, args):
         sensor.disable()
         if num_packets > 0:
             avg = Packet(*tuple(map(lambda x: x/num_packets, summed_packets)))
-            log.info(avg)
+            print(json.dumps(avg._asdict()))
         else: exit(1)

 def install_signal_handlers(sensor):

@michalrus
Copy link
Author

Eh, but it uses 100% CPU. Python’s insane. https://www.google.com/search?q=python+serial+port+read+cpu+100

@michalrus
Copy link
Author

N.b. this problem also happens in the original code, w/o my PR.

@michalrus
Copy link
Author

If anyone needs a no-bullshit solution, feel free to use https://github.com/michalrus/pms5003.

@michalrus michalrus closed this Jan 2, 2018
@michalrus michalrus reopened this Jan 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant