// MQTT : Publish our message
void publishMessage()
{
	if (mqtt.getConnectionState() != eTCS_Connected) {
		startMqttClient(); // Auto reconnect
		return;
	}

	// Read DHT22
	TempAndHumidity th;
	if(!dht.readTempAndHumidity(th)) {
		return;
	}
	// Make JSON data
	String message = "{\"temp\":";
	message += th.temp;
	message += ", \"humi\":";
	message += th.humid;
	message += "}";

	// publish message
	Serial.println("Let's publish message now!");
	mqtt.publish("home/thirdroom/temp_humi", message, true); // retained message

	displayTemp(message);
}
Ejemplo n.º 2
0
void HomeScreen::displayTemp() {
#if DBG
  Serial.print("HomeScreen::displayTemp: ");
  Serial.println(tNow);
#endif
  float temp = readTemp(TEMP_F);
  displayTemp(TEMP_F, temp);
}
Ejemplo n.º 3
0
void HomeScreen::display() {
  lcd.clear();
  lcd.noBlink();
  lcd.noCursor();
  displayHeader();
  displayDateTime();
  displayTemp();
}
Ejemplo n.º 4
0
void HomeScreen::loop(unsigned long tNow) {
#if DBG
  Serial.print("HomeScreen::loop: ");
  Serial.println(tNow);
#endif
  if (tLastDateTime == 0 || tNow - tLastDateTime > LOOP_UPDATE_INTERVAL) {
    displayDateTime();
    tLastDateTime = tNow;
  }
  
  if (tLastTemp == 0 || tNow - tLastTemp > (LOOP_UPDATE_INTERVAL * 10)) {
    displayTemp();
    tLastTemp = tNow;
  }
}
Ejemplo n.º 5
0
void loop() 
{

  buttonSense(); //check to see if the button is pressed
  blinkLED(); //blink the LEDs to a predetermined pattern
  delay(1000); //pause for 1 second

  readADCvalue = analogRead(138); //get the raw ADC data. Must use "pin" 138 due to backend coding located in pins_energia.h
  
  //below formulas were taken from the MSP430 user guide for calibrating internal temp sensor
  cal_1 = t85 - t30;
  cal_2 = 85-30;
  cal_3 = cal_1 / cal_2;
  cal_4 = readADCvalue - t30;
  cal_5 = cal_3 * cal_4;
  cal_6 = cal_5 + 30; //final temp result in degC
    
  displayTemp(cal_6, mode); //pass temp info and mode info to be displayed on LEDs
  delay(1000); //pause for 1 second
  
}
Ejemplo n.º 6
0
double PIDControl::reflowPID(double setTempPoint, double setTimePoint, unsigned long windowStartTime)
{
    _val=analogRead(sensePin);
    currTemp = _val * 0.00489 / 0.005;	//Converting the voltage of sensePin to current temp.

    displayTemp(currTemp,setTempPoint);

    myPID.Compute();
    Serial.println(Output);
    return Output;

    _now = millis();
    if((_now - windowStartTime)/1000 > setTimePoint)
    {   //time to shift the Reflow Window
        windowStartTime += setTimePoint;
    }
    if (Output > (_now - windowStartTime)/1000)
    {
        digitalWrite(heaterPin,HIGH);
    }
    else digitalWrite(heaterPin,LOW);
}
Ejemplo n.º 7
0
void tempSensor()
{
    //Initialize the ADC Module
    /*
     * Base Address for the ADC Module
     * Use Timer trigger 1 as sample/hold signal to start conversion
     * USE MODOSC 5MHZ Digital Oscillator as clock source
     * Use default clock divider of 1
     */
    ADC_init(ADC_BASE,
        ADC_SAMPLEHOLDSOURCE_2,
        ADC_CLOCKSOURCE_ADCOSC,
        ADC_CLOCKDIVIDER_1);

    ADC_enable(ADC_BASE);

    //Configure Memory Buffer
    /*
     * Base Address for the ADC Module
     * Use input A12 Temp Sensor
     * Use positive reference of Internally generated Vref
     * Use negative reference of AVss
     */
    ADC_configureMemory(ADC_BASE,
        ADC_INPUT_TEMPSENSOR,
        ADC_VREFPOS_INT,
        ADC_VREFNEG_AVSS);

    ADC_clearInterrupt(ADC_BASE,
            ADC_COMPLETED_INTERRUPT);

    // Enable the Memory Buffer Interrupt
    ADC_enableInterrupt(ADC_BASE,
            ADC_COMPLETED_INTERRUPT);

    ADC_startConversion(ADC_BASE,
                        ADC_REPEATED_SINGLECHANNEL);

    // Enable internal reference and temperature sensor
    PMM_enableInternalReference();
    PMM_enableTempSensor();

    // TimerA1.1 (125ms ON-period) - ADC conversion trigger signal
    Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam_A1);

    //Initialize compare mode to generate PWM1
    Timer_A_initCompareMode(TIMER_A1_BASE, &initCompParam);

    // Start timer A1 in up mode
    Timer_A_startCounter(TIMER_A1_BASE,
        TIMER_A_UP_MODE
        );

    // Delay for reference settling
    __delay_cycles(300000);

    //Enter LPM3.5 mode with interrupts enabled
    while(*tempSensorRunning)
    {
        __bis_SR_register(LPM3_bits | GIE);                       // LPM3 with interrupts enabled
        __no_operation();                                         // Only for debugger

        if (*tempSensorRunning)
        {
        	// Turn LED1 on when waking up to calculate temperature and update display
            P1OUT |= BIT0;

            // Calculate Temperature in degree C and F
            signed short temp = (ADCMEM0 - CALADC_15V_30C);
            *degC = ((long)temp * 10 * (85-30) * 10)/((CALADC_15V_85C-CALADC_15V_30C)*10) + 300;
            *degF = (*degC) * 9 / 5 + 320;

            // Update temperature on LCD
            displayTemp();

            P1OUT &= ~BIT0;
        }
    }

    // Loop in LPM3 to while buttons are held down and debounce timer is running
    while(TA0CTL & MC__UP)
    {
        __bis_SR_register(LPM3_bits | GIE);         // Enter LPM3
        __no_operation();
    }

    if (*mode == TEMPSENSOR_MODE)
    {
        // Disable ADC, TimerA1, Internal Ref and Temp used by TempSensor Mode
        ADC_disableConversions(ADC_BASE,ADC_COMPLETECONVERSION);
        ADC_disable(ADC_BASE);

        Timer_A_stop(TIMER_A1_BASE);

        PMM_disableInternalReference();
        PMM_disableTempSensor();
        PMM_turnOffRegulator();

        __bis_SR_register(LPM4_bits | GIE);         // re-enter LPM3.5
        __no_operation();
    }
}