ESP32 から Ubuntu 24.04 にデータを送信してみました。
ESP32-WROOM-32E と M5StackCore2 で確認しました。
Ubuntu 24.04 上の Arduino IDE 2.3.2 を使いました。
ボードは、 ESP32 Dev Module です。
ESP32 のプログラム
bluetooth_serial.ino
// ---------------------------------------------------------------------
// bluetooth_serial.ino
//
// Feb/10/2023
// ---------------------------------------------------------------------
#include "BluetoothSerial.h"
#define PROGRAM "bluetooth_serial.ino"
#define VERSION "2023-2-10 PM 17:19"
BluetoothSerial SerialBT;
int count = 0;
// ---------------------------------------------------------------------
void setup()
{
SerialBT.begin("ESP32test_01"); //Bluetooth device name
}
// ---------------------------------------------------------------------
void loop()
{
SerialBT.printf("count = %d\r\n",count);
delay(1000);
SerialBT.println("Good Morning!");
delay(1000);
SerialBT.println("Good Afternoon!");
delay(1000);
SerialBT.println(PROGRAM);
SerialBT.println(VERSION);
SerialBT.println();
delay(1000);
count++;
}
// ---------------------------------------------------------------------
Ubuntu の操作
デバイスのスキャン
$ hcitool scan
Scanning ...
8C:4B:14:16:B8:6E ESP32test_01
デバイスに対して ping をうつ
$ sudo l2ping -c 3 8C:4B:14:16:B8:6E
Ping: 8C:4B:14:16:B8:6E from 3C:21:9C:50:7C:46 (data size 44) ...
0 bytes from 8C:4B:14:16:B8:6E id 0 time 7.63ms
0 bytes from 8C:4B:14:16:B8:6E id 1 time 5.84ms
0 bytes from 8C:4B:14:16:B8:6E id 2 time 5.89ms
3 sent, 3 received, 0% loss
デバイスの確認
$ sdptool browse 8C:4B:14:16:B8:6E
Browsing 8C:4B:14:16:B8:6E ...
Service Name: ESP32SPP
Service RecHandle: 0x10000
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
Profile Descriptor List:
"Serial Port" (0x1101)
Version: 0x0102
ポートの割りつけ
sudo rfcomm bind 1 8C:4B:14:16:B8:6E
ポートの状態の確認
$ sudo rfcomm
rfcomm1: 8C:4B:14:16:B8:6E channel 1 clean
シリアル接続
$ cu -l /dev/rfcomm1 -s 115200
Connected.
bluetooth_serial.ino
2023-2-10 PM 17:19
count = 9
Good Morning!
Good Afternoon!
bluetooth_serial.ino
2023-2-10 PM 17:19
count = 10
Good Morning!
Good Afternoon!
bluetooth_serial.ino
2023-2-10 PM 17:19
ポートの開放
sudo rfcomm release 1