Read and compare command characters with Arduino Ethernet Shield

client.read() returns single byte.
https://www.arduino.cc/reference/en/libraries/ethernet/client.read/

A simple test sketch based on “Chat Server” example.

One gets following Serial monitor after sending a set of characters “ABCD” by, for example, socket.send(“ABCD”.encode(“utf-8”)) in a python script.


カテゴリー: 未分類 | Read and compare command characters with Arduino Ethernet Shield はコメントを受け付けていません

バイナリデータ 文字リテラル 2進数 16進数

python
整数 255 から \xff を示す1バイトのバイナリデータをつくりたい.
そのために bytes.fromhex() に与える16進表示の文字列をつくりたい.
整数が 0~255 の変数のときにどのようにしたらいいか.

bytes.fromhex(hex(255)[2:])
返り値 b\xff
これだと
bytes.fromhex(hex(15)[2:])
ではエラーとなって駄目だ. hex(15)= "0xf" であるため(ふつう 0 padding されていないので文字列の長さが変わる) .

解決:
"{0:0{1}x}".format(15,2)
"{0:0{1}x}".format(255,2)
これでそれぞれ 文字列
"0f"
"ff"
を生成できる.

prefix “0x” が必要な場合は "{0:#0{1}x}".format(15,4)
format の2つ目の引数が全体の長さを決めている.

参考:
python – Decorating Hex function to pad zeros – Stack Overflow

byte 型は + 演算子で結合できるので

bytes.fromhex("{0:0{1}x}".format(15,2))+ bytes.fromhex("{0:0{1}x}".format(255,2))
b"\x0f\xff" を得る.

カテゴリー: 未分類 | バイナリデータ 文字リテラル 2進数 16進数 はコメントを受け付けていません

ssh 接続先をIPアドレスではなくホスト名で代替する /etc/hosts

/etc/hosts に IPaddress hostname を列挙して ssh や scp の際のIP アドレス入力をホスト名に代替可能:
(例)127.0.0.1 localhost
192.168.22.22 my-daq

.ssh/known_hosts
に過去に接続した接続先と公開鍵情報の一覧が書いてある
/etc/ssh/ssh_config ファイルの HashKnownHosts が yes の場合IPアドレスがハッシュ化されている. |1|xxxxXX=|XXXXXX= ecdsa-sha2-nistp256 (…)

sshkeygen -R ホスト名
で known_hosts の当該ホスト対応行を削除

ssh -G ホスト名
でそのホスト名にマッチする ssh の設定値を得る

カテゴリー: 未分類 | ssh 接続先をIPアドレスではなくホスト名で代替する /etc/hosts はコメントを受け付けていません

plot of (x,y) data with sqrt(y) errorbar by gnuplot

A shell script:

gnuplot << EOF
set terminal png
set output “tmpplot.png”
plot “inputfile.txt” using 1:2:(sqrt(\$2)) with ye
exit
EOF

単に \ でエスケープすればよかったんだ.

inputfile.txt には (x, y) という2列のデータが入っているとして.
# x y
0.0 10
0.5 250
1.0 1010

カテゴリー: 未分類 | plot of (x,y) data with sqrt(y) errorbar by gnuplot はコメントを受け付けていません

よく使う自然定数(原子物理)

hbar c = 197.326 980 4… MeV fm

https://physics.nist.gov/cgi-bin/cuu/Value?bgspu|search_for=universal_in!

カテゴリー: 未分類 | よく使う自然定数(原子物理) はコメントを受け付けていません