Exemplo n.º 1
0
    def run(self):

        sensors = None
        datalogger = None

        try:

            # initialise objects
            sensors = Sensors(self.T_OFFSET,self.P_OFFSET,self.H_OFFSET)
            datalogger = DataLogger(self.DATALOGFILE, self.DATALOGKEYS, self.DATALOGMAXFILESIZE)
            self.scheduler = HeaterScheduler()
            self.modemanager = ModeManager( scheduler=self.scheduler,
                                            callbackfunc=self.modemanagercallbackfunc)
            self.mqttclient = MqttClient(subscribelist=self.SUBSCRIBELIST)
            self.heatercontroller = HeaterController()
            
            # initialise state
            self.modemanager.setMode(self.modemanager.AUTO)

            # initial data
            t_avg,p_avg,h_avg = sensors.getData()

            # present ourselves
            self.mqttclient.publish({topics.IOTHERMSTATUS:'Active'})
            self.mqttclient.publish({topics.IOTHERMVERSION:__version__ +' '+ __status__})
            self.mqttclient.publish({topics.MODE:self.modemanager.currentmode.name})
            self.mqttclient.publish({topics.TARGETTEMPERATURE:self.modemanager.currentmode.targettemperature})

            t = 0
            
            while True:
               t_,p,h = sensors.getData()
               messages = self.mqttclient.getData()
               
               # use temperature value from mqtt
               if self.USE_OTHERTEMPERATURE and topics.OTHERTEMPERATURE in messages:
                   t = float( messages[topics.OTHERTEMPERATURE] )
            
               if not self.USE_OTHERTEMPERATURE:
                   t = t_
            
               # calculate averages
               t_avg = (t_avg + t)/2       
               p_avg = (p_avg + p)/2       
               h_avg = (h_avg + h)/2

               # calculate derivatives
               d_t = (t - t_avg)/self.REFRESH_SECONDS
               d_p = (p - p_avg)/self.REFRESH_SECONDS
               d_h = (h - h_avg)/self.REFRESH_SECONDS

               # process data from subscribed topics
               self.processMessages( messages )
           
               # prepare for publishing
               messages = self.prepareMessages(t, p, h, d_t, d_p, d_h)
               datalogger.log(messages)
               self.mqttclient.publish(messages)

               # update the heatercontroller with the current and target temperatures
               #print('targettemperature = {}'.format(self.modemanager.currentmode.targettemperature))
               self.heatercontroller.update(t,self.modemanager.currentmode.targettemperature)

               sleep(self.REFRESH_SECONDS)

        finally:
            print('IOThermostat: Stopping IOThermostat..')
            if datalogger:
                datalogger.close()
                
            if sensors:
                sensors.close()
                
            if self.scheduler:
                self.scheduler.close()
                
            if self.heatercontroller:
                self.heatercontroller.close()
                
            if self.mqttclient:
                self.mqttclient.close()
Exemplo n.º 2
0
    ax.set_xlim([[0, 70], [0, 5]][a])
    ax.set_xticks([np.linspace(0, 70, 8), np.linspace(0, 5, 6)][a])
    ax.set_ylim([[0, 5], [0, 70]][a])
    ax.set_yticks([np.linspace(0, 5, 6), np.linspace(0, 70, 8)][a])
    ax.set_xlabel(["Heat Flux [kW/m2]", "Voltage to lamps (VDC)"][a])
    ax.set_ylabel(["Voltage to lamps (VDC)", "Heat Flux [kW/m2]"][a])

# plot both regressions
axes[1].scatter(y, x, color="dodgerblue", alpha=0.5)
axes[1].plot(y,
             all_data.loc[:, "polyfit_voltage_to_heatflux"],
             color="maroon",
             linewidth=2)
axes[0].scatter(x, y, color="dodgerblue", alpha=0.5)
axes[0].plot(x,
             all_data.loc[:, "polyfit_heatflux_to_voltage"],
             color="maroon",
             linewidth=2)

address_plot = f"{address_file.split('.xlsx')[0]}.pdf"
plt.savefig(address_plot)

# finish the calibration
logger.write(':SOURce:VOLTage %G,(%s)' % (0.0, '@304'))
logger.close()
rm.close()

print("\n\nCalibration finished")
print(
    f"Total duration = {np.round((time.time() - time_start_logging)/60,1)} minutes"
)
Exemplo n.º 3
0
class ProzedaTrace(object):
    def __init__(self, fileprefix, filesuffix):
        self.fileprefix = fileprefix
        self.filesuffix = filesuffix

        self.starttime = None
        self.stoptime = None
        self.logger = None

        self.livetrace = collections.deque(maxlen=100)

    def start(self, duration, comment=None):
        if self.starttime == None:
            self.starttime = time.time()

        if duration is None:
            duration = 0
        self.stoptime = time.time() + int(duration)

        if self.logger is None:
            self.logger = DataLogger(self.fileprefix, self.filesuffix,
                                     '%Y-%m-%d_%H.%M.%S', True)

        if comment is not None and self.logger is not None:
            self.logger.write(None, 'c', comment)

    def stop(self):
        if self.logger is not None:
            self.logger.close()
        self.logger = None
        self.starttime = None
        self.stoptime = None

    def stats(self):
        result = {
            'file': None,
            'start': self.starttime,
            'stop': self.stoptime,
            'remaining': None,
            'size': None
        }
        if self.stoptime is not None:
            result['remaining'] = self.stoptime - time.time()
        if self.logger is not None:
            result['file'] = self.logger.filename
            result['size'] = self.logger.get_filesize()
        return result

    def data_received(self, prd, timestamp, line):
        if time.time() >= self.stoptime:
            self.stop()

        if self.logger is not None:
            self.logger.write(timestamp, 'd', line)

        self.livetrace.append([timestamp, line])

    def livetrace_get(self, last_timestamp=0):
        result = []
        for item in self.livetrace:
            if item[0] > last_timestamp:
                result.append(item)
        return result