{"id":12026,"date":"2026-02-09T12:00:48","date_gmt":"2026-02-09T03:00:48","guid":{"rendered":"https:\/\/www.moonmile.net\/blog\/?p=12026"},"modified":"2026-02-09T11:33:39","modified_gmt":"2026-02-09T02:33:39","slug":"cocoa-%e5%8f%97%e4%bf%a1%ef%bc%88en-api-%e4%bb%95%e6%a7%98%ef%bc%89%e3%81%ae%e5%ae%9f%e9%9a%9b-windows-c-%e7%89%88","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/12026","title":{"rendered":"COCOA \u53d7\u4fe1\uff08EN API \u4ed5\u69d8\uff09\u306e\u5b9f\u969b Windows + C# \u7248"},"content":{"rendered":"\n<p>\u65e2\u306b COCOA \u3082\u5ec3\u6b62\u306b\u306a\u3063\u3066\u3044\u3066\u3001\u5b9f\u6e2c\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u306e\u3067\u3059\u304c\u3001EN API \u306e\u30a2\u30c9\u30d0\u30bf\u30a4\u30ba\u53d7\u4fe1\u6a5f\u3082 Windows + C# \u3067\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002\u5f53\u6642\u306f Android \u3092\u4f7f\u3063\u3066\u53d7\u4fe1\u3055\u305b\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001iBeacon \u306e\u53d7\u4fe1\u6a5f\u3068\u540c\u3058\u3088\u3046\u306b Windows \u3067\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-28.png\"><img loading=\"lazy\" decoding=\"async\" width=\"792\" height=\"277\" src=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-28.png\" alt=\"\" class=\"wp-image-12027\" srcset=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-28.png 792w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-28-300x105.png 300w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-28-768x269.png 768w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><\/a><\/figure>\n\n\n\n<p>\u96fb\u6587\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u304c\u308f\u304b\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u53d7\u4fe1\u30c7\u30fc\u30bf\u3092\u89e3\u6790\u3059\u308c\u3070\u3088\u3044\u3060\u3051\u3067\u3059\u3002iBeacon \u3068\u306f\u9055\u3063\u3066\u300116 bit \u306e\u30b5\u30fc\u30d3\u30b9 UUID\uff080xFD6F\uff09\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u9078\u5225\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d7\u4fe1\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Windows.Devices.Bluetooth.Advertisement;\nusing Windows.Storage.Streams;\n\n\/\/ BLE\u306e\u30b9\u30ad\u30e3\u30ca\nBluetoothLEAdvertisementWatcher watcher;\n\nMain(args);\n\nvoid Main(string&#x5B;] args)\n{\n    Console.WriteLine(&quot;COCOA Check&quot;);\n    watcher = new BluetoothLEAdvertisementWatcher()\n    {\n        ScanningMode = BluetoothLEScanningMode.Passive\n    };\n    \/\/ \u30b9\u30ad\u30e3\u30f3\u3057\u305f\u3068\u304d\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u8a2d\u5b9a\n    watcher.Received += Watcher_Received;\n    \/\/ \u30b9\u30ad\u30e3\u30f3\u958b\u59cb\n    watcher.Start();\n    \/\/ \u30ad\u30fc\u304c\u62bc\u3055\u308c\u308b\u307e\u3067\u5f85\u3064\n    Console.WriteLine(&quot;Press any key to continue&quot;);\n    Console.ReadLine();\n}\n\nvoid Watcher_Received(\n    BluetoothLEAdvertisementWatcher sender,\n    BluetoothLEAdvertisementReceivedEventArgs args)\n{\n\n    var uuids = args.Advertisement.ServiceUuids;\n    var mac = string.Join(&quot;:&quot;,\n                BitConverter.GetBytes(args.BluetoothAddress).Reverse()\n                .Select(b =&gt; b.ToString(&quot;X2&quot;))).Substring(6);\n    var rssi = args.RawSignalStrengthInDBm;\n    var time = args.Timestamp.ToString(&quot;yyyy\/MM\/dd HH:mm:ss.fff&quot;);\n    \n    if (uuids.Count == 0) return;\n    \/\/ 0xFD6F \u306f Exposure Notification \u306e\u30b5\u30fc\u30d3\u30b9UUID\n    if (uuids.FirstOrDefault(t =&gt; t.ToString() == &quot;0000fd6f-0000-1000-8000-00805f9b34fb&quot;) == Guid.Empty) return;\n\n    foreach (var it in args.Advertisement.DataSections)\n    {\n        if ( it.DataType == 0x16 &amp;&amp; it.Data.Length &gt;= 2 + 16)\n        {\n            byte&#x5B;] data = new byte&#x5B;it.Data.Length];\n            DataReader.FromBuffer(it.Data).ReadBytes(data);\n            if ( data&#x5B;0] == 0x6f &amp;&amp; data&#x5B;1] == 0xfd)\n            {\n                byte&#x5B;] rpi = data&#x5B;2..18];\n                Console.WriteLine($&quot;{time} &#x5B;{tohex(rpi)}] {rssi} dBm {mac}&quot;);\n            }\n        }\n    }\n\n    string tohex( byte&#x5B;] data )\n    {\n        return BitConverter.ToString(data).Replace(&quot;-&quot;, &quot;&quot;).ToLower();\n    }\n}\n<\/pre><\/div>\n\n\n<p>1. args.Advertisement.ServiceUuids \u3067 Service UUID 0xFD6F \u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<br>2. args.Advertisement.DataSections \u3067 AD Type 0x16\uff08Service Data &#8211; 16-bit UUID\uff09\u3092\u63a2\u3057\u307e\u3059\u3002<br>3. DataSections(Service Data) \u304b\u3089 Service Data UUID 0xFD6F \u3092\u63a2\u3057\u51fa\u3057\u307e\u3059\u3002<br>4. \u898b\u3064\u304b\u3063\u305f Service Data \u304b\u3089 RPI \u60c5\u5831\u3092\u53d6\u308a\u51fa\u3057\u307e\u3059<\/p>\n\n\n\n<p>BluetoothLEAdvertisementWatcher \u3067\u53d7\u4fe1\u3059\u308b\u3068\u304d\u306b\u3001args.Advertisement.ServiceUuids \u3068\u304b args.Advertisement.DataSections \u306e\u3088\u3046\u306b\u8907\u6570\u306e Service UUID \u304c\u53d6\u308c\u308b\u3088\u3046\u306a\u611f\u3058\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001BLE \u30a2\u30c9\u30d0\u30bf\u30a4\u30ba\u306f 32 bytes \u307e\u3067\u3057\u304b\u306a\u3044\u306e\u3067\u3001\u5b9f\u8cea 1 \u3064\u3057\u304b\u9001\u308c\u307e\u305b\u3093\u3002\u4f55\u6545\u3053\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u62e1\u5f35\u306e\u305f\u3081\u3067\u3057\u3087\u3046\u304b\uff1f\u3000\u78ba\u304b\u3001GATT \u306e\u5834\u5408\u306f Service UUID \u3092\u30da\u30ea\u30d5\u30a7\u30e9\u30eb\u306b\u554f\u3044\u5408\u308f\u305b\u308b\u30e2\u30fc\u30c9\u304c\u3042\u308b\u306e\u3067\u305d\u306e\u305f\u3081\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p>\u3072\u3068\u307e\u305a\u3001Service UUID \u3067\u3042\u308b 0xFD6F \u3092 2 \u56de\u63a2\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u3046\u3044\u3046\u96fb\u6587\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3089\u3067\u3059\u3002Service Data UUID \u306e\u307b\u3046\u306e 0xFD6F \u306f\u81ea\u7531\u306b\u6c7a\u3081\u3089\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u5024\u3058\u3083\u306a\u304f\u3066\u3082\u826f\u3044\u306f\u305a\u306a\u306e\u3067\u3059\u304c\u3001COCOA \u3067\u306f\u3053\u3046\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e 16 bit Service UUID \u3092\u4f7f\u3063\u305f\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f\u3001Bluetooth SIG \u3067 16 bit Company ID \u3092\u6301\u3063\u305f\u4f1a\u793e\u3067\u3042\u308c\u3070\u81ea\u7531\u306b\u4f5c\u308c\u308b\u306e\u3067\u3001iBeacon \u306e\u3088\u3046\u306b\u8272\u3005\u306a\u7528\u9014\u3067\u4f7f\u3048\u307e\u3059\u3002\u6e29\u5ea6\u30bb\u30f3\u30b5\u30fc\u3092\u30a2\u30c9\u30d0\u30bf\u30a4\u30ba\u3067\u767a\u4fe1\u3059\u308b\u3068\u304b\u3001\u4f4d\u7f6e\u60c5\u5831\u3092\u767a\u4fe1\u3059\u308b\u3068\u304b\u3001\u305d\u3046\u3044\u3046\u7528\u9014\u3067\u3059\u3002GATT \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e Notify \u3088\u308a\u3082\u624b\u8efd\u306e\u3067\u3001\u53d7\u4fe1\u5074\u3092\u554f\u308f\u306a\u3051\u308c\u3070\u7d50\u69cb\u4f7f\u3044\u9053\u304c\u3042\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u3044\u307e\u306e\u3068\u3053\u308d\u3042\u307e\u308a\u4f7f\u308f\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u3067\u3059\u3002\u3068\u4e91\u3046\u304b\u3001\u53d7\u4fe1\u6a5f\u3092\u30a2\u30d7\u30ea\u7b49\u3067\u4f5c\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u4f55\u304b\u5c02\u9580\u7528\u9014\u306b\u4f7f\u3063\u3066\u3044\u3066\u3042\u307e\u308a\u5916\u90e8\u6d41\u51fa\u3057\u306a\u3044\u306e\u3067\u3057\u3087\u3046\u3002EN API \u306e\u5834\u5408\u306e\u3088\u3046\u306b\u4e00\u822c\u7684\u306a\u30a2\u30d7\u30ea\u304c\u53d7\u4fe1\u3059\u308b\u3068\u3044\u3046\u30d1\u30bf\u30fc\u30f3\u306f\u73cd\u3057\u3044\u306e\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u53d7\u4fe1\u30c7\u30fc\u30bf\u3092\u5168\u90e8\u898b\u308b\u5834\u5408<\/strong><\/h2>\n\n\n\n<p>Android \u306e\u5834\u5408\u306f ScanCallback \u3092\u4f7f\u3063\u3066\u53d7\u4fe1\u3057\u305f\u751f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001BluetoothLEAdvertisementWatcher \u30af\u30e9\u30b9\u3067\u306f\u751f\u30c7\u30fc\u30bf\u3068\u3044\u3046\u5f62\u3067\u307f\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u305f\u3060\u3057\u3001Advertisement.DataSections \u3092\u4f7f\u3063\u3066\u4e2d\u8eab\u3092\u307f\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059&#8230;\u3068\u3044\u3046\u306e\u306f\u65e2\u306b\u66f8\u3044\u3066\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3059\u3079\u3066\u306e AD \u30bb\u30af\u30b7\u30e7\u30f3\u3092\u8868\u793a\u3059\u308b\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n    \/\/ \u3067\u304d\u308b\u3060\u3051 raw data \u3092\u5168\u90e8\u8868\u793a\u3059\u308b\u5834\u5408\n    foreach (var section in args.Advertisement.DataSections)\n    {\n        byte&#x5B;] buf = new byte&#x5B;section.Data.Length];\n        DataReader.FromBuffer(section.Data).ReadBytes(buf);\n        Console.WriteLine($&quot;AD 0x{section.DataType:X2} len={buf.Length} data={BitConverter.ToString(buf)}&quot;);\n    }\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-30.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"325\" src=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-30-1024x325.png\" alt=\"\" class=\"wp-image-12029\" srcset=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-30-1024x325.png 1024w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-30-300x95.png 300w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-30-768x244.png 768w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-30.png 1074w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nAD 0x01 len=1 data=1A\nAD 0x03 len=2 data=6F-FD\nAD 0x16 len=22 data=6F-FD-01-01-01-01-02-02-02-02-03-03-03-03-04-04-04-04-05-05-05-05\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>AD Type: 1byte<\/li>\n\n\n\n<li>Length: 1byte<\/li>\n\n\n\n<li>Data: n bytes<\/li>\n<\/ul>\n\n\n\n<p>\u3068\u3044\u3046\u5f62\u3067\u3067\u3066\u3044\u308b\u306e\u304c\u826f\u304f\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5b9f\u6e2c\u72b6\u614b<\/strong><\/h2>\n\n\n\n<p>\u3061\u3087\u3063\u3068\u3001m5stack \u3067 COCOA \u767a\u4fe1\u6a5f\u3092\u4f5c\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u305d\u306e\u5f8c\u3067\u3002<br>\u53d7\u4fe1\u3057\u305f\u72b6\u614b\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-31.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"378\" src=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-31-1024x378.png\" alt=\"\" class=\"wp-image-12030\" srcset=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-31-1024x378.png 1024w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-31-300x111.png 300w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-31-768x284.png 768w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2026\/02\/image-31.png 1072w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>RPI \u60c5\u5831\u306f\u9069\u5f53\u306b\u57cb\u3081\u3066\u3042\u308b\u306e\u3067\u3001\u305d\u306e\u30c7\u30fc\u30bf\u304c\u6d41\u308c\u3066\u3044\u307e\u3059\u3002COCOA \u304c\u52d5\u4f5c\u3057\u3066\u3044\u308b\u3068\u3059\u308b\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u3067 RPI \u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e2\u306b COCOA \u3082\u5ec3\u6b62\u306b\u306a\u3063\u3066\u3044\u3066\u3001\u5b9f\u6e2c\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u306e\u3067\u3059\u304c\u3001EN API \u306e\u30a2\u30c9\u30d0\u30bf\u30a4\u30ba\u53d7\u4fe1\u6a5f\u3082 Windows + C# \u3067\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002\u5f53\u6642\u306f Android \u3092\u4f7f\u3063\u3066\u53d7\u4fe1\u3055\u305b\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001iBeacon &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/12026\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,110],"tags":[],"class_list":["post-12026","post","type-post","status-publish","format-standard","hentry","category-dev","category-folkbears"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/12026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=12026"}],"version-history":[{"count":2,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/12026\/revisions"}],"predecessor-version":[{"id":12032,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/12026\/revisions\/12032"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=12026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=12026"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=12026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}