2020/12,江端さんの技術メモ

Tile38

Slack Channel Docker Ready

Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types including lat/lon points, bounding boxes, XYZ tiles, Geohashes, and GeoJSON.

Tile38は、オープンソース(MITライセンス)で、インメモリのジオロケーションデータストア、空間インデックス、リアルタイムジオフェンスです。緯度/経度ポイント、バウンディングボックス、XYZタイル、Geohash、GeoJSONを含む様々なオブジェクトタイプをサポートしています。

This README is quick start document. You can find detailed documentation at https://tile38.com.

このREADMEはクイックスタートのドキュメントです。詳細なドキュメントはhttps://tile38.com.

Nearby Within Intersects Geofencing Roaming Geofences

Features

特徴

Components

  • tile38-server - The server → サーバ
  • tile38-cli - Command line interface tool → コマンドインターフェースツール
  • tile38-benchmark - Server benchmark tool → サーバベンチマークツール

Getting Started

はじめに

Getting Tile38

タイル38の取得

Perhaps the easiest way to get the latest Tile38 is to use one of the pre-built release binaries which are available for OSX, Linux, FreeBSD, and Windows. Instructions for using these binaries are on the GitHub releases page. → 最新のTile38を入手する最も簡単な方法は、OSX、Linux、FreeBSD、Windows用に提供されているビルド済みのリリースバイナリを使用することでしょう。これらのバイナリの使い方は、GitHub release pageにあります。

Docker

To run the latest stable version of Tile38:→Tile38の最新の安定版を実行する。

docker pull tile38/tile38
docker run -p 9851:9851 tile38/tile38

Visit the Tile38 hub page for more information. → 詳しくはTile38ハブページをご覧ください。

Homebrew (macOS)

Install Tile38 using Homebrew →Homebrew](https://brew.sh/)を使ってTile38をインストールします。

brew install tile38
tile38-server

Building Tile38

タイル38の構築

Tile38 can be compiled and used on Linux, OSX, Windows, FreeBSD, and probably others since the codebase is 100% Go. We support both 32 bit and 64 bit systems. Go must be installed on the build machine.

Tile38は、コードベースが100%Goなので、Linux、OSX、Windows、FreeBSD、そしておそらく他のOSでもコンパイルして使うことができます。32ビットと64ビットの両方をサポートしています。ビルドマシンにはGoがインストールされている必要があります。

To build everything simply:

すべてをシンプルに構築する為に

$ make

To test:

$ make test

Running

実行

For command line options invoke: コマンドラインオプションの場合は、次を呼び出します。

$ ./tile38-server -h

To run a single server:

$ ./tile38-server

# The tile38 shell connects to localhost:9851
$ ./tile38-cli
> help

Playing with Tile38

Basic operations: 基本操作:

$ ./tile38-cli

# add a couple of points named 'truck1' and 'truck2' to a collection named 'fleet'.
#「fleet」という名前のコレクションに「truck1」および「truck2」という名前のポイントをいくつか追加します。
> set fleet truck1 point 33.5123 -112.2693   # on the Loop 101 in Phoenix
> set fleet truck2 point 33.4626 -112.1695   # on the I-10 in Phoenix

# search the 'fleet' collection.
#「フリート」コレクションを検索します。
> scan fleet                                 # returns both trucks in 'fleet'
> nearby fleet point 33.462 -112.268 6000    # search 6 kilometers around a point. returns one truck.

# key value operations
# キー値操作
> get fleet truck1                           # returns 'truck1'
> del fleet truck2                           # deletes 'truck2'
> drop fleet                                 # removes all 

Tile38 has a ton of great commands. Tile38にはたくさんの[すばらしいコマンド](https://tile38.com/commands)があります。

Fields

フィールド

Fields are extra data that belongs to an object. A field is always a double precision floating point. There is no limit to the number of fields that an object can have.

フィールドは、オブジェクトに属する追加のデータです。 フィールドは常に倍精度浮動小数点です。 オブジェクトが持つことができるフィールドの数に制限はありません。

To set a field when setting an object: オブジェクトを設定するときにフィールドを設定するには:

> set fleet truck1 field speed 90 point 33.5123 -112.2693             
> set fleet truck1 field speed 90 field age 21 point 33.5123 -112.2693

To set a field when an object already exists: オブジェクトがすでに存在するときにフィールドを設定するには:

> fset fleet truck1 speed 90

Searching

検索

Tile38 has support to search for objects and points that are within or intersects other objects. All object types can be searched including Polygons, MultiPolygons, GeometryCollections, etc.

Tile38は、他のオブジェクト内または他のオブジェクトと交差するオブジェクトおよびポイントの検索をサポートしています。 Polygons、MultiPolygons、GeometryCollectionsなどを含むすべてのオブジェクトタイプを検索できます。

Search Within

Within

WITHIN searches a collection for objects that are fully contained inside a specified bounding area. WITHINは、指定された境界領域内に完全に含まれているオブジェクトをコレクションで検索します。

Search Intersects

Intersects

INTERSECTS searches a collection for objects that intersect a specified bounding area.

Search Nearby

Nearby

NEARBY searches a collection for objects that intersect a specified radius. INTERSECTSは、指定された境界領域と交差するオブジェクトをコレクションで検索します。

Search options

検索オプション

SPARSE - This option will distribute the results of a search evenly across the requested area.

** SPARSE **-このオプションは、検索結果を要求された領域全体に均等に分散します。

This is very helpful for example; when you have many (perhaps millions) of objects and do not want them all clustered together on a map. Sparse will limit the number of objects returned and provide them evenly distributed so that your map looks clean.

これは、非常に役立ちます。 多数(おそらく数百万)のオブジェクトがあり、それらすべてをマップ上にクラスター化したくない場合。 スパースは、返されるオブジェクトの数を制限し、マップがきれいに見えるようにそれらを均等に分散させます。

You can choose a value between 1 and 8. The value 1 will result in no more than 4 items. The value 8 will result in no more than 65536. 1=4, 2=16, 3=64, 4=256, 5=1024, 6=4098, 7=16384, 8=65536.

1から8までの値を選択できます。値1は、4つ以下のアイテムになります。 値8は、65536以下になります。* 1 = 4、2 = 16、3 = 64、4 = 256、5 = 1024、6 = 4098、7 = 16384、8 =65536。*

>

No SparsingSearch WithinSparse 1Search WithinSparse 2Search WithinSparse 3Search WithinSparse 4Search WithinSparse 5Search Within

Please note that the higher the sparse value, the slower the performance. Also, LIMIT and CURSOR are not available when using SPARSE.

スパース値が高いほど、パフォーマンスが低下することに注意してください。 また、SPARSEを使用している場合、LIMITとCURSORは使用できません。

WHERE - This option allows for filtering out results based on field values. For example
nearby fleet where speed 70 +inf point 33.462 -112.268 6000 will return only the objects in the 懼fleet懼 collection that are within the 6 km radius and have a field named speed that is greater than 70.

Multiple WHEREs are concatenated as and clauses. WHERE speed 70 +inf WHERE age -inf 24 would be interpreted as speed is over 70 and age is less than 24.

The default value for a field is always 0. Thus if you do a WHERE on the field speed and an object does not have that field set, the server will pretend that the object does and that the value is Zero.

WHERE - このオプションは、fieldの値に基づいて結果をフィルタリングすることができます。例えば
`nearby fleet where speed 70 +inf point 33.462 -112.268 6000````は、半径6km以内にあるオブジェクトのみを返します。<br><br>複数のWHEREは**and**句として連結されます。<br><br>フィールドのデフォルト値は常に0です。したがって、フィールドspeed` の WHERE を実行したときに、オブジェクトにそのフィールドが設定されていない場合、サーバーはオブジェクトが設定されていて、その値がゼロであるかのように振舞うことになります。

MATCH - MATCH is similar to WHERE except that it works on the object id instead of fields.
nearby fleet match truck* point 33.462 -112.268 6000 will return only the objects in the 懼fleet懼 collection that are within the 6 km radius and have an object id that starts with truck. There can be multiple MATCH options in a single search. The MATCH value is a simple glob pattern.

nearby fleet match truck* point 33.462 -112.268 6000は、半径6km以内にある懼fリート懼コレクションのオブジェクトのうち、かつtruckで始まるオブジェクトIDを持つものだけを返します。1つの検索で複数のMATCHオプションを指定することができます。MATCHの値は単純なglob patternです。

CURSOR - CURSOR is used to iterate though many objects from the search results. An iteration begins when the CURSOR is set to Zero or not included with the request, and completes when the cursor returned by the server is Zero.

CURSOR - CURSORは、検索結果から多くのオブジェクトを繰り返し処理するために使用されます。CURSORが0に設定されているか、リクエストに含まれていない場合には反復処理が開始され、サーバから返されたカーソルが0になった時点で終了します。

NOFIELDS - NOFIELDS tells the server that you do not want field values returned with the search results.

NOFIELDS - NOFIELDSは、検索結果で返されるフィールド値を望まないことをサーバーに伝えます。

LIMIT - LIMIT can be used to limit the number of objects returned for a single search request.

LIMIT - LIMITは、1つの検索リクエストに対して返されるオブジェクトの数を制限するために使用することができます。

Geofencing

ジオフェンシング

Geofence animation A geofence is a virtual boundary that can detect when an object enters or exits the area. This boundary can be a radius, bounding box, or a polygon. Tile38 can turn any standard search into a geofence monitor by adding the FENCE keyword to the search.

ジオフェンスは、物体がその領域に入ったり出たりしたときに検出できる仮想的な境界です。この境界は、半径、境界ボックス、または多角形にすることができます。Tile38は、検索にFENCEキーワードを追加することで、標準的な検索をジオフェンスモニタに変えることができます。

Tile38 also allows for Webhooks to be assigned to Geofences.

*Tile38では、ジオフェンスにWebhooksを割り当てることもできます。

 

A simple example:

簡単な例です。

> nearby fleet fence point 33.462 -112.268 6000

This command opens a geofence that monitors the 懼fleet懼 collection. The server will respond with:

このコマンドは 懼fリート懼 コレクションを監視するジオフェンスを開きます。サーバは以下のように応答します。

{"ok":true,"live":true}

And the connection will be kept open. If any object enters or exits the 6 km radius around 33.462,-112.268 the server will respond in realtime with a message such as:

また、接続はオープンに保たれます。33.462,-112.268` 付近の半径6kmの範囲に何か物体が出入りすると、サーバはリアルタイムで次のようなメッセージを返します。

{"command":"set","detect":"enter","id":"truck02","object":{"type":"Point","coordinates":[-112.2695,33.4626]}}

The server will notify the client if the command is del | set | drop.

サーバは commanddel | set | drop の場合にクライアントに通知する。

  • del notifies the client that an object has been deleted from the collection that is being fenced.
  • del` は、フェンシングされているコレクションからオブジェクトが削除されたことをクライアントに通知します。
  • drop notifies the client that the entire collection is dropped.
  • drop` はコレクション全体が削除されたことをクライアントに通知する。
  • set notifies the client that an object has been added or updated, and when it懼s position is detected by the fence.
  • set` はオブジェクトが追加または更新されたことをクライアントに通知し、フェンスによってその位置が検出されたときにそのことを通知します。

The detect may be one of the following values.

detect` は以下の値のいずれかである。

  • inside is when an object is inside the specified area.
  • inside` はオブジェクトが指定された領域の内側にあるときのことである。
  • outside is when an object is outside the specified area.
  • outside` は、オブジェクトが指定された領域の外にあるときのことである。
  • enter is when an object that was not previously in the fence has entered the area.
  • enter`は、それまで柵の中に**なかったオブジェクトがエリア内に入ってきたときのことである。
  • exit is when an object that was previously in the fence has exited the area.
  • exit`は、以前にフェンスの中にあった***オブジェクトがエリア外に出たときのことである。
  • cross is when an object that was not previously in the fence has entered and exited the area.
  • クロス`とは、それまで柵の中になかったオブジェクトがエリアに入ってきて**エリアから出てきたときのことである。

These can be used when establishing a geofence, to pre-filter responses. For instance, to limit responses to enter and exit detections:

これらは、ジオフェンスを確立する際に、応答を事前にフィルタリングするために使用することができます。例えば、enterexit の検出に対して応答を制限することができます。

> nearby fleet fence detect enter,exit point 33.462 -112.268 6000

Pub/sub channels

パブ/サブチャンネル

Tile38 supports delivering geofence notications over pub/sub channels.

Tile38は、パブ/サブチャンネル上のジオフェンス通知の配信をサポートしています。

To create a static geofence that sends notifications when a bus is within 200 meters of a point and sends to the busstop channel:

バスがポイントから200メートル以内にいるときに通知を送信し、busstopチャンネルに送信する静的ジオフェンスを作成します。

> setchan busstop nearby buses fence point 33.5123 -112.2693 200

Subscribe on the busstop channel:

バストップチャンネルを購読してください。

> subscribe busstop

Object types

オブジェクトの種類

All object types except for XYZ Tiles and QuadKeys can be stored in a collection. XYZ Tiles and QuadKeys are reserved for the SEARCH keyword only.

XYZ TilesとQuadKeyを除くすべてのオブジェクトタイプは、コレクションに格納することができます。XYZ TilesとQuadKeyは、SEARCHキーワードのみに予約されています。

Lat/lon point

ラット/ロングポイント

The most basic object type is a point that is composed of a latitude and a longitude. There is an optional z member that may be used for auxiliary data such as elevation or a timestamp.

最も基本的なオブジェクト型は緯度と経度からなる点である。オプションの z メンバがあり、標高やタイムスタンプなどの補助データに使用することができます。

set fleet truck1 point 33.5123 -112.2693     # plain lat/lon
set fleet truck1 point 33.5123 -112.2693 225 # lat/lon with z member

Bounding box

バウンディングボックス

A bounding box consists of two points. The first being the southwestern most point and the second is the northeastern most point.

バウンディングボックスは2つの点で構成されています。1つ目は最も南西の点で、2つ目は最も北東の点です。

set fleet truck1 bounds 30 -110 40 -100

Geohash

ジオハッシュ

A geohash is a string representation of a point. With the length of the string indicating the precision of the point.

geohash は、点を文字列で表現したものです。文字列の長さは点の精度を表します。

set fleet truck1 hash 9tbnthxzr # this would be equivalent to 'point 33.5123 -112.2693'

GeoJSON

GeoJSON is an industry standard format for representing a variety of object types including a point, multipoint, linestring, multilinestring, polygon, multipolygon, geometrycollection, feature, and featurecollection.

GeoJSON](https://tools.ietf.org/html/rfc7946)は、点、多点、線条、多線条、多角形、マルチポリゴン、ジオメトリコレクション、フィーチャ、フィーチャコレクションなど、様々なオブジェクトタイプを表現するための業界標準フォーマットです。

* All ignored members will not persist.

* すべての無視されたメンバーは持続しません。

Important to note that all coordinates are in Longitude, Latitude order.

すべての座標は経度、緯度の順になっていることに注意してください。

set city tempe object {"type":"Polygon","coordinates":[[[0,0],[10,10],[10,0],[0,0]]]}

XYZ Tile

XYZタイル

An XYZ tile is rectangle bounding area on earth that is represented by an X, Y coordinate and a Z (zoom) level.

XYZタイルとは、X,Y座標とZ(ズーム)レベルで表現された地球上の矩形領域のことです。

Check out maptiler.org for an interactive example.

インタラクティブな例は maptiler.org をご覧ください。

QuadKey

A QuadKey used the same coordinate system as an XYZ tile except that the string representation is a string characters composed of 0, 1, 2, or 3. For a detailed explanation checkout The Bing Maps Tile System.

QuadKey は XYZ タイルと同じ座標系を使用しますが、文字列表現は 0, 1, 2, 3 で構成される文字列です。詳しい説明は Bing Maps Tile System をご覧ください。

Network protocols

ネットワークプロトコル

It懼s recommended to use a client library or the Tile38 CLI, but there are times when only HTTP is available or when you need to test from a remote terminal. In those cases we provide an HTTP and telnet options.

クライアントライブラリ](#client-libraries)またはTile38 CLIを使用することをお勧めしますが、HTTPしか利用できない場合や、リモート端末からテストする必要がある場合があります。そのような場合には、HTTPとtelnetオプションを用意しています。

HTTP

One of the simplest ways to call a tile38 command is to use HTTP. From the command line you can use curl. For example:

tile38コマンドを呼び出す最も簡単な方法の1つは、HTTPを使用することです。コマンドラインからcurlを使用することができます。例えば、以下のようになります。

# call with request in the body
curl --data "set fleet truck3 point 33.4762 -112.10923" localhost:9851

# call with request in the url path
curl localhost:9851/set+fleet+truck3+point+33.4762+-112.10923

Websockets

ウェブソケット

Websockets can be used when you need to Geofence and keep the connection alive. It works just like the HTTP example above, with the exception that the connection stays alive and the data is sent from the server as text websocket messages.

Websocket は、ジオフェンスして接続を維持する必要がある場合に使用することができます。これは上記の HTTP の例と同じように動作しますが、接続が生きていることと、データがテキストの Websocket メッセージとしてサーバーから送信されることを除いては、動作しません。

Telnet

There is the option to use a plain telnet connection. The default output through telnet is RESP.

プレーンなtelnet接続を使用するオプションがあります。telnetによるデフォルトの出力はRESPです。

telnet localhost 9851
set fleet truck3 point 33.4762 -112.10923
+OK

The server will respond in JSON or RESP depending on which protocol is used when initiating the first command.

サーバは、最初のコマンドを開始するときに使用されるプロトコルに応じて、JSONまたはRESPで応答します。

  • HTTP and Websockets use JSON.
  • HTTPとWebsocketsはJSONを使用しています。
  • Telnet and RESP clients use RESP.
  • Telnet と RESP クライアントは RESP を使用します。

Client Libraries

クライアントライブラリ

Tile38 uses the Redis RESP protocol natively. Therefore most clients that support basic Redis commands will in turn support Tile38. Below are a few of the popular clients.

Tile38はRedis RESPプロトコルをネイティブに使用します。そのため、基本的なRedisコマンドをサポートしているほとんどのクライアントがTile38をサポートしています。以下に人気のあるクライアントをいくつか紹介します。

Contact

連絡先

Josh Baker [@tidwall](https://twitter.com/tidwall)

License

ライセンス

Tile38 source code is available under the MIT License.

Tile38のソースコードはMIT Licenseで公開されています。

2020/12,江端さんの技術メモ

キッチンの蛍光管を交換しても点灯しなくなったことから、どうやら安定器(スターター)が不調になってきているとアタリを付けました。

そもそも、この家を作った時には、LED電球という考え方すらなく、今のように蛍光管の代替となるLED直管ライトなどは、影も形もありませんでした。

で、この機会に、スターターをバイパス(無視)して、LED直管ライトを接続できるように、回路を変更してやろうと思ったのですが、そもそも、蛍光管も、LED直管ライトも、その仕組みがよく分っていません(ネットの情報も、これといったものが見つかりませんでした)。

で、今回、「オーム電機 LED蛍光灯 直管形LEDランプ G13 40形 昼光色 グロー専用 LDF40SS・D/17/23」を使って調べてみました。

https://www.youtube.com/watch?v=ne2NLdvOvSI
 

これで、ざっくりと結線のやり方が分かりました。

 

赤丸のところにマイナスドライバーを差し込むと、配線が外れました。

配線の番号はこのようになっています(ネットで仕様書を調べて、アタリを付けています)

これを、以下のように変更します。電子安定器に接続された結線は、すべて外して(あるいは切断して)下さい。

結線を外す前に配線の番号をタグ付けしておきます。

今回は、半田付けが難しかったので、こういう接合具を使って結線しました。外被を向いた動線を差し込んで、ペンチで金属部を押し潰します。

結線して、点灯を確認しました。

これで、安定器(スターター)は不要となりました。待機電力の消費もなくなるので、少しは節電になるでしょう。

注意事項:LED直管ライトの方向を逆にするとショートします。映像の中で見たように、逆方向は短絡しているからです。結線の中にヒューズを入れておくべきです(私も今、気がつきましたので、後日対応しておきます)。