def get_temperature(sensor=None):

    if sensor == None:
        time_stamp = datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S.%f")
        record_name = 'ERROR'

        return [time_stamp, record_name, -999]

    elif sensor == 'reaction':
        time_stamp = datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S.%f")
        record_name = 'ReactionTemp'

        if piplate == True:
            temperature = THERMO.getTEMP(0, sensor)
        else:
            temperature = -999.99

        return [time_stamp, record_name, temperature]

    elif sensor == 'cooling_water':
        time_stamp = datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S.%f")
        record_name = 'CoolingWater'

        if piplate == True:
            temperature = THERMO.getTEMP(0, sensor)
        else:
            temperature = -999.99

        return [time_stamp, record_name, temperature]
Exemple #2
0
def get_current_Meat_temp():
    try:
        counter = 0
        totalHarmonic = 0
        arrayOfTemps = [None] * NUM_TEMPERATURE_SAMPLES
        while counter < NUM_TEMPERATURE_SAMPLES:
            temp = THERMO.getTEMP(0, 2)
            arrayOfTemps[counter] = temp
            totalHarmonic = totalHarmonic + (1 / arrayOfTemps[counter])
            counter = counter + 1

        # since thermocouples are unreliable and can have variance in their readings
        # use the thermocouple to gather 10 samples, or NUM_TEMPERATURE_SAMPLES
        # use the samples and statistics to get the harmonic mean and the grouped median out of those values
        # average the harmonic mean and grouped median and return that as the value
        harmonicMean = NUM_TEMPERATURE_SAMPLES / totalHarmonic
        return float(
            "%.2f" %
            ((statistics.median_grouped(arrayOfTemps) + harmonicMean) / 2))
    except Exception as e:
        smartPrint(
            "***** Warning: Failed to gather data from device (Meat Temperature). Exception: %s"
            % str(e))
        raise
Exemple #3
0
                        'cyan', 'white'
                ]:
                    DP2.setLED(addr, color)
                else:
                    sys.stderr.write("unsupported LED color: " + color)

                resp['color'] = color
            else:
                sys.stderr.write("unknown daqc(2) cmd: " + cmd)
            print(json.dumps(resp))
        elif (plate_type == "MOTOR"):
            break
        elif (plate_type == "THERMO"):
            if (cmd == "getTEMP"):
                channel = args['channel']
                value = TP.getTEMP(addr, channel)
                resp['channel'] = channel
                resp['value'] = value
            elif (cmd == "getCOLD"):
                value = TP.getCOLD(addr)
                resp['value'] = value
            elif (cmd == "setLED"):
                TP.setLED(addr)
                resp['LED'] = 1
            elif (cmd == "clrLED"):
                TP.clrLED(addr)
                resp['LED'] = 0
            elif (cmd == "toggleLED"):
                TP.toggleLED(addr)
                resp['LED'] = TP.getLED(addr)
            else:
Exemple #4
0
 def get_value(self):
     return THERMO.getTEMP(self.piid, self.tid)
Exemple #5
0
GPIO.setmode(GPIO.BCM)
pinList = [GPIO_RELAY_FAN_PIN]
for i in pinList:
    GPIO.setup(i, GPIO.OUT)
    GPIO.output(i, GPIO.HIGH)

GRILL_THERMOCOUPLE = 1  # Thermocouple input on Pi-Plates THERMOplate board
MEAT_THERMOCOUPLE = 2  # Thermocouple input on Pi-Plates THERMOplate board
NUM_TEMPERATURE_SAMPLES = 10  # How many temperature samples to take to calculate harmonic mean
#==================== FIXED GLOBAL VARIABLES ====================#

#=================== OTHER GLOBAL VARIABLES  ====================#
global groveUpdateStartTime
groveUpdateStartTime = time.time()
GROVESTREAMS_UPDATE_INTERVAL_MINS = 3
THERMO.setSCALE('f')  # use Farenheit
#=================== OTHER GLOBAL VARIABLES  ====================#

#================================================================#


def log_grovestreams_data(currGrillTemp, currMeatTemp):
    base_url = '/api/feed?'
    conn = http.client.HTTPConnection('www.grovestreams.com')

    try:
        datapointTime = int(time.mktime(
            datetime.datetime.now().timetuple())) * 1000
        url = base_url + urllib.parse.urlencode(
            {
                'compId': GROVE_COMPONENT_ID,
Exemple #6
0
    async def setup(self):

        try:

            print("[%s]: Setting up the BBQ Monitor" %
                  self.config["NameSpace"])

            # --------------------------------------------------------
            # GPIO
            # --------------------------------------------------------
            GPIO.setmode(GPIO.BCM)
            GPIO.setwarnings(False)

            # --------------------------------------------------------
            # Set Mode Leds (STATUS)
            # --------------------------------------------------------
            GPIO.setup(self.Alert, GPIO.OUT)
            GPIO.setup(self.Wait, GPIO.OUT)
            GPIO.setup(self.Good, GPIO.OUT)

            # Verbose
            self.logger.info("[{0}]: Alert Pin {1}".format(
                self.config["NameSpace"],
                self.config["Status"]["Pins"]["Alert"]))
            self.logger.info("[{0}]: Wait Pin {1}".format(
                self.config["NameSpace"],
                self.config["Status"]["Pins"]["Wait"]))
            self.logger.info("[{0}]: Good Pin {1}".format(
                self.config["NameSpace"],
                self.config["Status"]["Pins"]["Good"]))

            # --------------------------------------------------------
            # Set Temperature Scale
            # --------------------------------------------------------
            ThermoPlate.setSCALE(
                self.config["ThermoPlate"]["TemperatureScale"])
            ThermoPlate.setSMOOTH(self.ThermoPlate_addr)

            # --------------------------------------------------------
            # Set Temperature ThermoCoupler Type
            # --------------------------------------------------------
            ThermoPlate.setTYPE(self.ThermoPlate_addr, self.FireBox, 'k')
            ThermoPlate.setTYPE(self.ThermoPlate_addr, self.WarmingBox, 'k')
            ThermoPlate.setTYPE(self.ThermoPlate_addr, self.LeftBack, 'k')
            ThermoPlate.setTYPE(self.ThermoPlate_addr, self.RightBack, 'k')
            ThermoPlate.setTYPE(self.ThermoPlate_addr, self.LeftFront, 'k')
            ThermoPlate.setTYPE(self.ThermoPlate_addr, self.RightFront, 'k')

            # Verbose
            self.logger.info("[{0}]: ThermoPlate Temperature Scale {1}".format(
                self.config["NameSpace"],
                self.config["ThermoPlate"]["TemperatureScale"]))

        except Exception as ex:
            self.logger.error("[ERROR] %s" % ex)
            self.logger.error(
                "[TERMINATING] We encountered an error in BBQ Monitor Setup::setup()"
            )

        print("[%s]: Completed setting up the BBQ Monitor" %
              self.config["NameSpace"])

        return
Exemple #7
0
    async def run(self):

        msgCnt = 0

        # Set device client from Azure IoT SDK and connect
        device_client = None

        try:

            while True:

                GPIO.output(self.Wait, GPIO.HIGH)
                await asyncio.sleep(self.config["TelemetryFrequencyInSeconds"])

                msgCnt = msgCnt + 1

                GPIO.output(self.Wait, GPIO.LOW)
                GPIO.output(self.Good, GPIO.HIGH)

                print("[%s]: Reading Thermocoupler Values" %
                      self.config["NameSpace"])
                print("[%s]: Plate Cold Value" %
                      ThermoPlate.getCOLD(self.ThermoPlate_addr))

                # READ FIREBOX
                print("[%s]: Reading the FIRE BOX TEMPERATURE" %
                      self.config["NameSpace"])
                DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.FireBoxStatus)
                self.TemperatureFireBox = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.FireBox)
                await asyncio.sleep(
                    self.config["ReadTimeBetweenTemperatureInSeconds"])
                DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.FireBoxStatus)

                # READ WARMING BOX
                print("[%s]: Reading the WARMING BOX TEMPERATURE" %
                      self.config["NameSpace"])
                DAQCPlate.setDOUTbit(self.DAQCPlate_addr,
                                     self.WarmingBoxStatus)
                self.TemperatureWarmingBox = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.WarmingBox)
                await asyncio.sleep(
                    self.config["ReadTimeBetweenTemperatureInSeconds"])
                DAQCPlate.clrDOUTbit(self.DAQCPlate_addr,
                                     self.WarmingBoxStatus)

                # READ LEFT BACK CHAMBER
                print("[%s]: Reading the LEFT BACK CHAMBER TEMPERATURE" %
                      self.config["NameSpace"])
                DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.LeftBackStatus)
                self.TemperatureLeftBack = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.LeftBack)
                await asyncio.sleep(
                    self.config["ReadTimeBetweenTemperatureInSeconds"])
                DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.LeftBackStatus)

                # READ RIGHT BACK CHAMBER
                print("[%s]: Reading the RIGHT BACK CHAMBER TEMPERATURE" %
                      self.config["NameSpace"])
                DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.RightBackStatus)
                self.TemperatureRightBack = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.RightBack)
                await asyncio.sleep(
                    self.config["ReadTimeBetweenTemperatureInSeconds"])
                DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.RightBackStatus)

                # READ LEFT FRONT CHAMBER
                print("[%s]: Reading the LEFT FRONT CHAMBER TEMPERATURE" %
                      self.config["NameSpace"])
                DAQCPlate.setDOUTbit(self.DAQCPlate_addr, self.LeftFrontStatus)
                self.TemperatureLeftFront = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.LeftFront)
                await asyncio.sleep(
                    self.config["ReadTimeBetweenTemperatureInSeconds"])
                DAQCPlate.clrDOUTbit(self.DAQCPlate_addr, self.LeftFrontStatus)

                # READ RIGHT FRONT CHAMBER
                print("[%s]: Reading the RIGHT FRONT CHAMBER TEMPERATURE" %
                      self.config["NameSpace"])
                DAQCPlate.setDOUTbit(self.DAQCPlate_addr,
                                     self.RightFrontStatus)
                self.TemperatureRightFront = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.RightFront)
                await asyncio.sleep(
                    self.config["ReadTimeBetweenTemperatureInSeconds"])
                DAQCPlate.clrDOUTbit(self.DAQCPlate_addr,
                                     self.RightFrontStatus)

                self.TemperatureAmbient = ThermoPlate.getTEMP(
                    self.ThermoPlate_addr, self.Ambient, "f")

                table = Texttable()
                table.set_deco(Texttable.HEADER)
                table.set_cols_dtype(["t", "f", "f", "f"])
                table.set_cols_align(["l", "r", "r", "r"])
                table.add_rows([
                    [
                        "Sensor Name", "Temperature", "Last Temperature",
                        "Smoothing"
                    ],
                    [
                        self.AmbientDisplayText, self.TemperatureAmbient,
                        self.LastTemperatureAmbient,
                        self.TemperatureAmbient / self.smoothing_value
                    ],
                    [
                        self.FireBoxDisplayText, self.TemperatureFireBox,
                        self.LastTemperatureFireBox,
                        self.TemperatureFireBox / self.smoothing_value
                    ],
                    [
                        self.WarmingBoxDisplayText, self.TemperatureWarmingBox,
                        self.LastTemperatureWarmingBox,
                        self.TemperatureWarmingBox / self.smoothing_value
                    ],
                    [
                        self.LeftBackDisplayText, self.TemperatureLeftBack,
                        self.LastTemperatureLeftBack,
                        self.TemperatureLeftBack / self.smoothing_value
                    ],
                    [
                        self.RightBackDisplayText, self.TemperatureRightBack,
                        self.LastTemperatureRightBack,
                        self.TemperatureRightBack / self.smoothing_value
                    ],
                    [
                        self.LeftFrontDisplayText, self.TemperatureLeftFront,
                        self.LastTemperatureLeftFront,
                        self.TemperatureLeftFront / self.smoothing_value
                    ],
                    [
                        self.RightFrontDisplayText, self.TemperatureRightFront,
                        self.LastTemperatureRightFront,
                        self.TemperatureRightFront / self.smoothing_value
                    ]
                ])

                print(table.draw())
                print("***")

                # Smooth Values
                self.TemperatureAmbient = self.TemperatureAmbient / self.smoothing_value
                self.TemperatureFireBox = self.TemperatureFireBox / self.smoothing_value
                self.TemperatureWarmingBox = self.TemperatureWarmingBox / self.smoothing_value
                self.TemperatureLeftBack = self.TemperatureLeftBack / self.smoothing_value
                self.TemperatureRightBack = self.TemperatureRightBack / self.smoothing_value
                self.TemperatureLeftFront = self.TemperatureLeftFront / self.smoothing_value
                self.TemperatureRightFront = self.TemperatureLeftFront / self.smoothing_value

                # Capture Last Values
                self.LastTemperatureAmbient = self.TemperatureAmbient
                self.LastTemperatureFireBox = self.TemperatureFireBox
                self.LastTemperatureWarmingBox = self.TemperatureWarmingBox
                self.LastTemperatureLeftBack = self.TemperatureLeftBack
                self.LastTemperatureRightBack = self.TemperatureRightBack
                self.LastTemperatureLeftFront = self.TemperatureLeftFront
                self.LastTemperatureRightFront = self.TemperatureLeftFront

                # Send Data to IoT Central
                for device in self.map_telemetry["Devices"]:

                    if device_client == None:
                        self.logger.info(
                            "[BBQ MONITOR] CONNECTING IOT CENTRAL: %s" %
                            device_client)
                        device_client = DeviceClient(self.logger,
                                                     device["Name"])
                        print(device_client)
                        await device_client.connect()

                    for interface in device["Interfaces"]:

                        self.logger.info("[BBQ MONITOR] InterfacelId: %s" %
                                         interface["InterfacelId"])
                        self.logger.info(
                            "[BBQ MONITOR] InterfaceInstanceName: %s" %
                            interface["InterfaceInstanceName"])

                        self.telemetry_dict = {}

                        for capability in interface["Capabilities"]:

                            # Assign variable name and value to dictionary
                            if capability[
                                    "Name"] == self.TemperatureAmbientMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureAmbient
                            elif capability[
                                    "Name"] == self.TemperatureFireBoxMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureFireBox
                            elif capability[
                                    "Name"] == self.TemperatureWarmingBoxMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureWarmingBox
                            elif capability[
                                    "Name"] == self.TemperatureLeftBackMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureLeftBack
                            elif capability[
                                    "Name"] == self.TemperatureRightBackMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureRightBack
                            elif capability[
                                    "Name"] == self.TemperatureLeftFrontMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureLeftFront
                            elif capability[
                                    "Name"] == self.TemperatureRightFrontMapName:
                                self.telemetry_dict[capability[
                                    "Name"]] = self.TemperatureRightFront
                            else:
                                self.telemetry_dict[capability["Name"]] = 0

                            self.logger.info("[BBQ MONITOR] DICTIONARY: %s" %
                                             self.telemetry_dict)

                        self.logger.info(
                            "[BBQ MONITOR] SENDING PAYLOAD IOT CENTRAL")
                        await device_client.send_telemetry(
                            self.telemetry_dict, interface["InterfacelId"],
                            interface["InterfaceInstanceName"])
                        self.logger.info("[BBQ MONITOR] SUCCESS")

                GPIO.output(self.Good, GPIO.LOW)

            return

        except Exception as ex:
            self.logger.error("[ERROR] %s" % ex)
            self.logger.error(
                "[TERMINATING] We encountered an error in BBQ Monitor Run::run()"
            )

        finally:
            await device_client.disconnect()