Just about “smart home”: how to make “smart” backlight
Coming home, it was always inconvenient: you open the door, and then it's dark, then there was an idea to make the backlight in the hallway, but not easy, and what could be turned on from the phone before coming home. Well said - it means you have to start.
3r33320.
3r33320. As further extensions of this system are planned (or not), it was decided to take a single-board computer as a basis. With a flick of the mouse on Ali, the cheapest <
was picked up. 3r33320.
3r33320. spoiler title = "orange pi zero 256mb">
3r33320. 3r314. orange pi zero 256mb
.
3r33320. 3r318.
3r33320. armbian or any other Linux, but I chose this one. I recommend writing an image using 3r375. etcher. 3r33333. 3r3122. 3r33320. 3r395. Next, through apt-get install java in 3 teams:
3r33320.
3r33320.
3r3118. #sudo add-apt-repository ppa: webupd8team /java
#sudo apt-get update
#sudo apt-get install oracle-java8-installer
3r3122. 3r33320. 3r395. Using the gita, add the set wiringPi for our board (it contains various libraries for working with gpio and all sorts of tools for the same) 3r33310. 3r33320. Also not difficult:
3r33320.
3r33320.
3r3118. #git clone https://github.com/vladikoms/WiringOP-Zero.git
#cd WiringOP-Zero
#chmod + x ./build
#sudo ./build
3r33320. Well, check:
3r33320.
3r33320.
3r3118. #gpio -v
#gpio readall
3r3122. 3r33320. 3r3124.
3r33320. On this part with the board finished, go to the computer and your favorite ide.
3r33320.
3r33320. We will deploy the server in spring, so go to their site or in ide we create a spring project with a hail.
3r33320.
3r33320.
3r33320.
3r33320. To work with gpio, you need to install the 3r3r2142 library. pi4j
, for this you need to add repository and dependency
3r33320.
3r33320. And then the final script should look something like this:
3r33320.
3r33320.
build.gradle [/b] buildscript {
ext {
springBootVersion = '???.RELEASE'
}
repositories {
mavenCentral ()
}
3r33320. dependencies {
classpath ("org.springframework.boot: spring-boot-gradle-plugin: $ {springBootVersion}")
}
}
3r33320. apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
3r33320. group = 'com.lary.sh'
version = '???-SNAPSHOT'
sourceCompatibility = ???r3r3320. 3r33320. jar {3r33320. baseName = 'SH'
version = '???-SNAPSHOT'
}
repositories {
mavenCentral ()
maven {
3r33320. url "https://oss.sonatype.org/content/groups/public" //here is the
repository.}
}
3r33320. dependencies {
implementation ('org.springframework.boot: spring-boot-starter-data-rest')
implementation ('org.springframework.boot: spring-boot-starter-web')
runtimeOnly ('org.springframework.boot: spring-boot-devtools')
testImplementation ('org.springframework.boot: spring-boot-starter-test')
compile 'com.pi4j: pi4j-core: 1.2-SNAPSHOT' //but the dependence
}
3r33320.
3r33320. Excellent go to the class managing gpio:
3r33320.
3r33320.
Gpio.java [/b] public class MyGpio {
private GpioController gpio; 3r33320. private GpioPinDigitalOutput myLed; 3r33320. 3r33320. public gpio () {
3r33320. try {//with errors, not really so far, only the prototype of the same (probably) 3r-3320 steam up. PlatformManager.setPlatform (Platform.ORANGEPI); //indicate that we are working with OrangePI
} catch (PlatformAlreadyAssignedException e) {
e.printStackTrace (); 3r33320.}
3r33320. gpio = GpioFactory.getInstance (); 3r33320. myLed = gpio.provisionDigitalOutputPin (OrangePiPin.GPIO_08); //initialize 8 pin as exit
//that is, we will manage its voltage
}
3r33320. public void light () {//method responsible for the
glow. if (myLed.isHigh ()) myLed.low (); //if on the selected pin a high voltage to make it equal to the voltage on the earth 3r-3320. else myLed.high (); //otherwise, apply a high voltage to the selected pin (8)
}
public void blink () {//well, and so blink for the mind 3r-3320. for (int i = 0; i 3-3r3239. try {
light ();
Thread.sleep (500);
}
catch (Exception e) {3rrr204. e .}
}
}
3r33320.
3r33320. The presented code is quite simple and does not imply good management of the board pins, but opens the door to this.
3r33320.
3r33320. Well, the final stage of the creation of the controller in the spring
3r33320.
3r33320.
GpioController.java [/b] @Controller
public class GpioController {
3r33320. @RequestMapping ("/blink")
@ResponseBody
public String blink (HttpServletResponse response, HttpServletRequest request)
{
Gpio gpio = new Gpio (); 3r33320. gpio.blink (); 3r33320. return "blink"; 3r33320.}
3r33320. @RequestMapping ("/light")
@ResponseBody
public void light () {
Gpio gpio = new Gpio (); 3r33320. gpio.light (); 3r33320.}
}
3r33320.
3r33320. Now a couple of recent gestures in the form of creating a jar file using gradle. After that, the transfer via sftp to the board (in many ideas, you can configure the deployment directly) and run the jar on the device. Next we go to the cherished browser ???. ***: 8080 /light
3r33320. and enjoy, simultaneously hoping that it will help keep our fingers at night or turn on the light, before coming home.
3r33320.
3r33320. In the next part (if ever I get to it) I will definitely show different ways of interacting with our “smart” home.
3r33320.
3r33320. 3r3308. here's the source code
3r33320. 3r33312. And here work with a comb (gpio) 3r3333313.
3r33320. 3r33320. 3r33320. 3r33333. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33333. 3r33320.
It may be interesting
weber
Author25-11-2018, 01:23
Publication DateDevelopment / JavaScript
Category- Comments: 0
- Views: 261