Exemplo n.º 1
0
 def btest_delete_deg(self):
     sender = Sender()
     response = sender.send_deg(self.get_random_degree())
     self.assertEqual(201, response.status_code)
     rjson = response.json()
     id = rjson['id']
     status_code = sender.del_deg(id)
     self.assertEqual(200, status_code)
Exemplo n.º 2
0
 def btest_sender_batterycharge(self):
     sender = Sender()
     value = 10
     try:
         response = sender.send_battery_level(value)
         print(response.json())
         self.assertEqual(201, response.status_code)
     except:
         print("No connection possible to send battery_level")
Exemplo n.º 3
0
def main():
    redox_value = 0.0
    if boxsettings.FAKE_DATA:
        redox_value = get_random_redox()
    else:
        redox_value = getORP()
    print "Redox: ", redox_value
    logging.debug("Redox value: %s", redox_value)
    sender = Sender()
    sender.send_redox(redox_value)
Exemplo n.º 4
0
 def btest_sender_send_log_with_LogUtil(self):
     sender = Sender()
     logutil = LogUtil()
     logutil.read_log(boxsettings.LOG_FILE)
     try:
         response = sender.send_log(logutil.log_text)
         print(response.json())
         self.assertEqual(201, response.status_code)
     except:
         msg = "problem occured when attempting to send the log"
         self.assertFalse(True, msg)
Exemplo n.º 5
0
 def send_measures(self):
     self.logger.info('Sending measures..')
     redox_sent = ph_sent = temp_sent = False
     sender = Sender()
     self.logger.debug('orp...')
     try:
         sender.send_redox(float(self.orp_value))
         redox_sent = True
     except Exception, e:
         self.logger.warning('We was not able to send redox to REST',
                             exc_info=True)
Exemplo n.º 6
0
 def send_logfile(self):
     self.logger.info('Sending log file')
     try:
         sender = Sender()
         logger.info('Bye bye.')
         time.sleep(10)
         logutil = LogUtil()
         logutil.read_log(boxsettings.LOG_FILE)
         sender.send_log(logutil.log_text)
         self.logger.debug('done')
     except Exception, e:
         msg = "problem occured when attempting to send the log."
         self.logger.fatal(msg, exc_info=True)
Exemplo n.º 7
0
    def btest_sender_deg(self):
        logging.info('testing deg send...')
        sender = Sender()
        for i in range(0, 2):
            if i % 2:
                pass
            else:
                sender.user_box = self.user_box
                sender.user_box_passwd = self.user_box_passwd

            response = sender.send_deg(self.get_random_degree())
            self.assertEqual(201, response.status_code)
        logging.info('DONE')
Exemplo n.º 8
0
 def send_log(self):
     self.logger.info('Sending log file')
     try:
         sender = Sender()
         self.logger.info('Bye bye.')
         time.sleep(1)
         logutil = LogUtil()
         logutil.read_log(boxsettings.LOG_FILE)
         if sender.is_online():
             self.logger.debug('sender.is_online')
             sender.send_log(logutil.log_text)
         else:
             self.logger.info('We do not send log as we are not online')
     except:
         msg = "problem occured when attempting to send the log."
         self.logger.fatal(msg)
Exemplo n.º 9
0
    def btest_sender_send_log(self):
        sender = Sender()
        log_text = """INFO	: 2018-07-13 16:28:04,039 : Saving settings to local JSON file settings.json 
INFO	: 2018-07-13 16:28:04,046 : Settings written to file.
INFO	: 2018-07-13 16:28:04,143 : Saving settings to local JSON file settings.json 
INFO	: 2018-07-13 16:28:04,143 : Settings written to file.
INFO	: 2018-07-13 16:28:04,144 : REST url: http://aquawatch.ch/battery/
INFO	: 2018-07-13 16:28:04,144 : JSON: {'battery_charge': '10'}
INFO	: 2018-07-13 16:28:04,144 : User: raspi
INFO	: 2018-07-13 16:28:04,248 : Data sent to /battery/ of REST service.
        """
        try:
            response = sender.send_log(log_text)
            print(response.json())
            self.assertEqual(201, response.status_code)
        except:
            msg = "problem occured when attempting to send the log"
            self.assertFalse(True, msg)
Exemplo n.º 10
0
def send_battery_charge_level(raspi, pool_settings, logger):
    logger.debug('send_battery_charge_level: pool_settings')
    logger.debug('Online: %s Reading: %s' %
                 (pool_settings.is_online(), pool_settings.enable_reading()))
    logger.debug('do_update pool_settings. do_update? %s ' %
                 pool_settings.do_update())

    try:
        sender = Sender()
        battery_level = raspi.get_charge_level()
        logger.info('Battery charge in percent: %s' % battery_level)
        if ONLINE:
            logger.info('ONLINE: Sending info to REST')
            response = sender.send_battery_level(battery_level)
            logger.info('Answer: %s' % response.status_code)
        else:
            logger.info(('NOT ONLINE. Battery level not sent'))
    except:
        logger.fatal("Cannot create pijuice object")
Exemplo n.º 11
0
    def __init__(self):
        self.logger = logging.getLogger('PoolSettings')
        self.settings = {
            'enable_reading': False,
            'do_update': False,
            'time_between_readings': 24,
            'enable_shutdown': False,
            'log_level': logging.DEBUG,
            'bigshutdown': False
        }

        self.online = False
        sender = Sender()

        try:
            settings_json = sender.get_pool_settings()
            self.settings = settings_json[0]
            self.logger.info(
                'We are online. Saving settings to local JSON file %s ' %
                self.file_name)
            with open(self.file_name, 'w') as outfile:
                json.dump(self.settings, outfile)
            self.logger.info("Settings written to file.")
            self.online = True
        except Exception, e:
            self.logger.warning('Connection error.', exc_info=True)
            self.logger.info(
                "trying to load previous settings from file, as network connection fails."
            )
            file_name = 'settings.json'
            try:
                with open(file_name) as infile:
                    self.settings = json.load(infile)
                self.logger.info("Success reading from file")
            except Exception, e:
                # falling back to default
                self.logger.warning("No file found. Using default values",
                                    exc_info=True)
Exemplo n.º 12
0
 def btest_sender_redox_1020(self):
     # TODO: strengthen out of range values
     sender = Sender()
     value = 1020.0
     response = sender.send_redox(value)
     self.assertEqual(201, response.status_code)
Exemplo n.º 13
0
 def btest_sender_redox(self):
     sender = Sender()
     value = self.get_random_redox()
     response = sender.send_redox(value)
     self.assertEqual(201, response.status_code)
Exemplo n.º 14
0
 def btest_sender_ph_3(self):
     logging.info('pH sending test')
     sender = Sender()
     response = sender.send_ph(3)
     logging.info('pH sent. Response: %s' % response.status_code)
     self.assertEqual(201, response.status_code)
Exemplo n.º 15
0
 def btest_sender_deg_toolow(self):
     sender = Sender()
     response = sender.send_deg(-23.000)
     self.assertEqual(400, response.status_code)
Exemplo n.º 16
0
a['year'] = 'EVERY_YEAR'
a['month'] = 'EVERY_MONTH'
a['day'] = 'EVERY_DAY'
a['hour'] = 'EVERY_HOUR'
t = datetime.datetime.utcnow()
#a['minute'] = (t.minute + DELTA_MIN) % 60
a['minute'] = 0
a['second'] = 0
status = pj.rtcAlarm.SetAlarm(a)
if status['error'] != 'NO_ERROR':
    print('Cannot set alarm\n')
    sys.exit()
else:
    print('Alarm set for ' + str(pj.rtcAlarm.GetAlarm()))

# Enable wakeup, otherwise power to the RPi will not be
# applied when the RTC alarm goes off
pj.rtcAlarm.SetWakeupEnabled(True)
time.sleep(0.4)

# PiJuice shuts down power to Rpi after 20 sec from now
# This leaves sufficient time to execute the shutdown sequence
sender = Sender()
enable_shutdown = sender.get_shutdown_settings()
if enable_shutdown:
    print('We will MAKE a shutdown')
    pj.power.SetPowerOff(20)
    subprocess.call(["sudo", "poweroff"])
else:
    print('We do NOT make a shutdown')
Exemplo n.º 17
0
 def send_ph(self):
     logging.debug('GetSendPh')
     sender = Sender()
     sender.send_ph(self.ph)
Exemplo n.º 18
0
 def btest_sender_deg_last(self):
     """Get last value saved"""
     sender = Sender()
     response = sender.deg_last()
     self.assertEqual(response.status_code, 200)
Exemplo n.º 19
0
 def send_temperature(self):
     logging.debug('GetSendTemp: send_temperature')
     sender = Sender()
     sender.send_deg(self.temperature)
Exemplo n.º 20
0
 def btest_send_charge_level(self):
     raspi = RaspiFactory.getRaspi('Mock')
     sender = Sender()
     if sender.is_online():
         response = sender.send_battery_level(raspi.get_charge_level())
         self.assertEqual(201, response.status_code)