コード例 #1
0
ファイル: bmp180.cpp プロジェクト: blinkingnoise/Sming
void publishBMP()
{
	if (mqtt.getConnectionState() != eTCS_Connected)
		startMqttClient(); // Auto reconnect

	Serial.print("*********************************************");
	Serial.println("Start reading BMP180 sensor");
	if (!barometer.EnsureConnected()) {
		Serial.println("Could not connect to BMP180");
	} else {
	// Retrive the current pressure in Pascals
	long currentPressure = barometer.GetPressure();
	// convert pressure to mmHg
	float BMPPress = currentPressure / 133.322;

	// Print out the Pressure
	Serial.print("Pressure: ");
	Serial.print(BMPPress);
	Serial.println(" mmHg");
	mqtt.publish(BMP_P, String(BMPPress));

	// Retrive the current temperature in degrees celcius
	float BMPTemp = barometer.GetTemperature();

	// Print out the Temperature
	Serial.print("Temperature: ");
	Serial.print(BMPTemp);
	Serial.println(" *C");
	mqtt.publish(BMP_T, String(BMPTemp));
	Serial.println("BMP180 sensor read and transmitted to server");
	Serial.println("*********************************************");
	}
}
コード例 #2
0
ファイル: application.cpp プロジェクト: flexiti/flexiti_sming
void Read_BMP180 ()
{


	if(!barometer.EnsureConnected())
		Serial.println("Could not connect to BMP180.");

	// When we have connected, we reset the device to ensure a clean start.
   //barometer.SoftReset();
   // Now we initialize the sensor and pull the calibration data.
    barometer.Initialize();
	barometer.PrintCalibrationData();

	Serial.print("Start reading");

	// Retrive the current pressure in Pascals.
	long currentPressure = barometer.GetPressure();

	// Print out the Pressure.
	Serial.print("Pressure: ");
	Serial.print(currentPressure);
	Serial.print(" Pa");

	// Retrive the current temperature in degrees celcius.
	float currentTemperature = barometer.GetTemperature();

	// Print out the Temperature
	Serial.print("\tTemperature: ");
	Serial.print(currentTemperature);
	Serial.write(176);
	Serial.print("C");

	Serial.println(); // Start a new line.

	cctemp=(int)(currentTemperature*10);
	ccpres=(int)(currentPressure/10);
}