Last active
July 11, 2018 07:36
-
-
Save TakehikoShimojima/70f2996ac2a52f0d5c65e22b93669830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void onRead(BLECharacteristic *pChar) { | |
| uint8_t buf[19]; | |
| bme280.get_sensor_data(&data); // センサーを読む | |
| Serial.printf("temp: %f, humid: %f, press: %f\r\n", data.temperature, data.humidity, data.pressure / 100); | |
| uint16_t temp = (uint16_t)(data.temperature * 100); | |
| uint16_t humid = (uint16_t)(data.humidity * 100); | |
| uint16_t press = (uint16_t)(data.pressure / 10); | |
| memset(buf, 0, sizeof buf); // バッファーを0クリア | |
| buf[0] = seq++; // シーケンス番号をバッファーにセット | |
| buf[1] = (uint8_t)(temp & 0xff); // 温度の下位バイトをセット | |
| buf[2] = (uint8_t)((temp >> 8) & 0xff); // 温度の上位バイトをセット | |
| buf[3] = (uint8_t)(humid & 0xff); // 湿度の下位バイトをセット | |
| buf[4] = (uint8_t)((humid >> 8) & 0xff); // 湿度の上位バイトをセット | |
| buf[9] = (uint8_t)(press & 0xff); // 気圧の下位バイトをセット | |
| buf[10] = (uint8_t)((press >> 8) & 0xff); // 気圧の上位バイトをセット | |
| pChar->setValue(buf, sizeof buf); // データーを書き込み | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment