SmartRubyPlug 0.1.2.beta → 0.2.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 +5 -0
- data/README.md +24 -12
- data/lib/smart_ruby_plug/processor.rb +3 -2
- data/lib/smart_ruby_plug/requests/smart_plug_on_request.rb +12 -8
- data/lib/smart_ruby_plug/requests/smart_plug_status_request.rb +9 -5
- data/lib/smart_ruby_plug/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fea9e4a921b4c63967cca9b5699c95367f5b433d6369b5a059de9ce637d75e5e
|
4
|
+
data.tar.gz: 81f22b51523d4d4bb2f80a3635ecbe027f38ca0db1a02c6ab746546fd6f37416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d24049153e426fd8ed867071b02b59733237708ac215359a95edcda316203350e652774e0620108a6e54410c6f845b8bfb0c2559de2aff2eb7813ea4ee86cb3
|
7
|
+
data.tar.gz: 68988542dddcbbebf971875432878b6c338e23e228757650193ee2e2da749e0d0737e6c884cc9b79235a66048a483bcd3ea998a08edb6ab3197875fc92155380
|
data/Changelog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
- fix issue, when Home Assistant node was not reachable and the exception was bubbling up, which caused app exit
|
3
|
+
- fix the case, when app was exited, if wifi or internet IP was not reachable
|
4
|
+
- fix missing ping package for Docker build
|
5
|
+
|
1
6
|
## 0.1.2.beta
|
2
7
|
- fix gemspec
|
3
8
|
|
data/README.md
CHANGED
@@ -7,7 +7,8 @@ The project has 3 repositories
|
|
7
7
|
- [Matho/smart_ruby_plug_c](https://github.com/Matho/smart_ruby_plug_c) - C source code for those, who want to change the drawing on the Raspberry Pi display
|
8
8
|
- [Matho/smart_ruby_plug_c_binaries](https://github.com/Matho/smart_ruby_plug_c_binaries) - prebuilded C binaries (.so file) for those, who do not want to build the binary from source code
|
9
9
|
|
10
|
-
You can find the **demo video** at [this link](http://websupport.matho.sk/smart_plug.webm)
|
10
|
+
You can find the **demo video** at [this link](http://websupport.matho.sk/smart_plug.webm)
|
11
|
+
See [wiki](https://github.com/Matho/smart_ruby_plug/wiki/End-User-manual) for end-user manual.
|
11
12
|
|
12
13
|
## 1. The motivation behind this project
|
13
14
|
Imagine the following situation:
|
@@ -26,7 +27,8 @@ It can cut your energy bill dramatically!
|
|
26
27
|
The idea is, that you will provide Raspberry Pi with LCD display to your neighbor and he will have option to turn your Starlink dish on, for case it is off (it is scheduled for turning off at midnight for each night)
|
27
28
|
|
28
29
|
The hardware you need to buy:
|
29
|
-
- you have to buy 2x Raspberry Pi
|
30
|
+
- you have to buy 2x Raspberry Pi. You need min 1GB ram model for Home Assistant node and min512MB ram model for the remote device.
|
31
|
+
- the project works both on armv7l and aarch64
|
30
32
|
- the first one will be used as remote control and the second one as master node with `Home Assistant` smart home software
|
31
33
|
- then I have bought [Waveshare 1,3" IPS LCD display HAT 240×240](https://www.waveshare.com/1.3inch-lcd-hat.htm) for the RPI used to act as remote device
|
32
34
|
- you need also some 2x MicroSD card, 32GB should be good enough
|
@@ -58,20 +60,21 @@ I have identified following costs:
|
|
58
60
|
|
59
61
|
- display ... 16 EUR
|
60
62
|
- smart plug ... 38 EUR
|
61
|
-
-
|
63
|
+
- 1x Raspberry Pi 1GB model ... 45 EUR
|
64
|
+
- 1x Raspbery Pi Zero 2W with GPIO header .... 23 EUR
|
62
65
|
- 2x power adapter .. 2x10EUR
|
63
66
|
- 2x ethernet cable ... 2x1.5EUR
|
64
67
|
- 2x micro SD card ... 2x8EUR
|
65
68
|
- 2x some rpi case ... optional
|
66
69
|
- shipping for orders from eshops ... unknown/optional
|
67
70
|
|
68
|
-
Total*:
|
71
|
+
Total*: 151 EUR
|
69
72
|
|
70
73
|
**Note:** The yearly energy bill is expected at `430Kwh` It should cost about 100 EUR / year.
|
71
74
|
I expect you can sell the used items on bazaar after few years with 70% of buy price,
|
72
|
-
so **your initial costs in this case would be only
|
75
|
+
so **your initial costs in this case would be only 46 EUR.** Also, you need to include here the saved energy costs.
|
73
76
|
|
74
|
-
**Note 2:**
|
77
|
+
**Note 2:** Raspbery Pi Zero 2W was not tested by me. But based on the its parameters, it should work too. The memory consumption on the node with Home Assistant is about 500MB. Not sure, but maybe it would work on RPI ZERO 2W also for the master node.
|
75
78
|
|
76
79
|
**Note 3:** Currently there is big issue with Raspberry Pi availability. The costs on Ebay are sometimes more then twice the price I'm including on this purchase list.
|
77
80
|
|
@@ -178,7 +181,7 @@ change the password immediately. You can set ssh keys to do not require copy pas
|
|
178
181
|
|
179
182
|
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/)
|
180
183
|
|
181
|
-
**The easiest way is install this project via Docker**. See chapter `6. Dockerfile building and running via Docker` for more info.
|
184
|
+
**The easiest way is install this project via Docker**. See chapter `6. Dockerfile building and running via Docker` for more info. I recommend Docker also for the case - when the app failed (exit), the Docker container can restart the container automatically.
|
182
185
|
|
183
186
|
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.
|
184
187
|
|
@@ -359,6 +362,9 @@ Log in to your raspberry pi, `cd` to the project and run:
|
|
359
362
|
|
360
363
|
The project need the prebuilded `.so` file.
|
361
364
|
|
365
|
+
### 5.1 Running rspec on amd64 machine
|
366
|
+
Alternatively, you can use prebuilded `libsmart_plug_C.so.for_tests` located in `lib/clibrary`. This is "empty" clibrary file, so it is able to run
|
367
|
+
it also on amd64 machine, without needed C packages. You can rename it to `libsmart_plug_C.so` and start the tests on your localhost (not from rpi).
|
362
368
|
|
363
369
|
## 6. Dockerfile building and running via Docker
|
364
370
|
|
@@ -375,7 +381,7 @@ software-properties-common
|
|
375
381
|
```
|
376
382
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
377
383
|
```
|
378
|
-
Use proper architecture - `arm64` for
|
384
|
+
Use proper architecture - `arm64` for >= Raspberry Pi 3B or `armhf` for <= Raspberry Pi 2B
|
379
385
|
```
|
380
386
|
sudo add-apt-repository \
|
381
387
|
"deb [arch=arm64] https://download.docker.com/linux/ubuntu \
|
@@ -392,20 +398,22 @@ sudo docker run hello-world
|
|
392
398
|
```
|
393
399
|
|
394
400
|
### 6.2 Build this image
|
401
|
+
If you want to only run the image with last version, skip to docker-compose tutorial in next section.
|
402
|
+
|
395
403
|
`cd ~/docker-builds/smart_ruby_plug`
|
396
404
|
Pass `--no-cache` for clean build and pass correct url with C binary version for C_BINARY_PATH arg.
|
397
405
|
|
398
406
|
For aarch64:
|
399
|
-
`sudo docker build -t mathosk/smart_ruby_plug:v0.
|
407
|
+
`sudo docker build -t mathosk/smart_ruby_plug:v0.2.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 .`
|
400
408
|
|
401
409
|
Alternatively for armv7l:
|
402
|
-
`sudo docker build -t mathosk/smart_ruby_plug:v0.
|
410
|
+
`sudo docker build -t mathosk/smart_ruby_plug:v0.2.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 .`
|
403
411
|
|
404
412
|
### 6.3 Execute
|
405
413
|
`-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
|
406
414
|
|
407
415
|
```
|
408
|
-
sudo docker run --privileged -d mathosk/smart_ruby_plug:v0.
|
416
|
+
sudo docker run --privileged -d mathosk/smart_ruby_plug:v0.2.0
|
409
417
|
```
|
410
418
|
|
411
419
|
**Note:** amd64 arch is not prebuilded, as you need to run this sw on the Raspberry Pi.
|
@@ -435,4 +443,8 @@ In standby mode, without this application, it takes 180MB ram. With this app it
|
|
435
443
|
|
436
444
|
## 7. TODOs
|
437
445
|
- add display redrawer specs
|
438
|
-
-
|
446
|
+
- when app is (re)started, redraw screem, to white, for example
|
447
|
+
- cloning external libraries during Docker build from this project repo / or ftp under my control
|
448
|
+
- do not do git clone of master branch of WiringPi library, but specific tag, to be sure things doesnt break in future
|
449
|
+
- persist logs, instead of stdout only
|
450
|
+
- implement log rotation and deletion, to save disk space
|
@@ -9,6 +9,7 @@ module SmartRubyPlug
|
|
9
9
|
|
10
10
|
def process
|
11
11
|
while true do
|
12
|
+
#sleep(10) # TODO uncomment if you are developing on non-Raspberry Pi architecture
|
12
13
|
SmartRubyPlug::StdoutLogger.logger.debug('Running processor with ping checks ...')
|
13
14
|
|
14
15
|
smart_plug_status = smart_plug_check
|
@@ -26,7 +27,7 @@ module SmartRubyPlug
|
|
26
27
|
@wifi_output = wifi_check
|
27
28
|
unless @wifi_output == []
|
28
29
|
redraw_display_with_error(@wifi_output)
|
29
|
-
|
30
|
+
next
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -34,7 +35,7 @@ module SmartRubyPlug
|
|
34
35
|
@internet_output = internet_check
|
35
36
|
unless @internet_output == []
|
36
37
|
redraw_display_with_error(@internet_output)
|
37
|
-
|
38
|
+
next
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -6,14 +6,18 @@ module SmartRubyPlug
|
|
6
6
|
SUCCESS_API_MESSAGE = 'OK'.freeze
|
7
7
|
|
8
8
|
def do_request
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
begin
|
10
|
+
response = HTTParty.post(do_request_url,
|
11
|
+
body: {
|
12
|
+
"entity_id": @plug_entity_id
|
13
|
+
}.to_json,
|
14
|
+
headers: {
|
15
|
+
"content-type" => 'application/json',
|
16
|
+
"Authorization" => "Bearer #{@long_lived_token}"
|
17
|
+
})
|
18
|
+
rescue => e
|
19
|
+
return false
|
20
|
+
end
|
17
21
|
|
18
22
|
response.code == SUCCESS_API_CODE && response.message == SUCCESS_API_MESSAGE
|
19
23
|
end
|
@@ -5,11 +5,15 @@ module SmartRubyPlug
|
|
5
5
|
API_STATUS_PATH = '/api/states/'.freeze
|
6
6
|
|
7
7
|
def do_request
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
begin
|
9
|
+
response = HTTParty.get(do_request_url,
|
10
|
+
headers: {
|
11
|
+
"content-type" => 'application/json',
|
12
|
+
"Authorization" => "Bearer #{@long_lived_token}"
|
13
|
+
})
|
14
|
+
rescue => e
|
15
|
+
return nil
|
16
|
+
end
|
13
17
|
|
14
18
|
# request has failed, we dont know if plug is on or off
|
15
19
|
return nil unless request_passed?(response)
|
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.2.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-07-
|
11
|
+
date: 2022-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: 2.0.0
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 1.3.
|
104
|
+
version: 1.3.5
|
105
105
|
requirements: []
|
106
106
|
rubygems_version: 3.3.7
|
107
107
|
signing_key:
|