SmartRubyPlug 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +6 -0
- data/README.md +252 -30
- data/bin/install_c_libraries.raspbian.sh +13 -0
- data/bin/run.sh +2 -2
- data/bin/run_armv6.sh +5 -0
- data/lib/smart_ruby_plug/processor.rb +6 -2
- data/lib/smart_ruby_plug/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbb1a9664fb01aeb8bec189831d84b092fb2b00b1262ba928b6f45869024a697
|
4
|
+
data.tar.gz: 27bcf2369ab69c59cb148744707d6e744295133f0baa0bb91b7615807a61d9ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11421fa8cae3e3ad8533f349eab8db49e7e0b399e6ec54bc2c3d024c2084514a6da0a74bc5fbd8620a788eea7f3f0d90841aea9a0b2fcc41954e16fc748955ab
|
7
|
+
data.tar.gz: 2bc47c15628238d66effbc16f066b5c384d7269e40d2a5f98a6f2d3854b9aba1ee16aa7034553573d3dd71079b0e4d143b7110859645814ff7112e0cf528c8bd
|
data/Changelog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.3.0
|
2
|
+
- add armv6 bash start scripts
|
3
|
+
- add info about read-only file system
|
4
|
+
- fix issue, when Home Assistant node was down, the internet requests was scheduled each 3 seconds instead of default 30 seconds
|
5
|
+
- readme improvements
|
6
|
+
|
1
7
|
## 0.2.0
|
2
8
|
- fix issue, when Home Assistant node was not reachable and the exception was bubbling up, which caused app exit
|
3
9
|
- fix the case, when app was exited, if wifi or internet IP was not reachable
|
data/README.md
CHANGED
@@ -170,10 +170,77 @@ Insert the token to `config/settings.yml`
|
|
170
170
|
Install the `Tplink's` [Kasa Smart](https://play.google.com/store/apps/details?id=com.tplink.kasa_android&hl=sk&gl=US) mobile application and follow the instructions in mobile app.
|
171
171
|
After successfull pairing, add the device in Home Assistant.
|
172
172
|
|
173
|
+
To add new smart plug to Home Assistant, follow doc at [https://www.home-assistant.io/integrations/tplink/](https://www.home-assistant.io/integrations/tplink/)
|
174
|
+
|
175
|
+
If you are connecting to SSID lets say X, you need the X network be the same, like the network where your Home Assistant node is available.
|
176
|
+
If the networks do not mach (like at my situation) you will need to add port forwarding from network X to network Y.
|
177
|
+
I have tried to scan open ports on smart plug via `nmap -Pn 10.0.2.105`
|
178
|
+
The response is:
|
179
|
+
```
|
180
|
+
PORT STATE SERVICE
|
181
|
+
9999/tcp open abyss
|
182
|
+
```
|
183
|
+
|
184
|
+
So I need to set port forwarding from port `9999` on the router, to port `9999` on the smart plug.
|
185
|
+
Note: The port depents on your smart plug model. If you have TPlink router, login to router IP and navigate
|
186
|
+
advanced > nat forwarding > virtual servers. There add port forwarding for port 9999.
|
187
|
+
|
188
|
+
If the smart plug was not auto discovered by Home Assistent, do following steps: (source: [https://www.home-assistant.io/integrations/tplink/](https://www.home-assistant.io/integrations/tplink/))
|
189
|
+
- Browse to your Home Assistant instance.
|
190
|
+
- In the sidebar click on Settings.
|
191
|
+
- From the configuration menu select: Devices & Services.
|
192
|
+
- In the bottom right, click on the Add Integration button.
|
193
|
+
- From the list, search and select “TP-Link Kasa Smart”.
|
194
|
+
|
195
|
+
Follow the instruction on screen to complete the set up.
|
196
|
+
|
197
|
+
In the modal, insert the IP of your router, where you have set port forwarding. Do not write the IP of the smart plug, as it is in another network and is not reachable.
|
198
|
+
|
173
199
|
You can check to turn on/off the plug via Home Assistant, or via REST API. The REST APIs doc is at [https://developers.home-assistant.io/docs/api/rest/](https://developers.home-assistant.io/docs/api/rest/)
|
174
200
|
|
201
|
+
### 3.2.1 Postman requests
|
202
|
+
Replace `10.0.3.3:8123` with the IP of Home Assistant node and 8123 with the port. If you havent changed it, the default port is `8123`
|
203
|
+
|
204
|
+
### 3.2.1.1 Turn on/off the plug
|
205
|
+
**Turn on:**
|
206
|
+
POST url: `http://10.0.3.3:8123/api/services/switch/turn_on`
|
207
|
+
|
208
|
+
**Turn off:**
|
209
|
+
POST url: `http://10.0.3.3:8123/api/services/switch/turn_off`
|
210
|
+
|
211
|
+
**Headers section:**
|
212
|
+
For Bearer, set your long lived token from Home Assistant:
|
213
|
+
```
|
214
|
+
Content-Type: application/json
|
215
|
+
Authorization: Bearer eyJ0eXA...
|
216
|
+
```
|
217
|
+
|
218
|
+
**Body:**
|
219
|
+
- select raw
|
220
|
+
- select application/json
|
221
|
+
- Body value: (change the `smart_zasuvka_1090` to your name)
|
222
|
+
```
|
223
|
+
{
|
224
|
+
"entity_id": "switch.smart_zasuvka_1090"
|
225
|
+
}
|
226
|
+
```
|
227
|
+
|
228
|
+
### 3.2.1.2 Get status of plug
|
229
|
+
(change the `smart_zasuvka_1090` to your name)
|
230
|
+
|
231
|
+
GET url: `http://10.0.3.3:8123/api/states/switch.smart_zasuvka_1090`
|
232
|
+
|
233
|
+
**Headers section:**
|
234
|
+
For Bearer, set your long lived token from Home Assistant:
|
235
|
+
```
|
236
|
+
Content-Type: application/json
|
237
|
+
Authorization: Bearer eyJ0eXA...
|
238
|
+
```
|
239
|
+
|
240
|
+
|
241
|
+
|
175
242
|
### 3.3 SmartRubyPlug installation
|
176
|
-
You need to install the Ubuntu OS to the rpi device, which will act as remote controller.
|
243
|
+
You need to install the Ubuntu OS to the rpi device, which will act as remote controller. Alternatively, Raspberry PI OS Lite for armv6 devices (PI Zero).
|
177
244
|
|
178
245
|
You can use Raspberry Pi's Imager to prepare bootable micro SD card. Select Ubuntu 22.04 aarch64 for Raspberry Pi 4B.
|
179
246
|
Once the card is prepared, insert it into rpi. The default user is ubuntu and password is `ubuntu`. You will be requested to
|
@@ -181,10 +248,16 @@ change the password immediately. You can set ssh keys to do not require copy pas
|
|
181
248
|
|
182
249
|
If you dont want to use ethernet port for internet, but wifi instead, I recommend to check this article [https://arstech.net/raspberry-pi-4-ubuntu-wifi/](https://arstech.net/raspberry-pi-4-ubuntu-wifi/)
|
183
250
|
|
184
|
-
**
|
251
|
+
**Note:** If you are running on armv6 compatible device (PI Zero, PI 1), you need to flash 32bit Raspbian (Raspberry PI OS Lite). You will select the wifi and user credentials via Imager software, in the right bottom corner - the setting icon.
|
252
|
+
|
253
|
+
**Note 2:** If you have 512MB ram device and you want to use ram disk (read-only filesystem) in "production", do not follow the Docker part, you will do not have enough memory for Docker image. Follow non-docker instructions and compile ruby from source code (rvm installation).
|
254
|
+
|
255
|
+
**For Docker installation** see chapter `6. Dockerfile building and running via Docker` for more info.
|
185
256
|
|
186
257
|
Now we need to install [RVM](https://rvm.io/). RVM is Ruby Version Manager and with RVM you can install multiple Ruby language versions in the same OS and switch between versions easily.
|
187
258
|
|
259
|
+
`sudo apt-get update`
|
260
|
+
|
188
261
|
Install GPG keys:
|
189
262
|
`sudo apt install gnupg2`
|
190
263
|
`gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB`
|
@@ -193,6 +266,11 @@ Install RVM:
|
|
193
266
|
```
|
194
267
|
curl -sSL https://get.rvm.io | bash -s stable
|
195
268
|
```
|
269
|
+
Install Vim editor
|
270
|
+
```
|
271
|
+
sudo apt-get install vim
|
272
|
+
```
|
273
|
+
|
196
274
|
Reload RVM shell for each login:
|
197
275
|
```
|
198
276
|
vim ~/.bashrc
|
@@ -204,20 +282,29 @@ source ~/.rvm/scripts/rvm
|
|
204
282
|
This will activate RVM after each login.
|
205
283
|
Logout and login again.
|
206
284
|
|
207
|
-
Download this SmartRubyPlug project to the home folder, eg to `/home/ubuntu/smart_ruby_plug`.
|
285
|
+
Download this SmartRubyPlug project to the home folder, eg to `/home/ubuntu/smart_ruby_plug`. If you are running Raspberry PI OS Lite, replace `ubuntu` with `pi`.
|
286
|
+
```
|
287
|
+
sudo apt-get install git
|
288
|
+
cd ~
|
289
|
+
git clone https://github.com/Matho/smart_ruby_plug.git
|
290
|
+
```
|
291
|
+
|
292
|
+
**Note:** it is not the best to clone master branch. Clone tag with version you want to download, instead.
|
293
|
+
|
294
|
+
|
208
295
|
Navigate to `cd ~/smart_ruby_plug`. You should be asked to switch to RVM Ruby version from project. Type `y` to yes and `enter`.
|
209
|
-
Install the Ruby version, the RVM is asking to install.
|
296
|
+
Install the Ruby version, the RVM is asking to install. (do NOT use sudo before this command)
|
210
297
|
```
|
211
298
|
rvm install "ruby-3.1.2"
|
212
299
|
```
|
213
|
-
This could take few minutes, it will compile Ruby, if no binaries are found.
|
300
|
+
This could take few minutes, it will compile Ruby, if no binaries are found. On Raspberry Pi ZERO it could take up to 2.5 hours, if no binaries are found.
|
214
301
|
|
215
302
|
After Ruby is installed, you can install project dependencies.
|
216
303
|
`gem install bundler`
|
217
304
|
`bundle install`
|
218
305
|
|
219
|
-
Then you need to copy the prebuilded C `.so` file. This file should be in the following project path: `lib/clibrary/libsmart_plug_C.so`
|
220
|
-
|
306
|
+
Then you need to copy the prebuilded C `.so` file or compile the .so file from C-code repository. This file should be in the following project path: `lib/clibrary/libsmart_plug_C.so`
|
307
|
+
|
221
308
|
|
222
309
|
Note: Enable SPI interface
|
223
310
|
```
|
@@ -226,17 +313,12 @@ sudo raspi-config
|
|
226
313
|
# Choose Interfacing Options -> SPI -> Yes to enable SPI interface
|
227
314
|
sudo reboot
|
228
315
|
```
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
If you want to compile the C code instead of using the prebuilded binary, you can follow this steps.
|
234
|
-
|
235
|
-
**NOTE:** I expect, you need to install `BCM2835 libraries` and `wiringPi libraries` in the following steps also for cases, you would like to run on the prebuilded binary, without custom compilation.
|
236
|
-
|
237
|
-
The instructions are extracted from [https://www.waveshare.com/wiki/1.3inch_LCD_HAT](https://www.waveshare.com/wiki/1.3inch_LCD_HAT)
|
316
|
+
You need to install the ping command, via:
|
317
|
+
```
|
318
|
+
sudo apt-get install iputils-ping
|
319
|
+
```
|
238
320
|
|
239
|
-
To be able build the libraries, you need to install:
|
321
|
+
To be able build the libraries, you need to install:
|
240
322
|
```
|
241
323
|
sudo apt-get install gcc cmake
|
242
324
|
```
|
@@ -262,10 +344,38 @@ gpio -v
|
|
262
344
|
# Run gpio -v and version 2.70 or newer will appear. If it does not appear, it means that there is an installation error
|
263
345
|
```
|
264
346
|
|
347
|
+
### 3.4 C-binary installation
|
348
|
+
The display redrawing and detection for keypress is written via C code. Then, the `main.so` file is prepared and Ruby is calling the C functions via `FFI` gem.
|
349
|
+
|
350
|
+
#### 3.4.1 Using precompiled .so file
|
351
|
+
Download the C project binary repository:
|
352
|
+
```
|
353
|
+
cd ~
|
354
|
+
git clone https://github.com/Matho/smart_ruby_plug_c_binaries.git
|
355
|
+
```
|
356
|
+
|
357
|
+
You can point symlink for Ruby project to file `/home/ubuntu/smart_ruby_plug_c/main.so`. If running on Raspbian, use `pi` instead of `ubuntu`
|
358
|
+
|
359
|
+
Start the ruby app:
|
360
|
+
```
|
361
|
+
cd ~/smart_ruby_plug
|
362
|
+
bundle exec bin/smart_ruby_plug start
|
363
|
+
```
|
364
|
+
|
365
|
+
#### 3.4.2 Compilation
|
366
|
+
|
367
|
+
If you want to compile the C code instead of using the prebuilded binary, you can follow this steps.
|
368
|
+
|
369
|
+
The instructions are extracted from [https://www.waveshare.com/wiki/1.3inch_LCD_HAT](https://www.waveshare.com/wiki/1.3inch_LCD_HAT)
|
370
|
+
|
265
371
|
Because we are not using Python source code examples, we do not need to install Python.
|
266
|
-
Also, we do not need to install FBCP driver as we are not displaying the OS GUI screens, but only drawing, like on canvas.
|
372
|
+
Also, we do not need to install FBCP driver as we are not displaying the OS GUI screens, but only drawing, like on canvas.
|
267
373
|
|
268
|
-
Download the C project repository code to
|
374
|
+
Download the C project repository code to
|
375
|
+
```
|
376
|
+
cd ~
|
377
|
+
git clone https://github.com/Matho/smart_ruby_plug_c.git
|
378
|
+
```
|
269
379
|
|
270
380
|
To build the C project on rpi, you need to install following dependencies:
|
271
381
|
```
|
@@ -274,12 +384,15 @@ sudo apt-get install gcc doxygen cmake gdb
|
|
274
384
|
|
275
385
|
Build the project via Makefile (or via Clion IDE, if you have configured it correctly):
|
276
386
|
```
|
387
|
+
cd ~/smart_ruby_plug_c
|
388
|
+
mkdir bin
|
389
|
+
# make clean will show error for the first time
|
277
390
|
make clean
|
278
391
|
make
|
279
392
|
```
|
280
393
|
You should see new `main.so` file. You can prepare symlink for Ruby project:
|
281
394
|
```
|
282
|
-
ln -s
|
395
|
+
ln -s ~/smart_ruby_plug_c/main.so ~/smart_ruby_plug/lib/clibrary/libsmart_plug_C.so
|
283
396
|
```
|
284
397
|
|
285
398
|
If you are going to do more work with this C project, you can setup `Clion IDE` settings to synchronize target files with your local files in IDE and run
|
@@ -288,10 +401,10 @@ the building on rpi. The building works only on compatible raspberry pi, it will
|
|
288
401
|
Start the ruby app:
|
289
402
|
```
|
290
403
|
cd ~/smart_ruby_plug
|
291
|
-
bin/smart_ruby_plug start
|
404
|
+
bundle exec bin/smart_ruby_plug start
|
292
405
|
```
|
293
406
|
|
294
|
-
|
407
|
+
#### 3.4.4 Using custom fonts:
|
295
408
|
Only few fonts and font sizes are available currently. If you want to change the font sizes to your custom, you will need to run this project [https://github.com/zst-embedded/STM32-LCD_Font_Generator](https://github.com/zst-embedded/STM32-LCD_Font_Generator)
|
296
409
|
It needs python v3.6. To do not break your current Ubuntu system on your localhost, I recommend to start up new VM for example in `DigitalOcean`.
|
297
410
|
If you want to install Python 3.6 on Ubuntu 22.04, you can follow this tutorial [https://stackoverflow.com/questions/72102435/how-to-install-python3-6-on-ubuntu-22-04](https://stackoverflow.com/questions/72102435/how-to-install-python3-6-on-ubuntu-22-04)
|
@@ -314,18 +427,25 @@ Rewrite the generated file based on the existing C files in project
|
|
314
427
|
|
315
428
|
### 3.5 Start the app on reboot
|
316
429
|
Currently, the app is not started on reboot. To do, follow this commands:
|
430
|
+
(note: more info about service restarting can be found at [https://ma.ttias.be/auto-restart-crashed-service-systemd/](https://ma.ttias.be/auto-restart-crashed-service-systemd/))
|
317
431
|
|
318
432
|
Create new file:
|
319
433
|
```
|
320
434
|
sudo vim /etc/systemd/system/smart_ruby_plug.service
|
321
435
|
```
|
322
436
|
|
323
|
-
and insert there:
|
437
|
+
and insert there: (change `ubuntu` to `pi` for Raspberry PI Os) and `run_armv6.sh` for Raspbery PI OS.
|
324
438
|
```
|
325
439
|
[Unit]
|
326
440
|
After=
|
327
441
|
|
442
|
+
StartLimitIntervalSec=500
|
443
|
+
StartLimitBurst=5
|
444
|
+
|
328
445
|
[Service]
|
446
|
+
Restart=on-failure
|
447
|
+
RestartSec=5s
|
448
|
+
|
329
449
|
ExecStart=/home/ubuntu/smart_ruby_plug/bin/run.sh
|
330
450
|
|
331
451
|
[Install]
|
@@ -351,8 +471,8 @@ sudo systemctl status smart_ruby_plug.service
|
|
351
471
|
## 4 Start the app manually (without systemctl)
|
352
472
|
Build the `.so` binary on your Raspberry Pi. Then copy the builded file to the `lib/clibrary/libsmart_plug_C.so`
|
353
473
|
|
354
|
-
Navigate to the root folder of this app and run:
|
355
|
-
`bin/smart_ruby_plug start`
|
474
|
+
Navigate to the root folder of this app and run:
|
475
|
+
`bundle exec bin/smart_ruby_plug start`
|
356
476
|
|
357
477
|
**Note:** You need to push the button for 2 seconds. Only the light click for few miliseconds doesnt register the key press event.
|
358
478
|
|
@@ -368,7 +488,15 @@ it also on amd64 machine, without needed C packages. You can rename it to `libsm
|
|
368
488
|
|
369
489
|
## 6. Dockerfile building and running via Docker
|
370
490
|
|
371
|
-
|
491
|
+
Note: Enable SPI interface
|
492
|
+
```
|
493
|
+
sudo apt-get install raspi-config
|
494
|
+
sudo raspi-config
|
495
|
+
# Choose Interfacing Options -> SPI -> Yes to enable SPI interface
|
496
|
+
sudo reboot
|
497
|
+
```
|
498
|
+
|
499
|
+
### 6.1.1 Install Docker on RPI 2+
|
372
500
|
```
|
373
501
|
sudo apt-get install \
|
374
502
|
apt-transport-https \
|
@@ -397,17 +525,44 @@ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose
|
|
397
525
|
sudo docker run hello-world
|
398
526
|
```
|
399
527
|
|
528
|
+
### 6.1.2 Install Docker on Rpi 1/ZERO (and armv6 devices)
|
529
|
+
Follow this steps [https://docs.docker.com/engine/install/debian/#install-using-the-convenience-script](https://docs.docker.com/engine/install/debian/#install-using-the-convenience-script)
|
530
|
+
|
531
|
+
```
|
532
|
+
curl -fsSL https://get.docker.com -o get-docker.sh
|
533
|
+
sh ./get-docker.sh
|
534
|
+
```
|
535
|
+
|
536
|
+
Then, we need to install docker-compose.
|
537
|
+
```
|
538
|
+
sudo apt-get install docker-compose
|
539
|
+
```
|
540
|
+
Note: This installation removes docker and install older version. Not sure, why it happens, but docker-compose works.
|
541
|
+
|
542
|
+
Start the Docker service:
|
543
|
+
```
|
544
|
+
sudo systemctl start docker.service
|
545
|
+
```
|
546
|
+
|
400
547
|
### 6.2 Build this image
|
401
548
|
If you want to only run the image with last version, skip to docker-compose tutorial in next section.
|
402
549
|
|
550
|
+
```
|
551
|
+
git clone https://github.com/Matho/smart_ruby_plug.git
|
552
|
+
```
|
403
553
|
`cd ~/docker-builds/smart_ruby_plug`
|
554
|
+
|
404
555
|
Pass `--no-cache` for clean build and pass correct url with C binary version for C_BINARY_PATH arg.
|
405
556
|
|
406
557
|
For aarch64:
|
407
|
-
`sudo docker build -t mathosk/smart_ruby_plug:v0.
|
558
|
+
`sudo docker build -t mathosk/smart_ruby_plug:v0.3.0_aarch64 --build-arg ARCH=aarch64 --build-arg C_BINARY_PATH=https://github.com/Matho/smart_ruby_plug_c_binaries/releases/download/v0.1.0.beta/libsmart_plug_C.so.v0.1.0.beta_77865ad7af .`
|
408
559
|
|
409
560
|
Alternatively for armv7l:
|
410
|
-
`sudo docker build -t mathosk/smart_ruby_plug:v0.
|
561
|
+
`sudo docker build -t mathosk/smart_ruby_plug:v0.3.0_armv7l --build-arg ARCH=armv7l --build-arg C_BINARY_PATH=https://github.com/Matho/smart_ruby_plug_c_binaries/raw/master/armv7l_32/v0.1.0/libsmart_plug_C.so.v0.1.0.beta_77865ad7af .`
|
562
|
+
|
563
|
+
For armv6:
|
564
|
+
`sudo docker build -t mathosk/smart_ruby_plug:v0.3.0_armv6 --file Dockerfile.raspbian --build-arg C_BINARY_PATH=https://github.com/Matho/smart_ruby_plug_c_binaries/raw/master/armv6/v0.1.0/libsmart_plug_C.so.v0.1.0.beta_77865ad7af .`
|
565
|
+
**Note:** If you have selected different user for Raspbian OS from `pi`, you need to change it in the `Dockerfile.raspbian` file to point to the correct path
|
411
566
|
|
412
567
|
### 6.3 Execute
|
413
568
|
`-d` means detached - running in background. If you do not want to run it in background (for test purposes) remove `-d` option from command line
|
@@ -425,7 +580,7 @@ You need to have installed the `docker-compose` package. Check it via:
|
|
425
580
|
Copy `smart_ruby_plug/config/settings.yml` file with modified yml according your needs and upload it to folder
|
426
581
|
`/data/smart_ruby_plug/config` on your Raspberry Pi.
|
427
582
|
|
428
|
-
The docker-compose file is located in this project root. Please, before you start it, point to correct version you want to pull.
|
583
|
+
The docker-compose file is located in this project root. Please, before you start it, point to correct version you want to pull (inside docker compose yml) and specify correct arch in the filename call.
|
429
584
|
|
430
585
|
You can start the project via: (use `-d` for run in background)
|
431
586
|
```
|
@@ -441,7 +596,74 @@ sudo docker-compose -f docker-compose_aarch64.yml down
|
|
441
596
|
I have installed Ubuntu 22.04 32bit edition on Raspberry Pi 2B model . This model has 1GB ram.
|
442
597
|
In standby mode, without this application, it takes 180MB ram. With this app it is almost 200MB ram usage.
|
443
598
|
|
444
|
-
|
599
|
+
### 7 Read-only filesystem (ram disk) instead of batteries
|
600
|
+
Stop the systemctl service for this app, before you are going to setup readonly filesystem:
|
601
|
+
```
|
602
|
+
sudo systemctl stop smart_ruby_plug.service
|
603
|
+
```
|
604
|
+
|
605
|
+
You can run on PiJuice HAT / PiSugar batteries. But better way is to run on read-only filesystem. I have chosen this way.
|
606
|
+
The good articles are at [https://medium.com/swlh/make-your-raspberry-pi-file-system-read-only-raspbian-buster-c558694de79](https://medium.com/swlh/make-your-raspberry-pi-file-system-read-only-raspbian-buster-c558694de79) and [https://grafolean.medium.com/run-docker-on-your-raspberry-pi-read-only-file-system-raspbian-1360cf94bace](https://grafolean.medium.com/run-docker-on-your-raspberry-pi-read-only-file-system-raspbian-1360cf94bace)
|
607
|
+
I have followed both, but was not successfully with running app in Docker and read-only mode for Raspberry PI Zero. There is 512MB of ram, and
|
608
|
+
the Docker image is pretty big. If you are running on Rpi 2B+ with more than 512MB, I expect you will succeed with read-only file system and Docker.
|
609
|
+
|
610
|
+
So, if you do not want to run in Docker, follow steps only from the first guide and first improvements chapter from the second one. The only difference I needed to do, is
|
611
|
+
to prefix mount commands in `/etc/bash.bash_logout` with sudo. Eg:
|
612
|
+
```
|
613
|
+
sudo mount -o remount,ro /
|
614
|
+
sudo mount -o remount,ro /boot
|
615
|
+
```
|
616
|
+
### 8 Use multiple wifi connection profiles
|
617
|
+
You probably want the RPI be able connect on multiple wifi networks. One from home (during development and testing), the second from your weekend house.
|
618
|
+
The initial wifi credentials for Raspberry PI OS was set via Imager tool.
|
619
|
+
|
620
|
+
To add another wifi profile, do following steps. (Ensure, you are in read-write mode) This will generate the text, you need to copy to `wpa_supplicant.conf`
|
621
|
+
```
|
622
|
+
sudo wpa_passphrase my_SSID my_password
|
623
|
+
```
|
624
|
+
|
625
|
+
Paste it in file:
|
626
|
+
```
|
627
|
+
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
|
628
|
+
```
|
629
|
+
|
630
|
+
More info you can find at [https://raspberrypi.stackexchange.com/questions/11631/how-to-setup-multiple-wifi-networks](https://raspberrypi.stackexchange.com/questions/11631/how-to-setup-multiple-wifi-networks)
|
631
|
+
Also, you can set the priority.
|
632
|
+
|
633
|
+
The `wpa_supplicant.conf` looks now like this:
|
634
|
+
```
|
635
|
+
country=SK
|
636
|
+
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
637
|
+
ap_scan=1
|
638
|
+
|
639
|
+
update_config=1
|
640
|
+
network={
|
641
|
+
ssid="chata"
|
642
|
+
#psk="your-password"
|
643
|
+
psk=bff8df...........
|
644
|
+
priority=3
|
645
|
+
}
|
646
|
+
|
647
|
+
network={
|
648
|
+
ssid="Chata"
|
649
|
+
#psk="your-password"
|
650
|
+
psk=a496f12...........
|
651
|
+
priority=2
|
652
|
+
}
|
653
|
+
network={
|
654
|
+
ssid="Matho-2"
|
655
|
+
psk=785b22c78...........
|
656
|
+
}
|
657
|
+
```
|
658
|
+
|
659
|
+
If you want to change the connection to another SSID based on this settings, without reboot, run following commands:
|
660
|
+
```
|
661
|
+
sudo systemctl daemon-reload
|
662
|
+
sudo systemctl restart dhcpcd
|
663
|
+
```
|
664
|
+
Note: You will be disconnected from your rpi, if the connection profile will be changed. Also, you will have assigned new IP address.
|
665
|
+
|
666
|
+
## 9 TODOs
|
445
667
|
- add display redrawer specs
|
446
668
|
- when app is (re)started, redraw screem, to white, for example
|
447
669
|
- cloning external libraries during Docker build from this project repo / or ftp under my control
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
cd /home/pi
|
4
|
+
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
|
5
|
+
tar zxvf bcm2835-1.68.tar.gz
|
6
|
+
cd bcm2835-1.68/
|
7
|
+
./configure && make && make check && make install
|
8
|
+
|
9
|
+
cd /home/pi
|
10
|
+
git clone https://github.com/WiringPi/WiringPi
|
11
|
+
cd WiringPi
|
12
|
+
./build
|
13
|
+
gpio -v
|
data/bin/run.sh
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/bin/bash
|
2
|
-
|
2
|
+
# If you are running on Raspbian OS, you need to change the homeuser to 'pi' or to the user you have choosen during the disk flashing
|
3
3
|
source /home/ubuntu/.rvm/scripts/rvm
|
4
4
|
|
5
|
-
cd /home/ubuntu/smart_ruby_plug; /home/ubuntu/smart_ruby_plug/bin/smart_ruby_plug start
|
5
|
+
cd /home/ubuntu/smart_ruby_plug; bundle exec /home/ubuntu/smart_ruby_plug/bin/smart_ruby_plug start
|
data/bin/run_armv6.sh
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# If you are running on Raspbian OS, you need to change the homeuser to 'pi' or to the user you have choosen during the disk flashing
|
3
|
+
source /home/pi/.rvm/scripts/rvm
|
4
|
+
|
5
|
+
cd /home/pi/smart_ruby_plug; bundle exec /home/pi/smart_ruby_plug/bin/smart_ruby_plug start
|
@@ -33,10 +33,14 @@ module SmartRubyPlug
|
|
33
33
|
|
34
34
|
if @check_internet
|
35
35
|
@internet_output = internet_check
|
36
|
-
|
36
|
+
|
37
|
+
if @internet_output == []
|
38
|
+
redraw_display_with_status(:on)
|
39
|
+
else
|
37
40
|
redraw_display_with_error(@internet_output)
|
38
|
-
next
|
39
41
|
end
|
42
|
+
|
43
|
+
next
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SmartRubyPlug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Markech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -60,8 +60,10 @@ files:
|
|
60
60
|
- Changelog.md
|
61
61
|
- LICENSE.md
|
62
62
|
- README.md
|
63
|
+
- bin/install_c_libraries.raspbian.sh
|
63
64
|
- bin/install_c_libraries.sh
|
64
65
|
- bin/run.sh
|
66
|
+
- bin/run_armv6.sh
|
65
67
|
- bin/smart_ruby_plug
|
66
68
|
- lib/clibrary/library.rb
|
67
69
|
- lib/main.rb
|