2019年4月17日水曜日

Raspberry Pi Joystick

C言語で、作った、動いた
ワイワイ (^^)/


Peace!!

Rasbina Lite に Desktopをインストールする


本家の説明が一番わかりやすい(^^)

https://www.raspberrypi.org/forums/viewtopic.php?t=133691

Peace!!

2019年4月16日火曜日

Connect Raspberry Pi and ACGAM R1 using Bluetooth

Amazonで購入したJoystickでロボットを動かしたく、設定した記録


搬送ロボットの学習行動や、所定の場所まで移動させるにはスマフォ片手というのは危険であり、やはり簡単な操作機器でするのが良いと思うわけでして、、、

通常Raspberry PiにはDesktop入れないので、コマンドラインでBluetoothとの接続をする。まずは、そこまでの記録。

sudo apt-get install -y pi-bluetooth

これによりsystemd配下のサービスとなる。はず、、、
で、

systemctl status bluetooth

なんとエラー、、、

Failed to obtain handles for "Service Changed" characteristic
Sap driver initialization failed.
sap-server: Operation not permitted (1)
Endpoint registered: sender=:1.26 path=/A2DP/SBC/Source/1
Endpoint registered: sender=:1.26 path=/A2DP/SBC/Sink/1

cat /etc/dbus-1/system.d/bluetooth.conf

確認するとパーミッション設定必要。

sudo usermod -a -G bluetooth pi
sudo reboot

bluetoothctl

scan on
おおおおお、、、で

scan off
connect FF:FF:30:01:0B:2A
Connection successful
pair FF:FF:30:01:0B:2A
Paring successful
trust FF:FF:30:01:0B:2A
Trust successful

info

device FF:FF:30:01:0B:2A
        Name: ACGAM R1
        Alias: ACGAM R1
        Paired: no
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
        UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
        UUID: Human Interface Device    (00001812-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v248Ap8266d3634

めでたしめでたし(^^)

sudo apt-get install joystick
sudo apt-get install jstest-gtk

jstest-gtk

おっと、この画面が現れて "Properties" を選択して、ぐにゅにゅ



因みに、このパッドは、4つのモードがあって
・シャッターモード(自撮りモード)
・マウスモード
・音楽モード
・ゲームモード
デフォルト(初期設定)は「音楽モード」。
左側にある"M"キーを押しながら"B"キーを押すとモードが変わるけど、
ようわからん。青いLEDは光るので反応はしているようだ
ロボットの制御をするので、中間値はいらないので、これで十分なはず。

今度は、アプリをつくります。

sudo apt-get install libbluetooth-dev

Peace!!



2019年4月12日金曜日

lighttpd を一発でBuildする

lighttpd を一発でbuild する

まあまあ、この作業が僕は多いので、こんな感じのbash
Raspberry Pi用です。
あと、変数VERは下記を確認して必要に応じて修正する。

https://www.lighttpd.net/

Peace!!

#!/bin/bash

HOME=/home/pi
VER=1.4.54

if [ -e $HOME/tmp ]; then
    cd $HOME/tmp
else
    mkdir $HOME/tmp
    cd $HOME/tmp
fi

wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-$VER.tar.gz
tar xvf lighttpd-$VER.tar.gz
cd  lighttpd-$VER
sudo apt-get -y install libpcre3-dev bzip2 libbz2-dev
./configure
make
sudo make install
sudo ldconfig
sudo mkdir /var/log/lighttpd
sudo chmod 777 /var/log/lighttpd



cat ./doc/systemd/lighttpd.service | sed s{usr{usr/local{ > qq
sudo cp qq /etc/systemd/system/lighttpd.service
rm qq
sudo systemctl enable lighttpd
sudo systemctl start lighttpd

2019年4月4日木曜日

mariaDB これだけ知っていれば困らないかも、、、

これだけ知っていれば、困らない
僕は、、、


(1) 検索について

結局大事なのは検索で、メモとして追加
NULL 検索をするとKeyも無視するらしいので、NULLを使ってはならない。

棚番号にXXXXが入って無く、かつdataに20%の値が設定されている。
select tana,hinc from zaiko where tana != "XXXX" and date like '20%';

カラムをグレイヴ アクセントで囲み検索条件をシングルクォーテーション
select count(*) from zaiko
where
`tana` like '%CHC%'
and
`data` like '20%';

(2) Login

mariadb -uroot db -pxxxxx
mariadb -uroot -p -h ホスト名


(3) DB処理

select * from zaiko;
select * from zaiko where id = 10;
select * from zaiko where hinc like('% style="font-size: 10pt;"%');

insert into users (name) values ('かばかば');
insert into profiles (name) select users from users where users.id = 1;
update users set name='kayak', status=3 where id=1;
delete from wakuwaku where kimoti like "waku%" and fuku <> "hadaka";

・例)検索してREPLACEで置換
update ship set post_kayakp = replace(post_content, 'style="font-size: 12pt;"', '') where kayak like('% style="font-size: 12pt;"%');

(4) DB import export

・import
入力ファイルはテーブル名
mysqlimport -uthn -pxxxxux --fields-terminated-by="|" 
 --lines-terminated-by="\n" --local test /home/pi/tmp/t1.csv

test.t1: Records: 21  Deleted: 0  Skipped: 0  Warnings: 0

・export
出力先は/tmpにしないとエラーになる。
DB名test, DB内にはtable名t1のみ、結果は  /tmp/t1.txt  となっている。
sudo rm /tmp/t*; mysqldump -uroot -pxxxxx --tab=/tmp  
 --fields-terminated-by='|' test

・コマンドライン
load data local infile “./test.csv” into table t1
 fields terminated by “,” lines terminated by “\r\n”;

出力先は/tmpにしないとエラーになる。

select * fromt1 into outfile ‘/tmp/te.csv’ 
 fields terminated by ‘|’ lines terminated by ‘\n’;


(5) DB, Table 作成、管理

・DB作成
create database DB名称;

・DB削除
drop database DB名称;

・例)DB作成とテーブル作成
create database wm;
create table wm.zaiko(hinc CHAR(32),
 hin CHAR(35),
 kazu int(6),
 hink CHAR(3),
 kata CHAR(200),
 hin2 VARCHAR(300),
 tana CHAR(32),
 yearin char(4),
 monthin char(2),
 date char(14),
 koushin datetime,
 other VARCHAR(256)
);
Query OK, 0 rows affected (5.89 sec)

・例)テーブル作成
cretat table t1(id int, name varchar(128), atr varchar(128));
  `id` int(11) default null,
  `name` varchar(128) default null,
  `atr` varchar(128) default null,
  `txt1` varchar(128) default null,
  `txt2` varchar(128) default null
) engine=InnoDB default charset=utf8mb4;

・テーブル確認
describe t1; 

・プライマリーキーの追加
alter table テーブル名 add primary key (カラム名);

・カラム名と型を変更
alter table `posts` change column `txt` `caption` varchar(255);

カラムの名前だけを変更する場合でも、上記のように型指定が必要
not null制約を追加する場合です。カラム名の制約を追加

alter table `posts` change column `txt` `caption` varchar(255) not null;

・カラムの型を変える
alter table `comments` modify column `post_id` bigint not null;

・カラム追加
alter tableとADDを使用してカラムを追加。
after 指定でpasswordカラムの後ろに、kayak_idカラムが追加
先頭に追加する時は、first  を指定する。

alter table `users` add `kayak_id` int(11) default null;
alter table `users` add `kayak_id` int(11) default null after `password`;
alter table `users` add `kayak_id` int(11) default null first;
alter table t1 addtxt2 varchar(128);
alter table t2 addtxt1 varchar(128) after txt1;

・テーブル内のデータを削除する。データだけの削除。
truncate t1;

(6) Utility

status;
show databases;
show columns from zaiko;
select count(*) from zaiko;
select version();
show variables;
show variables like "char%";
show variables like 'slow%';

use mysql;
select * from user;


(7) ユーザ管理

・ユーザー確認
select user from mysql.user;

・ユーザ追加とパスワード設定
create user 'ユーザ名'@'localhost' identified by 'ここにパスワード';

create user 'kayak'@'localhost' identified by 'password';

・ユーザーのパスワードを変更
set password for kayak@localhost=password( 'kayakPassword' );

・ユーザーを削除
drop user ユーザー名@ホスト名;

・ユーザー権限を確認
show grants for wordpress@localhost;
show grants for 'kayak'@'%';

・権限を追加 
grant all privileges on DB名.テーブル名 to 'ユーザ名'@'localhost';
mariadb 10.1.37では、上記のDB名.テーブル名は、シングルコーテーションで
囲むとエラーになる。従って、下記のようにする。
grant all privileges on TESTDB.* to 'user'@'localhost';

grant select on `kayakdb`.`users` to 'kayak'@'%'
grant file on *.* to kayak@localhost;

まとめると、、、
・グローバルレベル.sql
全DBの全テーブルに対して、与える権限を与える
grant 与える権限 on *.* to user名;

・データベースレベル.sql
指定したDB名の全テーブルに与える権限を与える
grant 与える権限 on DB名.* to user名;

・テーブルレベル.sql
指定したDB名の指定したテーブル名に与える権限を与える
grant 与える権限 on DB名.テーブル名 to user名;

・変更を反映さえる
flush privileges;


(8)開発環境を作る

sudo apt-get install default-libmysqlclient-dev
gcc slct01.c -o slct01 -lmysqlclient -L/usr/lib/arm-linux-gnueabihf

libmariadbclient-dev は、必要無いのかしら、、、

 Peace!!

memo:Raspberry Piにmysqlをインストールする

インストールでの問題は、rootのパスワード設定に技が必要な事
将来は解りませんが、、、

sudo apt-get -y install mysql-server

190722  OS:2019-07-10-raspbian-buster-lite
マジかー、、、

$ sudo apt-get -y install mysql-server
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
パッケージ mysql-server は使用できませんが、別のパッケージから参照されます。
これは、パッケージが欠落しているか、廃止されたか、または別のソース
からのみ利用可能であることを意味します。
しかし、以下のパッケージが置き換えます:
  mariadb-server-10.0
E: パッケージ 'mysql-server' にはインストール候補がありません
で、、、
sudo apt-get -y install mariadb-server
OK
クライアントモジュールが必要な場合は、mariadb-client
僕は、サーバ側でCで開発しているので使わない。
その代わりに、これを使うのでインストール


sudo apt-get install default-libmysqlclient-dev

20210428 問題
以下のrootのパスワードを設定をしようとしたら、エラー
サーバのsocketに繋がらない。
いろいろ調べたけど、、、不明
一つ一つ確認作業、、、、、
/lib/systemd/systemを確認して、、、
systemctl status も確認して、、、

sudo systemctl enable mariadb
sudo systemctl start mariadb

結局、serviceとして、手作業で設定し実行する。
以前は、インストール時に自動的にやっていたのに、、、

rootパスワードの設定をします。
いろいろ聞いてきますが、return, パスワード設定設定して、後はYで進めます。

sudo /usr/bin/mysql_secure_installation
return password password y,y,,,,,

でてくるメッセージは、ちゃんと読まないとならないかもです。
この設定は、そのままでは有効になりません。
root は、デフォルトでpluginがunix_socketに設定されているので、
それを削除します。sudoで軌道していますが、、、

sudo mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user,password,plugin from user;
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select user,password,plugin from user;
+------+-------------------------------------------+-------------+
| user | password                                  | plugin      |
+------+-------------------------------------------+-------------+
| root | *8637AD513CC7ED5F46D72CD7C3C587CFC9522613 | unix_socket |
+------+-------------------------------------------+-------------+
1 row in set (0.00 sec)

MariaDB [mysql]> update user set plugin='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> select user,password,plugin from user;
+------+-------------------------------------------+--------+
| user | password                                  | plugin |
+------+-------------------------------------------+--------+
| root | *8637AD513CC7ED5F46D72CD7C3C587CFC9522613 |        
+------+-------------------------------------------+--------+
1 row in set (0.00 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [mysql]> exit
Bye

rootで、設定したパスワードでloginできるか確認します。

mysql -u root -p
mariadb -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

完了です。

Peace !!

2019年3月24日日曜日

----------------------------------------------------------------
pi-packages
sudo -A rp-prefapps
rp-prefapps
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
gps_dmm2xy 3424.0094559 13520.3414517 6

cu -s 115200 -l /dev/ttyUSB0

sudo  apt-get install gpsd gpsd-clients
sudo vi /etc/default/gpsd
sudo systemctl restart gpsd
systemctl status gpsd

sudo apt-get install libgps-dev
gcc -o q1 q1.c -lm -lgps

確認 cu -s 115200 -l /dev/ttyUSB0
cu -s 115200 -l /dev/ttyUSB0 << EOS
stty -a -F /dev/ttyUSB0 | grep speed

設定
sudo stty -F /dev/ttyUSB0 115200

----------------------------------------------------------------
$ hciconfig
hci0:   Type: Primary  Bus: UART
        BD Address: B8:27:EB:04:7C:5E  ACL MTU: 1021:8  SCO MTU: 64:1
        DOWN
        RX bytes:654 acl:0 sco:0 events:33 errors:0
        TX bytes:419 acl:0 sco:0 commands:33 errors:0

$ sudo hciconfig hci0 up

Can't init device hci0: Operation not possible due to RF-kill (132)

$ rfkill list
0: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
1: hci0: Bluetooth
        Soft blocked: yes
        Hard blocked: no

$ sudo rfkill unblock bluetooth

$ rfkill list
0: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
1: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no

 $ sudo hciconfig hci0 reset

$ sudo hciconfig hci0
hci0:   Type: Primary  Bus: UART
        BD Address: B8:27:EB:04:7C:5E  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:2109 acl:0 sco:0 events:120 errors:0
        TX bytes:2011 acl:0 sco:0 commands:120 errors:0

$ sudo hciconfig hci0 up


$ echo N | sudo tee /sys/module/bluetooth/parameters/disable_ertm

$ sudo chmod 666 js*

$ ll
total 0
drwxr-xr-x  4 root root     240 Mar 24 13:06 .
drwxr-xr-x 15 root root    3400 Mar 24 13:06 ..
drwxr-xr-x  2 root root     100 Mar 24 12:29 by-id
drwxr-xr-x  2 root root     100 Mar 24 12:29 by-path
crw-rw----  1 root input 13, 64 Mar 24 12:29 event0
crw-rw----  1 root input 13, 65 Mar 24 12:29 event1
crw-rw----  1 root input 13, 66 Mar 24 13:06 event2
crw-rw-rw-  1 root input 13,  0 Mar 24 12:29 js0
crw-rw-rw-  1 root input 13,  1 Mar 24 13:06 js1
crw-rw----  1 root input 13, 63 Mar 24 12:29 mice
crw-rw----  1 root input 13, 32 Mar 24 12:29 mouse0
crw-rw----  1 root input 13, 33 Mar 24 13:06 mouse1

$ sudo apt-get install joystick
$ sudo apt-get install jstest-gtk

$ jstest-gtk


Opencv 3.4.4

$ cmake -D CMAKE_BUILD_TYPE=RELEASE     -D CMAKE_INSTALL_PREFIX=/usr/local     -D INSTALL_PYTHON_EXAMPLES=OFF     -D PLANTUML_JAR=/usr/share/java/plantuml.jar     -D ENABLE_NEON:BOOL=ON     -D WITH_TBB=ON -D BUILD_TBB=ON     -D WITH_QT=OFF -D WITH_OPENGL=OFF     -D BUILD_EXAMPLES=ON ..