Skip to content

Commit 6a0db6f

Browse files
authored
detailed instructions to build raspberry pi for project
1 parent ce09f03 commit 6a0db6f

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

detailed-build-instructions.txt

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
build rapsberry pi ble to mqtt
2+
202012161409
3+
4+
5+
sudo dd bs=1m if=2020-08-20-raspios-buster-armhf-full.img of=/dev/rdisk6 conv=sync
6+
7+
touch /Volumes/boot/ssh
8+
9+
vi /Volumes/boot/wpa_supplicant.conf
10+
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
11+
update_config=1
12+
country=US
13+
14+
network={
15+
ssid="xxx"
16+
psk="yyy"
17+
key_mgmt=WPA-PSK
18+
}
19+
20+
diskutil eject /dev/disk6
21+
22+
boot the pi
23+
find on network
24+
25+
sudo raspi-config
26+
# wait for network
27+
# consistent network names
28+
29+
30+
edit /etc/dhcpcd.conf
31+
interface eth0
32+
static ip_address=192.168.x.y/24
33+
static routers=192.168.x.x
34+
static domain_name_servers=1.1.1.1
35+
36+
interface enxb827ebczzzzz
37+
static ip_address=192.168.x.y/24
38+
static routers=192.168.x.x
39+
static domain_name_servers=1.1.1.1
40+
41+
removed /etc/wpa_supplicant.conf
42+
43+
sudo apt-get update
44+
sudo apt-get full-upgrade
45+
reboot
46+
sudo apt-get install tmux
47+
48+
fix login warning:
49+
/etc/profile.d/sshpwd.sh
50+
/etc/xdg/lxsession/LXDE-pi/sshpwd.sh
51+
52+
mkdir ~/.ssh
53+
cat .ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
54+
55+
create .vimrc for pi and root
56+
57+
sudo mkdir /media/pi
58+
sudo mkdir /media/pi/nas
59+
60+
vi /home/pi/.NASCREDS
61+
62+
user=xxx
63+
password=yyy
64+
65+
in /etc/fstab
66+
67+
//192.168.x.y/nas /media/pi/nas cifs credentials=/home/pi/.NASCREDS,uid=pi,gid=pi,vers=1.0,comment=x-systemd.automount 0 0
68+
69+
# test it
70+
sudo mount -a
71+
72+
mkdir ~/ble-sensors
73+
cd ~/ble-sensors
74+
git clone https://github.com/deepcoder/bluetooth-temperature-sensors.git
75+
sudo apt-get install libbluetooth-dev
76+
git clone https://github.com/eclipse/paho.mqtt.c.git
77+
cd paho.mqtt.c
78+
make
79+
sudo make install
80+
cd ..
81+
cd bluetooth-temperature-sensors
82+
gcc -o ble_sensor_mqtt_pub ble_sensor_mqtt_pub.c -lbluetooth -l paho-mqtt3c
83+
cp ble_sensor_mqtt_pub ..
84+
cd ..
85+
create ble_sensor_mqtt_pub.csv
86+
create hack_ble.sh
87+
=====
88+
#!/bin/bash
89+
90+
trap "echo Exited!; exit;" SIGINT SIGTERM
91+
92+
if [ $EUID -ne 0 ]; then
93+
echo "This script should be run as root." > /dev/stderr
94+
exit 1
95+
fi
96+
97+
while :
98+
do
99+
echo 'Running ble_sensor_mqtt_pub'
100+
date '+%Y%m%d%H%M%S'
101+
echo "Press [CTRL+C] to stop.."
102+
cd /home/pi/ble-sensors
103+
/home/pi/ble-sensors/ble_sensor_mqtt_pub 0 1 200 500
104+
done
105+
=====
106+
chmod +x hack_ble.sh
107+
108+
sudo vi /etc/rc.local
109+
=====
110+
#!/bin/bash
111+
112+
########!/bin/sh -e
113+
#
114+
# rc.local
115+
#
116+
# This script is executed at the end of each multiuser runlevel.
117+
# Make sure that the script will "exit 0" on success or any other
118+
# value on error.
119+
#
120+
# In order to enable or disable this script just change the execution
121+
# bits.
122+
#
123+
# By default this script does nothing.
124+
125+
# Print the IP address
126+
_IP=$(hostname -I) || true
127+
if [ "$_IP" ]; then
128+
printf "My IP address is %s\n" "$_IP"
129+
fi
130+
131+
# wait for networks to start
132+
133+
STATE="error";
134+
135+
while [ $STATE == "error" ]; do
136+
#do a ping and check that its not a default message or change to grep for something else
137+
STATE=$(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error)
138+
139+
#sleep for 2 seconds and try again
140+
sleep 2
141+
done
142+
143+
su pi -c 'tmux new-session -d -s ble'
144+
su pi -c 'tmux send-keys sudo Space /home/pi/ble-sensors/hack_ble.sh C-m'
145+
146+
147+
exit 0
148+
=====
149+
hciconfig
150+
hci0: Type: Primary Bus: UART
151+
BD Address: cc:bb:aa:zz:yy:xx ACL MTU: 1021:8 SCO MTU: 64:1
152+
UP RUNNING
153+
RX bytes:1476 acl:0 sco:0 events:90 errors:0
154+
TX bytes:3274 acl:0 sco:0 commands:90 errors:0
155+
156+
tmux attach -t ble
157+

0 commit comments

Comments
 (0)