警告エラーをシリアルに出力
This commit is contained in:
parent
d6105a8f9a
commit
8bc573069e
|
|
@ -58,6 +58,7 @@ public:
|
|||
void onConnect(BLEServer*) override {
|
||||
// 接続中は、画面に接続中であることを表示できます。
|
||||
logger_->bluetoothConnected_ = true;
|
||||
Serial.println("[INFO] BLE client connected");
|
||||
}
|
||||
|
||||
void onDisconnect(BLEServer* server) override {
|
||||
|
|
@ -66,6 +67,7 @@ public:
|
|||
logger_->commandBuffer_ = "";
|
||||
logger_->lastAdvertise_ = millis();
|
||||
server->startAdvertising();
|
||||
Serial.println("[WARNING] BLE client disconnected; advertising restarted");
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -82,9 +84,19 @@ void SensorLogger::begin(uint8_t soilPin) {
|
|||
// 未接続時にライブラリへアクセスすると、不要なI2Cエラーや待ち時間が発生します。
|
||||
if (isI2cDevicePresent(0x38)) {
|
||||
aht20Ready = aht20.begin();
|
||||
if (!aht20Ready) {
|
||||
Serial.println("[ERROR] AHT20 initialization failed");
|
||||
}
|
||||
} else {
|
||||
Serial.println("[WARNING] AHT20 not detected at 0x38");
|
||||
}
|
||||
if (isI2cDevicePresent(0x23)) {
|
||||
bh1750Ready = bh1750.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
|
||||
if (!bh1750Ready) {
|
||||
Serial.println("[ERROR] BH1750 initialization failed");
|
||||
}
|
||||
} else {
|
||||
Serial.println("[WARNING] BH1750 not detected at 0x23");
|
||||
}
|
||||
|
||||
// ESP32固有の番号を名前に加え、同じ名前の機器と区別します。
|
||||
|
|
@ -93,6 +105,7 @@ void SensorLogger::begin(uint8_t soilPin) {
|
|||
snprintf(name, sizeof(name), "%s-%05llX", kBleDeviceNamePrefix, mac & 0xFFFFF);
|
||||
bluetoothName_ = name;
|
||||
BLEDevice::init(bluetoothName_.c_str());
|
||||
Serial.printf("[INFO] BLE initialized as '%s'\n", bluetoothName_.c_str());
|
||||
|
||||
// BLEサーバーと、センサー通信用のサービスを作ります。
|
||||
server_ = BLEDevice::createServer();
|
||||
|
|
@ -119,6 +132,7 @@ void SensorLogger::begin(uint8_t soilPin) {
|
|||
advertising->setMinPreferred(0x06);
|
||||
advertising->setMinPreferred(0x12);
|
||||
BLEDevice::startAdvertising();
|
||||
Serial.println("[INFO] BLE advertising started");
|
||||
|
||||
// 起動直後にも1回計測して、画面に値を表示できるようにします。
|
||||
readAndStore();
|
||||
|
|
@ -281,6 +295,8 @@ void SensorLogger::receiveBluetoothData(const String& data) {
|
|||
commandBuffer_ += character;
|
||||
} else if (commandBuffer_.length() < 64) {
|
||||
commandBuffer_ += character;
|
||||
} else if (commandBuffer_.length() == 64) {
|
||||
Serial.println("[ERROR] BLE command is too long and was truncated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -340,9 +356,12 @@ void SensorLogger::processCommand(const String& command) {
|
|||
txCharacteristic_->setValue("OK_TIME\n");
|
||||
txCharacteristic_->notify();
|
||||
} else {
|
||||
Serial.printf("[ERROR] Invalid TIME command: %s\n", command.c_str());
|
||||
txCharacteristic_->setValue("ERROR_TIME\n");
|
||||
txCharacteristic_->notify();
|
||||
}
|
||||
} else {
|
||||
Serial.printf("[WARNING] Unknown BLE command: %s\n", command.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -183,6 +183,8 @@ void avrc_metadata_callback(uint8_t id, const uint8_t *text) {
|
|||
} else if (id == ESP_AVRC_MD_ATTR_ARTIST) {
|
||||
currentArtist = (char*)text;
|
||||
updated = true;
|
||||
} else {
|
||||
Serial.printf("[WARNING] Unsupported AVRCP metadata id: %u\n", id);
|
||||
}
|
||||
|
||||
if (updated && bluetoothConnected && musicPlaying) {
|
||||
|
|
@ -201,6 +203,8 @@ void volume_changed_callback(int volume) {
|
|||
void audio_state_changed_callback(esp_a2d_audio_state_t state, void *) {
|
||||
// 音声が流れ始めたかどうかを保存し、LEDと画面を更新します。
|
||||
musicPlaying = state == ESP_A2D_AUDIO_STATE_STARTED;
|
||||
Serial.printf("[INFO] Audio state changed: %d (playing=%s)\n",
|
||||
state, musicPlaying ? "yes" : "no");
|
||||
neoPixelController.setPlaying(musicPlaying);
|
||||
updateDisplay();
|
||||
}
|
||||
|
|
@ -208,6 +212,8 @@ void audio_state_changed_callback(esp_a2d_audio_state_t state, void *) {
|
|||
void connection_state_changed_callback(esp_a2d_connection_state_t state, void *) {
|
||||
// スマートフォンとの接続状態を保存します。
|
||||
bluetoothConnected = state == ESP_A2D_CONNECTION_STATE_CONNECTED;
|
||||
Serial.printf("[INFO] A2DP connection state changed: %d (connected=%s)\n",
|
||||
state, bluetoothConnected ? "yes" : "no");
|
||||
if (!bluetoothConnected) {
|
||||
musicPlaying = false;
|
||||
}
|
||||
|
|
@ -217,6 +223,7 @@ void connection_state_changed_callback(esp_a2d_connection_state_t state, void *)
|
|||
void setup() {
|
||||
// setupは、電源を入れた直後に1回だけ実行されます。
|
||||
Serial.begin(115200);
|
||||
Serial.println("[INFO] Firmware starting");
|
||||
|
||||
neoPixelController.begin(18);
|
||||
|
||||
|
|
@ -237,6 +244,9 @@ void setup() {
|
|||
u8g2.begin();
|
||||
u8g2.enableUTF8Print(); // UTF-8(日本語)描画を有効化
|
||||
oledReady = true;
|
||||
Serial.printf("[INFO] OLED detected at 0x%02X\n", oledAddress);
|
||||
} else {
|
||||
Serial.println("[WARNING] OLED not detected at 0x3C or 0x3D");
|
||||
}
|
||||
|
||||
sensorLogger.begin(32);
|
||||
|
|
@ -262,6 +272,7 @@ void setup() {
|
|||
|
||||
// Bluetoothスピーカーとして起動します。
|
||||
a2dp_sink.start(kA2dpDeviceName);
|
||||
Serial.printf("[INFO] A2DP started as '%s'\n", kA2dpDeviceName);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue