Exemple #1
0
    def find_for_topic(self, topic, start_date, end_date, batch_pause=0.0):
        request_path = '/v1/messages/topic/' + topic

        total = 0
        collection = []

        # request...
        self.__rest_client.connect()

        try:
            for batch in self.__find(request_path, start_date, end_date):
                collection.extend(batch)

                if self.__verbose:
                    now = LocalizedDatetime.now().utc()
                    batch_count = len(batch)
                    total += batch_count

                    print("%s: batch: %d total: %d" % (now.as_iso8601(), batch_count, total), file=sys.stderr)
                    sys.stderr.flush()

                time.sleep(batch_pause)     # prevent "Rate limit exceeded" error

        finally:
            self.__rest_client.close()

        return collection
Exemple #2
0
    def update(self):
        # time...
        display_datetime = self.__show_time and Host.time_is_synchronized()
        datetime = LocalizedDatetime.now() if display_datetime else None

        # network...
        nmcli = NMCLi.find()
        homes = {} if nmcli is None else nmcli.connections

        # message...
        message = self.__status_message

        # PSU...
        if self.__psu_report_filename:
            psu_report = self.__psu_report_class.load(
                self.__psu_report_filename)
            batt_percent = None if psu_report is None else psu_report.batt_percent
        else:
            batt_percent = None

        # MQTT queue...
        if self.__queue_report_filename:
            queue_report = QueueReport.load(self.__queue_report_filename)
            queue_message = self.__QUEUE_STATE[queue_report.queue_state()]

            message += ':' + queue_message

        # GPS quality...
        if self.__gps_report_filename:
            gps_report = GPSDatum.load(self.__gps_report_filename)
            gps_quality = gps_report.quality

            message += '  GPS:' + str(gps_quality)

        return self.render(datetime, BattDisplay(batt_percent), homes, message)
    def print(self, status):
        if not self.__verbose:
            return

        now = LocalizedDatetime.now().utc()
        print("%s:         mqtt: %s" % (now.as_time(), status), file=sys.stderr)
        sys.stderr.flush()
Exemple #4
0
    def __open_file(self):
        self.log.timeline_start = LocalizedDatetime.now().utc()

        self.__clear_space()
        self.log.mkdir()

        self.__file = open(self.log.file_path(), "w")
        self.__writer = csv.writer(self.__file, quoting=csv.QUOTE_MINIMAL)

        if self.__paths:
            self.__writer.writerow(self.__paths)
Exemple #5
0
    def sample(self):
        rec = LocalizedDatetime.now().utc()

        self.__ndir.sample()

        try:
            time.sleep(self.__interval)
        except KeyboardInterrupt:
            pass

        p_a = self.__ndir.get_sample_pressure()

        return NDIRPressureDatum(rec, p_a)
Exemple #6
0
    def sample(self):
        rec = LocalizedDatetime.now().utc()

        self.__ndir.sample()

        try:
            time.sleep(self.__interval)
        except KeyboardInterrupt:
            pass

        co2_datum = self.__ndir.get_sample_gas()

        return GasesSample(self.__tag, rec, co2_datum, None, None)
Exemple #7
0
    def sample(self):
        rec = LocalizedDatetime.now().utc()

        self.__ndir.sample()

        try:
            time.sleep(self.__interval)
        except KeyboardInterrupt:
            pass

        sample = self.__ndir.get_sample_voltage()
        voltage_datum = NDIRSampleVoltageDatum.construct_from_sample(sample)

        return GasesSample(self.__tag, rec, voltage_datum, None, None)
    def read_learned_params(self):
        try:
            self.obtain_lock()

            calibrated_on = LocalizedDatetime.now()

            r_comp_0 = self.__read_reg(self.__REG_R_COMP_0)
            temp_co = self.__read_reg(self.__REG_TEMP_CO)
            full_cap_rep = self.__read_reg(self.__REG_FULL_CAP_REP)
            full_cap_nom = self.__read_reg(self.__REG_FULL_CAP_NOM)

            cycles = self.__read_reg(self.__REG_CYCLES)

            return Max17055Params(calibrated_on, r_comp_0, temp_co,
                                  full_cap_rep, full_cap_nom, cycles)

        finally:
            self.release_lock()
Exemple #9
0
    def __write(self, datum):
        # first run...
        if not self.__file:
            if self.log.tag is None and 'tag' in datum.collection:
                self.log.tag = datum.collection['tag']

            self.__open_file()

        # start log for new day...
        if not self.log.in_timeline(LocalizedDatetime.now().utc()):
            self.close()
            self.__open_file()

        # write header...
        if not self.__paths:
            self.__paths = datum.paths()
            self.__writer.writerow(self.__paths)

        # write row...
        self.__writer.writerow(datum.row(self.__paths))
    def sample(self):
        rec = LocalizedDatetime.now().utc()
        sample = self.__ndir.measure_voltage()

        return NDIRMeasureVoltageDatum.construct_from_sample(rec, sample)
Exemple #11
0
 def sample(self):
     return 'SAMPLE ' + LocalizedDatetime.now().utc().as_iso8601()
Exemple #12
0
        # check for existing registration...
        device = device_manager.find(api_auth.org_id, cmd.client_id)

        if device is None:
            print("device_topics: Device not found.", file=sys.stderr)
            exit(1)

        topic_manager = TopicManager(api_auth.api_key)

        # ------------------------------------------------------------------------------------------------------------
        # run...

        # time...
        if cmd.use_offset():
            end = LocalizedDatetime.now()
            start = end.timedelta(minutes=-cmd.minutes)
        else:
            end = LocalizedDatetime.now() if cmd.end is None else cmd.end
            start = cmd.start

        if cmd.verbose:
            print("device_topics: start: %s" % start, file=sys.stderr)
            print("device_topics: end: %s" % end, file=sys.stderr)
            sys.stderr.flush()

        # topics...
        topics = topic_manager.find_for_device(cmd.client_id, start, end)

        for topic in topics:
            print(JSONify.dumps(topic))
Exemple #13
0
 def null_datum(cls):
     return OPCDatum(None,
                     LocalizedDatetime.now().utc(), None, None, None, 0.0,
                     [], 0, 0, 0, 0)
Exemple #14
0
    def file_prefix(self):
        dt = AQCSVDatetime(LocalizedDatetime.now().utc().datetime)
        site = AQCSVSite.construct_from_code(self.site_code)

        return dt.filename_prefix() + '_' + str(
            site.country_code)  # goal is YYYYMMDDhhmm_CCC.AAAAAAAAAA
Exemple #15
0
    def save(self, host):
        if self.__calibrated_on is None:
            self.__calibrated_on = LocalizedDatetime.now().utc()

        super().save(host)
    def save(self, manager, encryption_key=None):
        if not self.__calibrated_on:
            self.__calibrated_on = LocalizedDatetime.now()

        super().save(manager, encryption_key=encryption_key)
Exemple #17
0
    print(pack)

    # overwrite any previous BattPack version...
    params = pack.default_params()
    print("default params: %s" % JSONify.dumps(params))
    params.save(Host)

    loaded = pack.initialise(Host, force_config=True)
    # loaded = pack.initialise(Host)
    print("loaded: %s" % loaded, file=sys.stderr)
    sys.stderr.flush()

    timer = IntervalTimer(10.0)

    while timer.true():
        print(LocalizedDatetime.now().as_iso8601(), file=sys.stderr)
        sys.stdout.flush()

        datum = pack.sample()
        print(JSONify.dumps(datum))

        params = pack.read_learned_params()
        print(JSONify.dumps(params), file=sys.stderr)
        # params.save(Host)

        print("-", file=sys.stderr)
        sys.stdout.flush()

except KeyboardInterrupt:
    print()
Exemple #18
0
# --------------------------------------------------------------------------------------------------------------------

# Interface...
interface_conf = InterfaceConf.load(Host)

psu_conf = PSUConf.load(Host)

psu = psu_conf.psu(Host, interface_conf.model)
print(psu)
print("-")

try:
    psu.open()

    for i in range(1000000):
        now = LocalizedDatetime.now().utc()
        start = time.time()

        response = psu.communicate('status')
        elapsed = time.time() - start

        print("%7d: %s, %0.3f, '%s'" %
              ((i + 1), now.as_iso8601(), elapsed, response))
        print("-")

        sys.stdout.flush()
        time.sleep(1.0)

        if len(response) < 10:
            break
Exemple #19
0
 def null_datum(cls):
     return SPSDatum(None,
                     LocalizedDatetime.now().utc(), None, None, None, None,
                     [], None)
#!/usr/bin/env python3
"""
Created on 3 Oct 2016

@author: Bruno Beloff ([email protected])

https://github.com/electricimp/MAX17055
"""

from scs_core.data.datetime import LocalizedDatetime
from scs_core.data.json import JSONify

from scs_psu.batt_pack.fuel_gauge.max17055.max17055_params import Max17055Params

# --------------------------------------------------------------------------------------------------------------------

r_comp_0 = 1
temp_co = 2
full_cap_rep = 3
full_cap_nom = 4
cycles = 5

params = Max17055Params(LocalizedDatetime.now(), r_comp_0, temp_co,
                        full_cap_rep, full_cap_nom, cycles)
print(params)
print("-")

jstr = JSONify.dumps(params)
print(jstr)
print("-")