TL;DR
Android nRF Connect ã® BLE ãã¯ãã®ãµãã»ããã macOS/iOS/... ä¸ã§éçºããç°å¢ãç¨æãã¾ããã
import Foundation import BLEMacroEasy // You can find your iPhone's UUID by running the following command in Terminal: // $ git clone https://github.com/Kuniwak/swift-ble-macro // $ cd swift-ble-macro // $ swift run ble discover let myIPhoneUUID = UUID(uuidString: "********-****-****-****-************")! let myMacro = try String(contentsOf: URL(string: "https://ble-macro.kuniwak.com/iphone/battery-level.xml")!) try await run(macroXMLString: myMacro, on: myIPhoneUUID) { data in // This handler is called when every value read from the peripheral. let batteryLevel = Int(data[0]) print("\(batteryLevel)%") }
macOS/iOS/... ä¸ã§ BLE ãã¯ããå®è¡ããæ©è½ã®ã»ããã¯ãã®éçºãå©ãã CLI ãæä¾ãã¦ãã¾ããBLE ãã¯ãå®è¡æ©è½ã«ã¤ãã¦ã¯ README ãè¦ã¦ãã ãããCLI 㯠BLE ããã¤ã¹ã®ã¹ãã£ã³ããã¯ãã®ããªãã¼ã·ã§ã³ããã¯ãã®å®è¡ã対話çãªãã¯ãå®è¡ããµãã¼ããã¦ãã¾ãï¼
$ # BLE ããã¤ã¹ãã¹ãã£ã³ãã $ ble discover 00000000-0000-0000-0000-000000000000 Example Device 1 -78 11111111-1111-1111-1111-111111111111 Example Device 2 -47 22222222-2222-2222-2222-222222222222 Example Device 3 -54 ... $ # Ctrl+C ã§ã¹ãã£ã³ãä¸æãã $ # BLE ãã¯ããå®è¡ãã $ ble run path/to/your/ble-macro.xml --uuid 00000000-0000-0000-0000-000000000000 $ # BLE ãã¯ãã対話çã«å®è¡ãã $ ble repl --uuid 00000000-0000-0000-0000-000000000000 connecting... connected (ble) ? write-command, w, wc Write to a characteristic without a response write-descriptor, wd Write to a descriptor write-request, req Write to a characteristic with a response read, r Read from a characteristic discovery-service, ds Discover services discovery-characteristics, dc Discover characteristics discovery-descriptor, dd Discover descriptors q, quit Quit the REPL (ble) dc 180A 2A29 read 180A 2A24 read D0611E78-BBB4-4591-A5F8-487910AE4366 8667556C-9A37-4C91-84ED-54EE27D90049 write/write/notify/extendedProperties 9FA480E0-4967-4542-9390-D343DC5D04AE AF0BADB1-5B99-43CD-917A-A77BC549E3CC write/write/notify/extendedProperties 180F 2A19 read/notify 1805 2A2B read/notify 1805 2A0F readk (ble) r 180F 2A19 58
ãªãéçºãã BLE ãã¯ã㯠Kuniwak/ble-macro ã§å ¬éãã¦ãã¾ãã
èæ¯
Nature Remo ã« BLEï¼Bluetooth Low Energyï¼ãã¯ãæ©è½ãæè¼ããã¾ããï¼å ¬å¼ã¢ãã¦ã³ã¹ï¼ã対å¿æ©ç¨®ï¼Nature Remo3ãNature Remo mini2 ãã¡ããªã¼ï¼ã® Remo ãã使ããªã BLE ããã¤ã¹ã Remo ããæä½ã§ãã¾ãããã㧠BLE ã§æä½ã§ããæã家㮠Philips Hue ã®ãã«ã«ã©ã¼é»çx3ã Remo ããæä½ãã¹ã BLE ãã¯ãã®éçºãå§ãã¾ããï¼ç¡é§ã«ãã«ã«ã©ã¼ãªã®ã¯ãã®åç»ãè¦ã¦æ·¡ãæ§ãããã£ãããï¼ã
Remo ã®ãµãã¼ããã¦ãã BLE ãã¯ã㯠Android nRF Connect ã®ãµãã»ããã§ãããã¯ã㯠XML ã§è¨è¿°ãã¾ããä¾ãã° Hue ãç½æ¼è²ã§ç¹ç¯ãããã«ã¯æ¬¡ã®ããã«è¨è¿°ãã¾ãï¼
<macro name="hue-daylight-white" icon="BRIGHTNESS_HIGH"> <assert-service description="Hue" uuid="932c32bd-0000-47a2-835a-a8d455b859dd"> <assert-characteristic description="Combined" uuid="932c32bd-0007-47a2-835a-a8d455b859dd"> <property name="WRITE" requirement="MANDATORY"/> </assert-characteristic> </assert-service> <write description="Set to Daylight White" characteristic-uuid="932c32bd-0007-47a2-835a-a8d455b859dd" service-uuid="932c32bd-0000-47a2-835a-a8d455b859dd" value="0101010201fe0302fa0005020100" type="WRITE_REQUEST" /> </macro>
BLE ãã¯ãã§ã¯ service ã characteristic ã¨ããæä½çªå£ã§å¤ã®èªã¿æ¸ããæ示ã§ãã¾ããæåãªããã¤ã¹ãªãã°ããã㯠第ä¸è ã«ããä»æ§ã®æ¨æ¸¬ ã§ããç¨åº¦è©³ç´°ããããã¾ãããã ãã¯ããè¨è¿°ã㦠Remo ã§åä½ããç¶æ ã«æã£ã¦ããã¾ã§ã«ã¯ãããªãã«è©¦è¡é¯èª¤ãå¿ è¦ã«ãªãã¾ãããã®è©¦è¡é¯èª¤ãã¨ã«ããè¦è¡ã§ããã
å ¬å¼æ°ã Android ãªã nRF Connect for Mobile ã¢ããªã§ BLE ãã¯ãã®è¨é²ããå®è¡ã¾ã§ããµãã¼ããã¦ããããã楽ã«ãã¯ããéçºã§ããããã§ãããããæå ã«ã¯ Android 端æ«ãããã¾ããã§ãããiOS ç¨ã«åãéçºè ã® ååã®ã¢ã㪠ãããã¾ããããã«ã¯ãã¯ãæ©è½ãã¤ãã¦ãã¾ããããã®ããæåã®é 㯠Remo ã« BLE ãã¯ããé£ã¹ããã¦ã¿ã¦çç±ã®ã»ã¨ãã©ããããªãã¨ã©ã¼ã«ç´é¢ãã¦ãBLE ãã¯ããåã§æ¸ãæãã¦â¦ã¨ãããµã¤ã¯ã«ãåãã¦ãã¾ããã
ãã®ãµã¤ã¯ã«ããã¾ãã«ä¸æ¯ã§ãã£ããã Android ã® nRF Connect for Mobile ã¨åæ§ã®æ©è½ããã¤ç°å¢ããªãã¨ãæ´ããããªããã¨æã Kuniwak/swift-ble-macro ãéçºãã¾ãããnRF Connect for Mobile ãããå¤§å¹ ã«æ©è½ã¯å°ãªãã§ãããRemo ã§åä½ãã BLE ãã¯ããéçºããã«ã¯ååãªæ©è½ãæã£ã¦ãã¾ãããã²ãæ´»ç¨ãã ããã
ãªãBLE ãã¯ããéçºããã«ã¯æ¢åã®ã¢ããªãã©ããªéä¿¡ã BLE ããã¤ã¹ã¨ãã¦ãããããã£ããã£ãããã¨ãéè¦ã§ãã詳ããã¯æ¬¡ã®ããã°ãèªãã¨ããæ¹ããããã§ãããï¼
BLE ãã¯ããéçºããéã®è¦å´
Hue ã Switchbot ã§ãã¾ãã¾ãªè¦å´ãããã®ã§ããã§ä¾é¤ãã¦ããã¾ãã
Hue ãã insufficient encryption ã¨ã©ã¼ãè¿ã£ã¦ãã
Hue ã¯ãã¢ãªã³ã°ããªãã¨æä½ã§ããªãããã§ãããã¢ãªã³ã°ãã¦ããªã central ãã read/write ãããã¨ãã㨠insufficient encryption ã¨ã©ã¼ãçºçãã¾ãããªããã¢ãªã³ã°ãããã®ã¯æåã«ãã¢ãªã³ã°ãããããã¤ã¹ã®ã¿ã§ãï¼å¾è¿°ããæ¹æ³ã§ãããåé¿ã§ããï¼ãä¾ãã°ååã« Hue ã®ã¢ããªã§æ¥ç¶ãã¦ãã¾ãã¨ãã以éã®ããã¤ã¹ï¼e.g. RemoãGoogle Nest miniï¼ããã¯æä½ãåãä»ãã¦ãããªããªã£ã¦ãã¾ãã¾ãããããåé¿ããã«ãã¢ãªã³ã°ãã¦ãã Hue ã®å
¬å¼ã¢ã㪠> è¨å® > é³å£°ã¢ã·ã¹ã¿ã³ã > Google Home > æ¤åºå¯è½ã«ãããã®æä½ãå¿
è¦ã§ãããã®æä½ã«ãã£ã¦ããçæéï¼1minã»ã©ï¼ï¼ãã¢ãªã³ã°ãåãä»ãã¦ãããããã«ãªãã¾ãããã㯠service 0000fe0f-0000-1000-8000-00805f9b34fb
ã® characteristic 97fe6561-2004-4f62-86e9-b71ee2da3d22
ã« 0x01
ãæ¸ãè¾¼ããã¨ã§åç¾ã§ãã¾ãï¼æ¤åºå¯è½ã«ãã BLE ãã¯ãï¼ã
ãã¢ãªã³ã°ãæãã Hue ã®ãã¡ã¯ããªãªã»ããæ¹æ³ãããããªã
å ¬å¼ã¢ããªã Mac ãªã©ã«ãã¢ãªã³ã°ããåã« Google Nest mini ãªã©ã«ãã¢ãªã³ã°ããã¦ãã¾ãã¨åè¿°ã® insufficient encryption åé¡ã«ãã£ã¦å ¬å¼ã¢ããªã Mac ãªã©ããæä½ãã§ããªããªãã¾ãããã¡ã¯ããªãªã»ãã㯠BLE ã«ããæä½ã§å®ç¾ããã¦ããããå ¬å¼ã¢ããªããã¢ãªã³ã°ããã¦ããªãç¶æ³ã§ã¯ãã¡ã¯ããªãªã»ãããå¿ è¦ã«ãªãã¾ãã
Hue ããã¡ã¯ããªãªã»ããããæ¹æ³ã¨ãã¦ç¹ç¯ã¨æ¶ç¯ã®ãµã¤ã¯ã«ãåãæ¹æ³ãç´¹ä»ããã¦ãã¾ãããããç§ã® Hueï¼ã¢ãã« LCA009ããã¡ã¼ã ã¦ã§ã¢ãã¼ã¸ã§ã³ v1.116.3ï¼ã§ã¯ãã¾ãåãã¾ããã§ããã代ããã«ãHue ã®é»æºãå£é¢ã®ã¹ã¤ããçããè½ã¨ãã¦ããåã³é»æºãå ¥ããã¨ãããçæé & ããªãã®è¿è·é¢ã§ããã° Hue ã®å ¬å¼ã¢ããªã§æ¤åºå¯è½ã«ãªããã¨ãçºè¦ãã¾ããããããããã¡ã¯ããªãªã»ãããã§ãã¾ããã
Switchbot ãæä½ãããã¨ãã¦ãåå¿ããªã
Switchbot ã BLE ã«ãã£ã¦æä½ãã§ããããã¤ã¹ã§ãããã ããã¤ããªããªãã®æ²è
ã§ããv6.6 ãªã Discord ã®éçºè
ã³ãã¥ããã£ã«ç´¹ä»ããã¦ãããã¯ã ã§æä½ãã§ããã®ã§ãã v6.3 ã§ã¯æä½ãåãä»ãã¦ããã¾ããã試è¡é¯èª¤ãã¦ãããã¡ v6.3 ã§ã characteristic cba20002-224d-11e6-9fb8-0002a5d5c51b
ã« 0x01 ãæ¸ãè¾¼ãåã« cba20003-224d-11e6-9fb8-0002a5d5c51b
ã§éç¥ã®è³¼èªãããã¨çªãåããã¨ãçºè¦ãã¾ãããã¨ãããã¨ã§ v6.3 ã§åããã¯ãã¯ä»¥ä¸ã«ãªãã¾ãï¼
<macro name="switchbot-push" icon="PLAY"> <assert-service description="Switchbot" uuid="cba20d00-224d-11e6-9fb8-0002a5d5c51b"> <assert-characteristic description="Push" uuid="cba20002-224d-11e6-9fb8-0002a5d5c51b"> <property name="WRITE" requirement="MANDATORY"/> </assert-characteristic> <assert-characteristic description="Configuration" uuid="cba20003-224d-11e6-9fb8-0002a5d5c51b"> <property name="NOTIFY" requirement="MANDATORY"/> <assert-cccd /> </assert-characteristic> </assert-service> <write-descriptor description="Enable notifications" characteristic-uuid="cba20003-224d-11e6-9fb8-0002a5d5c51b" service-uuid="cba20d00-224d-11e6-9fb8-0002a5d5c51b" uuid="00002902-0000-1000-8000-00805f9b34fb" value="0100" /> <write description="Write 0x570100" characteristic-uuid="cba20002-224d-11e6-9fb8-0002a5d5c51b" service-uuid="cba20d00-224d-11e6-9fb8-0002a5d5c51b" value="570100" type="WRITE_REQUEST" /> <wait-for-notification description="Wait for notification" characteristic-uuid="cba20003-224d-11e6-9fb8-0002a5d5c51b" service-uuid="cba20d00-224d-11e6-9fb8-0002a5d5c51b" timeout="5000" /> </macro>
ãä¸è©±ã«ãªã£ã製åã»æç®
æå¾ã«ãä¸è©±ã«ãªã£ã製åã»æç®ãç´¹ä»ãã¾ãï¼