Skip to content

Instantly share code, notes, and snippets.

@vkuhlen vkuhlen/beep.py Secret
Created Apr 3, 2019

Embed
What would you like to do?
Example BEEP data logger
import urequests
class Beep:
'''
BEEP datalogger class
Parameter "config" is a dict with the configuration of the BEEP datalogger.
From the root os the settings.json file this should be at ['telemetry']['beep']
'''
def __init__(self, config):
# Server address from beep config
# Current default is "http://bobserver.informatik.uni-bremen.de"
self.server = config['server']
# Sensor key generated by the BEEP Server when you add a sensor in the webinterface
# Add a sensor at the BOB BEEP instance at http://bobserver.informatik.uni-bremen.de
self.key = config['sensor_key']
def add(self, data):
'''
data is a dict where the keys are the identifier expected by the BEEP instance and the values are the measurements
e.g.
{
't': 22.66734,
'h': 52.41612,
'weight': 10.0,
't_i_1': 23.1875,
't_i_2': 23.125,
't_i_3': 23.125,
't_i_4': 23.1875,
'p': 1002.334
}
where t, h, p are measurements from the BME280, weight is from the HX711.
The t_i entries are the different DS1820 and only configured in our BEEP instance (this could change in the future).
Currently the frontend is used to map all t_i_* to the associated 28************** hardware identifier.
This is saved in the settings.json with the path ['sensors']['ds1820']['positions'] in the form of e.g.
{
't_i_1': '28ff6b76311802db',
't_i_2': '28ffc9343118016e'
}
To map the hardware identifiers to their positions easily the keys and values from the config can be reversed with
_ds_positions = {v: k for k, v in _ds_config['positions'].items()}
All allowed keys (except our custom additions) are the entries in 'valid_keys' in this link:
https://github.com/beepnl/BEEP/blob/bob-additions/database/seeds/MeasurementSeeder.php
'''
data['key'] = self.key
urequests.post(
'{}/api/sensors'.format(self.server),
json=data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.